Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: 'go test all' tests unused std lib packages when using modules #31075

Closed
alexedwards opened this issue Mar 27, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@alexedwards
Copy link

commented Mar 27, 2019

Based on #26317 (comment) and the documentation for all in go help packages, when using modules I expect go test all to test only the standard library packages which actually get built into the packages in a module.

It appears to be testing all standard library packages.

System details

go version go1.12.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/alex/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/alex/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOROOT/bin/go version: go version go1.12.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.12.1
uname -sr: Linux 4.18.0-16-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 18.10
Release:	18.10
Codename:	cosmic
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.28-0ubuntu1) stable release version 2.28.
gdb --version: GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2

What did you do?

$ mkdir /tmp/ta
$ cd /tmp/ta
$ go mod init example.com/ta
$ cat >main.go <<EOF
> package main
> 
> import "fmt"
> 
> func main() {
>         fmt.Println("hello")
> }
> EOF
$ go test all

What did you expect to see?

From go help packages:

When using modules, "all" expands to all packages in the main module and their dependencies, including dependencies needed by tests of any of those.

So I would expect to see go test all test the following standard library packages only (based on the output of go list -deps):

errors
internal/cpu
unsafe
math/bits
math
internal/bytealg
runtime/internal/atomic
runtime/internal/sys
runtime/internal/math
runtime
unicode/utf8
strconv
internal/race
sync/atomic
sync
unicode
reflect
sort
internal/fmtsort
io
syscall
time
internal/poll
internal/syscall/unix
internal/testlog
os
fmt

What did you see instead?

Running go test all appears to unnecessarily test additional standard library packages:

$ go test all
ok  	bufio	0.119s
ok  	bytes	2.426s
ok  	compress/bzip2	0.086s
ok  	compress/flate	12.565s
ok  	compress/gzip	0.047s
ok  	compress/lzw	0.086s
ok  	compress/zlib	1.020s
ok  	container/heap	0.021s
ok  	container/list	0.023s
ok  	context	2.372s
ok  	crypto	0.014s
ok  	crypto/aes	0.033s
ok  	crypto/cipher	0.299s
ok  	crypto/des	0.016s
ok  	crypto/dsa	11.754s
ok  	crypto/ecdsa	4.906s
...

@alexedwards alexedwards changed the title cmd/go: go test all cmd/go: go test all testing unused std lib packages Mar 27, 2019

@alexedwards alexedwards changed the title cmd/go: go test all testing unused std lib packages cmd/go: 'go test all' tests unused std lib packages Mar 27, 2019

@alexedwards alexedwards changed the title cmd/go: 'go test all' tests unused std lib packages cmd/go: 'go test all' tests unused std lib packages whne using modules Mar 27, 2019

@alexedwards alexedwards changed the title cmd/go: 'go test all' tests unused std lib packages whne using modules cmd/go: 'go test all' tests unused std lib packages when using modules Mar 27, 2019

@agnivade

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

Note from the “system details” section of the report:

GOMOD=""

That indicates that the go command is not, in fact, in module mode. What happens if you run GO111MODULE=on go test all?

@bcmills

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

CC @jayconrod

go list -deps does not include the dependencies of tests of dependencies. However, all explicitly does: that accounts for the observed difference.

example.com$ go1.12.1 mod init example.com
go: creating new go.mod: module example.com

example.com$ cat >main.go <<EOF
package main

import "fmt"

func main() {
        fmt.Println("hello")
}
EOF

example.com$ go1.12.1 list -deps >deps.txt

example.com$ go1.12.1 list -deps -test $(<deps.txt) | sort -u
bufio
bufio [internal/cpu.test]
bufio [runtime.test]
bufio [sync.test]
bytes
bytes [internal/cpu.test]
bytes [runtime.test]
bytes [sync.test]
compress/flate
compress/flate [fmt.test]
compress/flate [internal/cpu.test]
compress/flate [internal/fmtsort.test]
compress/flate [internal/poll.test]
compress/flate [math/bits.test]
compress/flate [math.test]
compress/flate [os.test]
compress/flate [reflect.test]
compress/flate [runtime.test]
compress/flate [sort.test]
compress/flate [strconv.test]
compress/flate [sync.test]
compress/flate [syscall.test]
compress/flate [time.test]
compress/gzip
compress/gzip [fmt.test]
compress/gzip [internal/cpu.test]
compress/gzip [internal/fmtsort.test]
compress/gzip [internal/poll.test]
compress/gzip [math/bits.test]
compress/gzip [math.test]
compress/gzip [os.test]
compress/gzip [reflect.test]
compress/gzip [runtime.test]
compress/gzip [sort.test]
compress/gzip [strconv.test]
compress/gzip [sync.test]
compress/gzip [syscall.test]
compress/gzip [time.test]
context
context [fmt.test]
context [internal/cpu.test]
context [internal/fmtsort.test]
context [internal/poll.test]
context [math/bits.test]
context [math.test]
context [os.test]
context [reflect.test]
context [runtime.test]
context [sort.test]
context [strconv.test]
context [sync.test]
context [syscall.test]
context [time.test]
crypto
crypto/aes [runtime.test]
crypto/cipher [runtime.test]
crypto/internal/subtle
crypto/rand [runtime.test]
crypto/sha1
crypto/subtle
encoding
encoding/base64
encoding/base64 [reflect.test]
encoding/binary
encoding/binary [internal/cpu.test]
encoding/binary [math/bits.test]
encoding/binary [math.test]
encoding/binary [reflect.test]
encoding/binary [runtime.test]
encoding/binary [strconv.test]
encoding/binary [sync.test]
encoding/gob [time.test]
encoding/json [reflect.test]
encoding/json [time.test]
errors
errors.test
errors_test [errors.test]
example.com
flag
flag [fmt.test]
flag [internal/cpu.test]
flag [internal/fmtsort.test]
flag [internal/poll.test]
flag [math/bits.test]
flag [math.test]
flag [os.test]
flag [reflect.test]
flag [runtime.test]
flag [sort.test]
flag [strconv.test]
flag [sync.test]
flag [syscall.test]
flag [time.test]
fmt
fmt [fmt.test]
fmt [internal/cpu.test]
fmt [internal/fmtsort.test]
fmt [internal/poll.test]
fmt [math/bits.test]
fmt [math.test]
fmt [os.test]
fmt [reflect.test]
fmt [runtime.test]
fmt [sort.test]
fmt [strconv.test]
fmt [sync.test]
fmt [syscall.test]
fmt.test
fmt_test [fmt.test]
fmt [time.test]
go/ast [reflect.test]
go/ast [runtime.test]
go/build [runtime.test]
go/doc [runtime.test]
go/parser [runtime.test]
go/scanner [reflect.test]
go/scanner [runtime.test]
go/token [reflect.test]
go/token [runtime.test]
hash
hash/crc32
hash/crc32 [internal/cpu.test]
hash/crc32 [runtime.test]
hash/crc32 [sync.test]
hash [internal/cpu.test]
hash [runtime.test]
hash [sync.test]
internal/bytealg
internal/bytealg [internal/cpu.test]
internal/cpu
internal/cpu [internal/cpu.test]
internal/cpu.test
internal/cpu_test [internal/cpu.test]
internal/fmtsort
internal/fmtsort [internal/cpu.test]
internal/fmtsort [internal/fmtsort.test]
internal/fmtsort [math/bits.test]
internal/fmtsort [math.test]
internal/fmtsort [reflect.test]
internal/fmtsort [runtime.test]
internal/fmtsort [sort.test]
internal/fmtsort [strconv.test]
internal/fmtsort [sync.test]
internal/fmtsort.test
internal/fmtsort_test [internal/fmtsort.test]
internal/goroot [runtime.test]
internal/nettrace
internal/poll
internal/poll [internal/cpu.test]
internal/poll [internal/poll.test]
internal/poll [runtime.test]
internal/poll [sync.test]
internal/poll [syscall.test]
internal/poll.test
internal/poll_test [internal/poll.test]
internal/poll [time.test]
internal/race
internal/singleflight
internal/singleflight [runtime.test]
internal/syscall/unix
internal/syscall/unix [internal/cpu.test]
internal/syscall/unix [runtime.test]
internal/syscall/unix [sync.test]
internal/syscall/unix [syscall.test]
internal/testenv [internal/cpu.test]
internal/testenv [os.test]
internal/testenv [runtime.test]
internal/testenv [sort.test]
internal/testenv [sync.test]
internal/testenv [syscall.test]
internal/testlog
internal/x/net/dns/dnsmessage
io
io [internal/cpu.test]
io/ioutil
io/ioutil [internal/cpu.test]
io/ioutil [internal/poll.test]
io/ioutil [math/bits.test]
io/ioutil [math.test]
io/ioutil [os.test]
io/ioutil [reflect.test]
io/ioutil [runtime.test]
io/ioutil [sort.test]
io/ioutil [strconv.test]
io/ioutil [sync.test]
io/ioutil [syscall.test]
io/ioutil [time.test]
io [runtime.test]
io [sync.test]
io.test
io_test [io.test]
log
log [fmt.test]
log [os.test]
log [runtime.test]
log [strconv.test]
math
math/big [runtime.test]
math/big [time.test]
math/bits
math/bits [math/bits.test]
math/bits.test
math/bits_test [math/bits.test]
math/cmplx
math [internal/cpu.test]
math [math/bits.test]
math [math.test]
math/rand
math/rand [runtime.test]
math/rand [sync.test]
math.test
math_test [math.test]
net [runtime.test]
net [syscall.test]
net/url [runtime.test]
os
os/exec [internal/cpu.test]
os/exec [os.test]
os/exec [runtime.test]
os/exec [sort.test]
os/exec [sync.test]
os/exec [syscall.test]
os [internal/cpu.test]
os [internal/poll.test]
os [os.test]
os [runtime.test]
os/signal [os.test]
os/signal [syscall.test]
os [sync.test]
os [syscall.test]
os.test
os_test [os.test]
os [time.test]
os/user [syscall.test]
path/filepath
path/filepath [internal/cpu.test]
path/filepath [internal/poll.test]
path/filepath [math/bits.test]
path/filepath [math.test]
path/filepath [os.test]
path/filepath [reflect.test]
path/filepath [runtime.test]
path/filepath [sort.test]
path/filepath [strconv.test]
path/filepath [sync.test]
path/filepath [syscall.test]
path/filepath [time.test]
path [runtime.test]
reflect
reflect [internal/cpu.test]
reflect [math/bits.test]
reflect [math.test]
reflect [reflect.test]
reflect [runtime.test]
reflect [strconv.test]
reflect [sync.test]
reflect.test
reflect_test [reflect.test]
regexp
regexp [internal/cpu.test]
regexp [math/bits.test]
regexp [math.test]
regexp [reflect.test]
regexp [runtime.test]
regexp [sort.test]
regexp [strconv.test]
regexp [sync.test]
regexp/syntax
regexp/syntax [internal/cpu.test]
regexp/syntax [math/bits.test]
regexp/syntax [math.test]
regexp/syntax [reflect.test]
regexp/syntax [runtime.test]
regexp/syntax [sort.test]
regexp/syntax [strconv.test]
regexp/syntax [sync.test]
runtime
runtime/cgo
runtime/debug
runtime/debug [internal/cpu.test]
runtime/debug [internal/poll.test]
runtime/debug [math/bits.test]
runtime/debug [math.test]
runtime/debug [os.test]
runtime/debug [reflect.test]
runtime/debug [runtime.test]
runtime/debug [sort.test]
runtime/debug [strconv.test]
runtime/debug [sync.test]
runtime/debug [syscall.test]
runtime/debug [time.test]
runtime/internal/atomic
runtime/internal/atomic.test
runtime/internal/atomic_test [runtime/internal/atomic.test]
runtime [internal/cpu.test]
runtime/internal/math
runtime/internal/math.test
runtime/internal/math_test [runtime/internal/math.test]
runtime/internal/sys
runtime/internal/sys.test
runtime/internal/sys_test [runtime/internal/sys.test]
runtime/pprof
runtime/pprof [fmt.test]
runtime/pprof [internal/cpu.test]
runtime/pprof [internal/fmtsort.test]
runtime/pprof [internal/poll.test]
runtime/pprof [math/bits.test]
runtime/pprof [math.test]
runtime/pprof [os.test]
runtime/pprof [reflect.test]
runtime/pprof [runtime.test]
runtime/pprof [sort.test]
runtime/pprof [strconv.test]
runtime/pprof [sync.test]
runtime/pprof [syscall.test]
runtime/pprof [time.test]
runtime [runtime.test]
runtime.test
runtime_test [runtime.test]
runtime/trace
runtime/trace [fmt.test]
runtime/trace [internal/cpu.test]
runtime/trace [internal/fmtsort.test]
runtime/trace [internal/poll.test]
runtime/trace [math/bits.test]
runtime/trace [math.test]
runtime/trace [os.test]
runtime/trace [reflect.test]
runtime/trace [runtime.test]
runtime/trace [sort.test]
runtime/trace [strconv.test]
runtime/trace [sync.test]
runtime/trace [syscall.test]
runtime/trace [time.test]
sort
sort [internal/cpu.test]
sort [math/bits.test]
sort [math.test]
sort [reflect.test]
sort [runtime.test]
sort [sort.test]
sort [strconv.test]
sort [sync.test]
sort.test
sort_test [sort.test]
strconv
strconv [internal/cpu.test]
strconv [math/bits.test]
strconv [math.test]
strconv [strconv.test]
strconv.test
strconv_test [strconv.test]
strings
strings [internal/cpu.test]
strings [runtime.test]
strings [sync.test]
sync
sync/atomic
sync/atomic.test
sync/atomic_test [sync/atomic.test]
sync [internal/cpu.test]
sync [runtime.test]
sync [sync.test]
sync.test
sync_test [sync.test]
syscall
syscall [internal/cpu.test]
syscall [runtime.test]
syscall [sync.test]
syscall [syscall.test]
syscall.test
syscall_test [syscall.test]
testing
testing [fmt.test]
testing [internal/cpu.test]
testing [internal/fmtsort.test]
testing [internal/poll.test]
testing/internal/testdeps
testing/internal/testdeps [fmt.test]
testing/internal/testdeps [internal/cpu.test]
testing/internal/testdeps [internal/fmtsort.test]
testing/internal/testdeps [internal/poll.test]
testing/internal/testdeps [math/bits.test]
testing/internal/testdeps [math.test]
testing/internal/testdeps [os.test]
testing/internal/testdeps [reflect.test]
testing/internal/testdeps [runtime.test]
testing/internal/testdeps [sort.test]
testing/internal/testdeps [strconv.test]
testing/internal/testdeps [sync.test]
testing/internal/testdeps [syscall.test]
testing/internal/testdeps [time.test]
testing/iotest [fmt.test]
testing [math/bits.test]
testing [math.test]
testing [os.test]
testing/quick [sync.test]
testing/quick [time.test]
testing [reflect.test]
testing [runtime.test]
testing [sort.test]
testing [strconv.test]
testing [sync.test]
testing [syscall.test]
testing [time.test]
text/tabwriter
text/tabwriter [internal/cpu.test]
text/tabwriter [runtime.test]
text/tabwriter [sync.test]
text/template/parse [runtime.test]
text/template [runtime.test]
time
time [internal/cpu.test]
time [runtime.test]
time [sync.test]
time [syscall.test]
time.test
time_test [time.test]
time [time.test]
unicode
unicode.test
unicode_test [unicode.test]
unicode/utf16
unicode/utf8
unicode/utf8.test
unicode/utf8_test [unicode/utf8.test]
unsafe

@bcmills bcmills closed this Mar 27, 2019

@alexedwards

This comment has been minimized.

Copy link
Author

commented Mar 27, 2019

Ah, I see.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.