-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: support table tests for test case structs with no fields #155
Comments
We should be able to support this by extending the current treesitter queries: https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/query.lua If you want to take a stab at it, there are Go tests in |
Sorry, I somehow missed you already looked into this. 😅
I see what you mean. Not sure myself without digging (not at my machine until next week). |
Seems possible to just match the first string defined in the struct which is likely the right one. Seems like an option if there's not a better way to index the fields between struct definition and literal definitions |
Please give #156 a try? Load the plugin by setting
This is exactly what I did now. |
Sorry for the long delay. Two things
func TestTableTestInlineStructLoopNotKeyed(t *testing.T) {
testcases := []struct {
name string
x int
y int
expected int
}{
{"TableTest1", 1, 2, 3}, // no `name:` to match on
{"TableTest2", 3, 4, 7},
}
for _, tc := testcases {
t.Run(tc.name, func(t *testing.T) {
if Add(tc.x, tc.y) != tc.expected {
t.Fail()
}
})
}
}
|
Sorry for the silence here. I'm quite busy at work and with life at the moment. I'll have a look when I have the time. Feel free to take a stab at it in case you wish. |
@jstensland I updated the query in #156 {
"fredrikaverpil/neotest-golang",
branch = "table-test-without-struct-fields",
} |
Hi @fredrikaverpil I stumbled upon the same issue by coincidence and checked out #156. The fix seems to work great on my end! 😄 Only slightly surprising behaviour I found is that if you run the nearest test when the cursor is below the array of test cases (e.g. on the |
Hi @kvalv ! I understand what you mean, but this is actually expected/intended behavior. Neotest gives the adapter the ability to provide treesitter queries so to detect what is considered a test or test case (in the test table). You can see the I also think (I'm not entirely sure as I'm on the go right now) that Neotest looks upwards the file when it tries to find the nearest test, so to make things more intuitive. But on a slightly different note, this PR has been open for a long time. Since you have verified that it works for you, I'm thinking we can merge this in. WDYT? |
Thanks for the clarification! Makes sense that neotest looks upward when finding the nearest test, so this is intended behaviour 👍
Sounds great! From what I can see, the PR should resolve this issue 😄 |
Did you check docs and existing issues?
Is your feature request related to a problem? Please describe.
I have multiple packages with test cases where there's an anonymous struct of test cases and the cases do not include fields. The current support for table tests do not detect these. e.g.
Given the support for this functionality when the field is there, it would be nice to support this form as well.
Describe the solution you'd like to see.
I would like to be able to run the nearest test case when my cursor is on it, or to run a single test case from the summary
Describe alternatives you've considered.
The obvious alternative is to just run the full test, which does work.
Additional context
I tried updated the treesitter query for these. I could only get as far as matchings the struct def with the first argument to run in this form (similar to what exists) but wasn't sure if it's possible to ask treesitter for the index of the sibling in the list of declared field, such that I could identify that name field to capture the test name. It may be good enough to assume its first, given this is just matching a specific code pattern anyways
The text was updated successfully, but these errors were encountered: