Skip to content
Permalink
Browse files

default to -tests=false

First, this makes the tool way faster, as most developers write tests
within the same package. This greatly slows down package loading, as we
must load each package twice.

If golang/go#29258 is ever accepted and
implemented, that cost might be reduced.

Second, most warnings within test files are not very useful. Even if
most aren't false positives, it's common for developers to not care as
much about test code quality.

Finally, loading the tests can lead to different results, as test files
can also use the functions which may or may not give warnings. More
often than not, the developer cares about how non-test functions are
used from within non-test code.

For all these reasons, disable test loading by default. It can still be
enabled manually.
  • Loading branch information...
mvdan committed Jan 24, 2019
1 parent ddebc80 commit cc9d2fb5297134d45a3e8fd7a0335965c6d79a0b
Showing with 6 additions and 6 deletions.
  1. +1 −1 main.go
  2. +5 −5 testdata/scripts/include_test.txt
@@ -14,7 +14,7 @@ import (
var (
flagSet = flag.NewFlagSet("unparam", flag.ContinueOnError)

tests = flagSet.Bool("tests", true, "include tests")
tests = flagSet.Bool("tests", false, "load tests too")
exported = flagSet.Bool("exported", false, "inspect exported functions")
debug = flagSet.Bool("debug", false, "debug prints")
)
@@ -2,14 +2,14 @@ env HOME=$WORK/home

! unparam .
stdout 'fooUnused .* unused'
stdout 'footestUnused .* unused'
stdout 'footestpkgUnused .* unused'

! unparam -tests=false .
stdout 'fooUnused .* unused'
! stdout 'footestUnused .* unused'
! stdout 'footestpkgUnused .* unused'

! unparam -tests=true .
stdout 'fooUnused .* unused'
stdout 'footestUnused .* unused'
stdout 'footestpkgUnused .* unused'

-- go.mod --
module testdata.tld/foo
-- foo.go --

0 comments on commit cc9d2fb

Please sign in to comment.
You can’t perform that action at this time.