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

feature: only run test in package instead of go.mod root #228

Closed
2 tasks done
damoye opened this issue Dec 9, 2024 · 6 comments · Fixed by #230
Closed
2 tasks done

feature: only run test in package instead of go.mod root #228

damoye opened this issue Dec 9, 2024 · 6 comments · Fixed by #230
Assignees
Labels
bug Something isn't working

Comments

@damoye
Copy link

damoye commented Dec 9, 2024

Did you check docs and existing issues?

Is your feature request related to a problem? Please describe.

When I run

require("neotest").run.run("<my_package_folder>")

It will search up to go.mod and run go test ./... from directory of go.mod file.

However I would like to run go test ./... only in my_package_folder.

Neotest summary also only shows tests in my_package_folder instead of directory of go.mod file.

Describe the solution you'd like to see.

Only run all tests in specified package.
Maybe change run_spec.cwd from go_mod_folderpath to pos.path in:
https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/runspec/dir.lua#L63

Describe alternatives you've considered.

No

Additional context

No response

@damoye damoye added the enhancement New feature or request label Dec 9, 2024
@damoye
Copy link
Author

damoye commented Dec 9, 2024

I find out that my specified package is empty without any go files. So it will search up to directory of go.mod run go test ./...
If it contains go files. It will only run go test <my_package_folder> without /.... So it won't run any test in sub folders.

Is this as expected? My expectation is running all tests in specified package. go test {my_package_folder}/...

Relative code: https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/runspec/dir.lua#L44

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Dec 10, 2024

Hi @damoye I'm not sure I understand the issue.

Let's take this repo as an example.

  1. Clone down neotest-golang into ~/code/neotest-golang; git clone https://github.com/fredrikaverpil/neotest-golang.git ~/code/neotest-golang
  2. cd ~/code/neotest-golang
  3. Start Neovim; nvim
  4. Run :lua require("neotest").run.run(vim.fn.expand("~/code/neotest-golang/tests/go/subpackage"))

The command that gets executed by Neotest/neotest-golang is:

go test -json -v -count=1 -race github.com/fredrikaverpil/neotest-golang/subpackage

Can you give an example lua command which exhibits substituting the package with ./...?

@damoye
Copy link
Author

damoye commented Dec 10, 2024

@fredrikaverpil Hi, let's use my fork for example: https://github.com/damoye/neotest-golang/tree/subpackage_test
Use branch: subpackage_test
File tree like this:
├── subpackage
│   ├── coverage.out
│   └── subpackage2
│   ├── subpackage2_test.go
│   └── subpackage3
│   └── subpackage3_test.go

Note that there is no test file in the root of subpackage.

First problem

When I run :lua require("neotest").run.run(vim.fn.expand("~/code/neotest-golang/tests/go/subpackage"))
It will run command go test -json ./... with cwd ~/code/neotest-golang/tests/go.
So it runs all tests in folder go, not subpackage.
But I expect it runs all tests in subpackage.

Second problem

When I run :lua require("neotest").run.run(vim.fn.expand("~/code/neotest-golang/tests/go/subpackage/subpackage2"))
It will run command go test -json github.com/fredrikaverpil/neotest-golang/subpackage/subpackage2
But this command only runs test files in subpackage/subpackage2,
not all packages in subpackage2 recursively, like subpackage3.

@fredrikaverpil
Copy link
Owner

Thank you @damoye I can reproduce. Let me have a closer look at this.

@fredrikaverpil
Copy link
Owner

fredrikaverpil commented Dec 12, 2024

@damoye wow, I can't believe this bug hasn't been found until now. It was quite severe. Huge thanks for reporting this!

If you have the time, would you please see if #230 resolves the issues you are seeing on your end?

{ "fredrikaverpil/neotest-golang", branch = "fix/package" }

@fredrikaverpil fredrikaverpil added bug Something isn't working and removed enhancement New feature or request labels Dec 12, 2024
@fredrikaverpil fredrikaverpil self-assigned this Dec 12, 2024
@damoye
Copy link
Author

damoye commented Dec 13, 2024

@fredrikaverpil Yes! It resolved my problems. Thansk a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants