This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
extension does not handle command-line args that need to be passed to tests #1534
Closed
Description
the go test
supports passing command-line arguments to the test binary. To quote go test -help
:
In addition to the build flags, the flags handled by 'go test' itself are:
-args
Pass the remainder of the command line (everything after -args)
to the test binary, uninterpreted and unchanged.
Because this flag consumes the remainder of the command line,
the package list (if present) must appear before this flag.
Sadly, the extension isn't aware of this rule, and adding any "-args" to the "go.testFlags" setting does not work, as the extension does not put such arguments last in the arguments list.
Steps to Reproduce:
- Write a test file:
import (
"flag"
"os"
"testing"
)
var dbCnn string
func TestMain(m *testing.M) {
flag.StringVar(&dbCnn, "dbcnn", "", "database connection")
flag.Parse()
os.Exit(m.Run())
}
func TestReports(t *testing.T) {
if dbCnn == "" {
t.Fatal("db connection not set")
}
}
- Change Go settings:
"go.testFlags": [
"-args",
"-dbcnn",
"postgres://foo:bar@baz/abc"
]
- Run test
Result:
Running tool: /usr/local/Cellar/go/1.9.3/libexec/bin/go test -args -dbcnn postgres://foo:bar@baz/abc -timeout 30s ***/server/db -run ^TestReports$
flag provided but not defined: -timeout
The error is because "-args" is not placed after all other args to go test
.
I think the correct solution would be to define a new setting - perhaps "go.testArgs" - an array of arguments to the test binary.
I would love to work on this myself and submit a PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment