Skip to content
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

Table tests not recognized when defined inside for-loop #86

Open
fredrikaverpil opened this issue Mar 28, 2024 · 2 comments
Open

Table tests not recognized when defined inside for-loop #86

fredrikaverpil opened this issue Mar 28, 2024 · 2 comments

Comments

@fredrikaverpil
Copy link

fredrikaverpil commented Mar 28, 2024

I just noticed that when you define your table tests like this, neotest-go does not recognize individual tests in the table:

func TestSomething(t *testing.T) {
	t.Parallel()
	t.Run("subtest of table tests", func(t *testing.T) {
		t.Parallel()
		for _, tt := range []struct {
			name string
		}{
			{
				name: "missing",
			},
			{
				name: "invalid",
			},
			{
				name: "wildcard not allowed",
			},
		} {
			tt := tt
			t.Run(tt.name, func(t *testing.T) {
				t.Parallel()
				// Act
				// Assert
			})
		}
	})
}

By rewriting them on the form seen in https://github.com/nvim-neotest/neotest-go/blob/main/neotest_go/many_table_test.go fixes the issue. But when you enter a large pre-existing codebase where table tests are defined this way, this is not a helpful workaround as it's hard to motivate refactoring hundreds of tests for this purpose.

I haven't looked into how neotest-go figures out that there are table tests. Treesitter AST inspection?

@JamesTeague
Copy link

JamesTeague commented Apr 2, 2024

It will run for me but it will mark tests as failed.
For example:
If I run only the method it will ALWAYS fail.
If I run the whole file it will ALWAYS pass.

This is regardless of the correctness of the tests.

That is incorrect. If I have my cursor on the line above the method and run the test on the method if will pass but if my cursor is on the method signature it fails.

@fredrikaverpil
Copy link
Author

@JamesTeague I just added support for this in https://github.com/fredrikaverpil/neotest-golang in case you were also looking for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants