You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we discussed in PR #12003, the way we did to run tests is not working for submodules. Because we use parent directory of test file in go test command as pattern like go test {parentDir} -run {testName}. It works for tests in current module but it won't if running a test in a different module.
go test . -run TestXxx will work but go test ./submodule -run TestXxx will not.
It gives error as main module (my-project) does not contain package my-project/submodule
There are some potential fixes for this:
Most easily, using file path instead of relative path of parent directory in go test command: go test ./submodule/submodule_test.go -run TestXxx.
Detect module directory of test file (./submodule for submodule_test.go) and setting cwd variable of TaskTemplate as this directory. So cwd = ./submodule and test command will be go test . -run TestXxx
Similar to 2, cwd will be set as module directory but we will use package tree instead of file system tree. Which I mean, when we detect the module of file, we should also get module name in go.mod like github.com/xx/some-package, then the test command should be go test github.com/xx/some-package/submodule -run TestXxx.
I think vscode-go extension doing something similar to this: Running tool: /usr/local/go/bin/go test -timeout 300s -run ^TestSomething$ github.com/anilsenay/zed-go-test/slice
The reason I came with this is that it could be useful for features which require package tree like this in the future:
Moshyfawn
added
language
An umbrella label for all programming languages syntax behaviors
go
Go programming language support
tasks
and removed
triage
Maintainer needs to classify the issue
labels
May 27, 2024
Hi @anilsenay, can you check if this is still an issue with recent versions of Zed? There has been work to improve how we detect runnables and build tasks and I wanted to see if this issue stands or if any of the details have changed in the intervening six months. Thanks
Check for existing issues
Describe the bug / provide steps to reproduce it
As we discussed in PR #12003, the way we did to run tests is not working for submodules. Because we use parent directory of test file in
go test
command as pattern likego test {parentDir} -run {testName}
. It works for tests in current module but it won't if running a test in a different module.for example we opened a project in Zed like this:
. ├── submodule/ │ ├── submodule.go │ ├── submodule_test.go │ └── go.mod ├── main.go ├── main_test.go └── go.mod
go test . -run TestXxx
will work butgo test ./submodule -run TestXxx
will not.It gives error as
main module (my-project) does not contain package my-project/submodule
There are some potential fixes for this:
Most easily, using file path instead of relative path of parent directory in
go test
command:go test ./submodule/submodule_test.go -run TestXxx
.Detect module directory of test file (
./submodule
forsubmodule_test.go
) and settingcwd
variable ofTaskTemplate
as this directory. So cwd = ./submodule and test command will bego test . -run TestXxx
Similar to 2, cwd will be set as module directory but we will use package tree instead of file system tree. Which I mean, when we detect the module of file, we should also get module name in go.mod like
github.com/xx/some-package
, then the test command should bego test github.com/xx/some-package/submodule -run TestXxx
.I think vscode-go extension doing something similar to this:
Running tool: /usr/local/go/bin/go test -timeout 300s -run ^TestSomething$ github.com/anilsenay/zed-go-test/slice
The reason I came with this is that it could be useful for features which require package tree like this in the future:
Environment
Zed: v0.138.0 (Zed Dev ddb551c)
OS: macOS 14.5.0
Memory: 16 GiB
Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your
~/Library/Logs/Zed/Zed.log
file to this issue.No response
The text was updated successfully, but these errors were encountered: