quolpr / quicktest.nvim

Run your tests in split window or popup with live feedback
MIT License
66 stars 5 forks source link

Add adapter for C assuming Meson build system and Criterion unit testing framework #1

Closed oyvindaakre closed 2 months ago

oyvindaakre commented 2 months ago

Add an adapter for unit tests written in C using the Criterion unit test framework and assuming the meson build system.

Note: Build directory assumptions:

Dependencies

Supported features

quolpr commented 2 months ago

@oyvindaakre looks great! Ready for merge?

quolpr commented 2 months ago

@oyvindaakre also, could add please example to test dir, like I did for go - test/gotest. The implementation should be very simple, just text for like 1 + 1 == 2, or as you want

oyvindaakre commented 2 months ago

Hi @quolpr, thanks for checking in :) I'm still fixing bugs and adding functionality, so the PR is not ready just yet :) I'll change the status back to a draft to reflect that. I will also clean up the implementation and add documentation before trying to merge this :)

I have to say, kudos to you! This is the first plugin I work on and as a lua-noob I found this as a good starting point and I think it was easy to get going on my own adapter.

quolpr commented 2 months ago

Btw, I reload plugin while developing with this command, could be helpful for you:

vim.api.nvim_create_user_command("C", function()
  require("lazy.core.loader").reload("quicktest.nvim")
end)

So, what I usually do:

  1. Add sample project to test folder
  2. Edit adapter
  3. Run :C command
  4. Rerun test
quolpr commented 2 months ago

@oyvindaakre

I made some breaking changes in API. Changes are not so much, please check Readme 🙂

oyvindaakre commented 2 months ago

@quolpr Should this PR update the doc too?

quolpr commented 2 months ago

@oyvindaakre the doc will be generated from Readme once PR is merged to main. So, please, mention your adapter in Readme 🙂

oyvindaakre commented 2 months ago

@quolpr Finally, I think the adapter is ready. I have two questions though: 1) The adapter needs to know the path to the build directory. Currently I hardcode build here: https://github.com/oyvindaakre/quicktest.nvim/blob/ea9396b6660116e220f575a5aa33743fe8a1a13a/lua/quicktest/adapters/criterion/init.lua#L12. Is it possible for users to override this and set a custom path if they want?

2) I added a sample project to tests/support/criterion. I also added a readme in an attempt to explain how to set up the project (+ some notes on the adapter itself). I'm not sure how to run it with the makefile. When I run make test it only seems to run the plugin_name_spec.lua test. Is that expected?

$ make test
Starting... 
Scheduling: tests/plugin_name/plugin_name_spec.lua

========================================    
Testing:    /home/oyvind/.local/share/nvim/lazy/quicktest.nvim/tests/plugin_name/plugin_name_spec.lua   
Success ||  setup works with default    

Success:    1   
Failed :    0   
Errors :    0   
========================================    
quolpr commented 2 months ago

@oyvindaakre as for

The adapter needs to know the path to the build directory. Currently I hardcode build here: https://github.com/oyvindaakre/quicktest.nvim/blob/ea9396b6660116e220f575a5aa33743fe8a1a13a/lua/quicktest/adapters/criterion/init.lua#L12. Is it possible for users to override this and set a custom path if they want?

Yep, I think the best way will be to make your plugin to work like this:

qt.setup({
  adapters = {
    require("quicktest.adapters.golang")({
       exec_path = function(params)
       end
    }),
  }
})

You can do this with meta table, check example here https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/init.lua#L179

I will be adding the same API to other adapters too soon. Also, notice that function is supplied for param, that's how user will be able to change behaviour per project. Based on what vim.fn.bufname(params.bufnr)(returns buffer path) contains, they will be able to dynamically configure exec_path.

Or you can support both functions and strings, like here https://github.com/olimorris/neotest-rspec?tab=readme-ov-file#setting-the-root-directory

Let me know what you think

I'm not sure how to run it with the makefile. When I run make test it only seems to run the plugin_name_spec.lua test. Is that expected?

Ha-ha, I didn't make tests for quicktet 😄 So only manual tests for now

oyvindaakre commented 2 months ago

Let me know what you think

It sounds neat to support both function and string, but I don't have enough Lua-experience under my belt to know the implications of supporting both :) Metatable is a new concept for me, so I have to read up on it, but I'm happy to take suggestions on how to implement it for this adapter.

quolpr commented 2 months ago

@oyvindaakre I made config options support for golang, could you do the same way? https://github.com/quolpr/quicktest.nvim/commit/a3bb0b6bded24ba2141cda023bf9161383ac4e30

oyvindaakre commented 2 months ago

@oyvindaakre I made config options support for golang, could you do the same way? a3bb0b6

Looks good! Copied your steps. Does it look okay?

quolpr commented 2 months ago

@oyvindaakre LGTM! Thank you for the contribution, merging it now :)