vscode-go
vscode-go copied to clipboard
Allow using another tool to run tests?
Is your feature request related to a problem? Please describe.
I use gotestsum in the terminal because of the test results formatting and would love to have vscode using the same.
Ref: https://github.com/gotestyourself/gotestsum/issues/259
Describe the solution you'd like I'm not sure exactly how it would be possible since the official way is:
go test XXXXXXXXXX
and that gotestsum works like
gotestsum XXXXXXXXXX
It respects native parameters as for go test... expect in go test the test is already a parameter. So it seems a generic way of aliasing is not possible :( . And it's very unlikely other custom tools would respect most of the parameters from the official way.
Except by delegating the tests to a specific extension that manages it properly, the quick workaround would be to allow a "replace" in the resulting test command to run. Like:
"go.testCommandReplacePatterns": {
"go test": "gotestsum"
}
... but I agree it's really ugly.
Any suggestion?
Thank you,
This can be worked around with the script here: https://github.com/golang/vscode-go/pull/3404#issuecomment-2143822643
It would be nice for vscode to support this natively, I think "go.testCommand": ["go", "test"] as a default would allow setting "go.testCommand": ["gotestsum", "--"]?
I'm using this script with success in gotestsum, fwiw:
#!/bin/bash
# put this in settings.json:
#
# "go.alternateTools": {
# "go": "${workspaceFolder}/path/to/this/script.sh"
# },
main() {
if [[ "$1" = 'test' && "$*" != *-json* ]]; then
shift
runv gotestsum --format testname -- "$@"
else
go "$@"
fi
}
runv() {
{
printf '>'
printf ' %s' "$@"
printf '\n'
} >&2
"$@"
}
main "$@"
The old test system - the one that pipes test output to an output pane - is deprecated. The new system - the test explorer - uses JSON events (the -json flag) to track the execution of tests. If your goal is to customize the output, that's not really possible with a 3rd party tool. The only realistic way to customize output is to modify vscode-go itself to allow customizing output.
If your goal is instead to change the test execution system, that is more feasible. However any alternative test executor would need to produce the same JSON events that the official tool produces, otherwise the test explorer will break. Also, as mentioned on #3340, debugging tests may be problematic. If you need a different executor because go test doesn't work, then dlv test (the test debugger) probably also won't work. Realistically I think the most viable option is for the alternative executor to also support building test binaries, which can then be debugged with delve like any other Go binary.
That's fair. In vscode I pretty much exclusively run tests via the "run test" / "debug test" inlays within test files. It seems like these tests don't go through the test explorer, if they did I don't think I'd care about being able to use gotestsum because the output is more clearly grouped automatically.
edit: I've updated my script above to only use gotestsum if json output is requested, which seems to make it work with test explorer.
They don't, unless you install prerelease vscode-go and Go Companion. Eventually™ they will use the test explorer.