cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.96k stars 345 forks source link

Add a -version flag to differentiate two gotests binaries #133

Open lepinkainen opened 4 years ago

lepinkainen commented 4 years ago

I have two setups, in one the -parallel option works just fine in vscode - it generates parallel test cases as it should. In the other it doesn't do anything (not reporting errors in custom flags is a problem in the vscode go plugin, which is not the issue here).

Both were installed with go get -u github.com/cweill/gotests/... when in the $HOME directory within 15 minutes of each other.

One installation looks like this (go version go1.14.3 darwin/amd64) - no -parallel option

Usage of gotests:
  -all
        generate tests for all functions and methods
  -excl string
        regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all
  -exported
        generate tests for exported functions and methods. Takes precedence over -only and -all
  -i    print test inputs in error messages
  -nosubtests
        disable generating tests using the Go 1.7 subtests feature
  -only string
        regexp. generate tests for functions and methods that match only. Takes precedence over -all
  -template string
        optional. Specify custom test code templates, e.g. testify
  -template_dir string
        optional. Path to a directory containing custom test code templates. Takes precedence over -template
  -template_params string
        read external parameters to template by json with stdin
  -template_params_file string
        read external parameters to template by json with file
  -w    write output to (test) files instead of stdout

The other like this (go version go1.13.8 linux/amd64) - -parallel found and works perfectly

Usage of ./gotests:
  -all
        generate tests for all functions and methods
  -excl string
        regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all
  -exported
        generate tests for exported functions and methods. Takes precedence over -only and -all
  -i    print test inputs in error messages
  -nosubtests
        disable generating tests using the Go 1.7 subtests feature
  -only string
        regexp. generate tests for functions and methods that match only. Takes precedence over -all
  -parallel
        enable generating parallel subtests
  -template string
        optional. Specify custom test code templates, e.g. testify. This can also be set via environment variable GOTESTS_TEMPLATE
  -template_dir string
        optional. Path to a directory containing custom test code templates. Takes precedence over -template. This can also be set via environment variable GOTESTS_TEMPLATE_DIR
  -template_params string
        read external parameters to template by json with stdin
  -template_params_file string
        read external parameters to template by json with file
  -w    write output to (test) files instead of stdout

Took me a LONG while to figure out why vscode was generating parallel tests on one and not on the other... There is no way to differentiate the two installs except by manually comparing the help texts - which themselves only appear when giving a faulty flag. Just running gotests by itself gives the exact same defaults on both installations.

It would be really useful to have a -version flag in gotests to debug these issues and maybe make it possible for plugins like the Go vscode plugin to determine if some options are available or not.

Bonus question: why did both platforms and go versions get a completely different version of gotests?

cweill commented 3 years ago

@lepinkainen Sorry you ran into that issue. If anyone wants to send a PR that will include the version (including git commit), I will review and approve it.

teddylear commented 3 years ago

@cweill I can take a look into adding this

cweill commented 3 years ago

@teddylear Sounds good to me. A PR will be welcome.

teddylear commented 3 years ago

@cweill Added PR. As noted in PR, there appears to be an existing bug in the with the 1.16 version of the tests. Please let me know if there is a ticket for that already or if I should make one.

butuzov commented 3 years ago

@teddylear can you tell more about failed tests? (maybe in sep issue)

teddylear commented 3 years ago

@butuzov Here is a an example off the failed tests off of develop on this draft PR: https://github.com/cweill/gotests/pull/158. Note that I only edited the README and the the tests failed. Looks like it's not just a golang 1.16.x issue.

sorenisanerd commented 4 months ago

Fwiw, go version -m $(which gotests) reveals the versioning info embedded in the binary. Example:

$ go version -m /Users/soren/go/bin/gotests 
/Users/soren/go/bin/gotests: go1.22.1
        path    github.com/cweill/gotests/gotests
        mod     github.com/cweill/gotests       v1.6.0  h1:KJx+/p4EweijYzqPb4Y/8umDCip1Cv6hEVyOx0mE9W8=
        dep     golang.org/x/tools      v0.0.0-20191109212701-97ad0ed33101      h1:LCmXVkvpQCDj724eX6irUTPCJP5GelFHxqGSWL2D1R0=
        build   -buildmode=exe
        build   -compiler=gc
        build   DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
        build   CGO_ENABLED=1
        build   CGO_CFLAGS=
        build   CGO_CPPFLAGS=
        build   CGO_CXXFLAGS=
        build   CGO_LDFLAGS=
        build   GOARCH=arm64
        build   GOOS=darwin