Description
This involves both documentation and the implementation (which I don't know it's intended or something to fix). Feel free to split this issue if necessary.
All experiments here are done outside GOPATH.
I have a two module testmod2
and testmod2/cmd
in one single repo.
The latest testmod2/cmd
(v0.0.2) depends on testmod2/v2
.
There are tests in testmod2/lib and testmod2/cmd packages.
$ git clone https://github.com/hyangah/testmod2.git /tmp/testmod2 $ cd /tmp/testmod2
$ go test ./... ok github.com/hyangah/testmod2/v2/lib 0.021s $ go test ./cmd/... go: finding github.com/hyangah/testmod2/v2/cmd latest can't load package: package github.com/hyangah/testmod2/v2/cmd: unknown import path "github.com/hyangah/testmod2/v2/cmd": cannot find module providing package github.com/hyangah/testmod2/v2/cmd
-
go test ./...
doesn't cross the module boundary, so tests in testmod2/cmd didn' run.go test ./cmd/...
doesn't work either because of the same reason. If we ever allow submodules in a single repo, this needs to be documented in https://tip.golang.org/cmd/go/#hdr-Package_lists_and_patterns. -
AFAIK, there is no automatic way to invoke all tests in the repo when submodules are involved. That's intended because module is like a separate workspace (as discussed in cmd/go: setting up a multi-module single repo is difficult #27056).
-
As specified in the [ Package lists and patterns] section,
all
can be used to test all modules the current module depends on. That implies testing in the standard libraries as well.
$ cd cmd $ go test all $ go test all ok bufio 0.141s ok bytes 1.862s ok compress/bzip2 0.147s --- FAIL: TestBlockHuff (0.00s) huffman_bit_writer_test.go:58: Testing "testdata/huffman-null-max.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok huffman_bit_writer_test.go:58: Testing "testdata/huffman-pi.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok huffman_bit_writer_test.go:58: Testing "testdata/huffman-rand-1k.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok huffman_bit_writer_test.go:58: Testing "testdata/huffman-rand-limit.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok huffman_bit_writer_test.go:58: Testing "testdata/huffman-rand-max.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok huffman_bit_writer_test.go:58: Testing "testdata/huffman-shifts.in" huffman_bit_writer_test.go:72: "testdata/huffman-shifts.in" != "testdata/huffman-shifts.golden" (see "testdata/huffman-shifts.in.got") huffman_bit_writer_test.go:74: open testdata/huffman-shifts.in.got: permission denied huffman_bit_writer_test.go:58: Testing "testdata/huffman-text-shift.in" huffman_bit_writer_test.go:72: "testdata/huffman-text-shift.in" != "testdata/huffman-text-shift.golden" (see "testdata/huffman-text-shift.in.got") huffman_bit_writer_test.go:74: open testdata/huffman-text-shift.in.got: permission denied huffman_bit_writer_test.go:58: Testing "testdata/huffman-text.in" huffman_bit_writer_test.go:72: "testdata/huffman-text.in" != "testdata/huffman-text.golden" (see "testdata/huffman-text.in.got") huffman_bit_writer_test.go:74: open testdata/huffman-text.in.got: permission denied huffman_bit_writer_test.go:58: Testing "testdata/huffman-zero.in" huffman_bit_writer_test.go:78: Output ok huffman_bit_writer_test.go:93: Reset ok huffman_bit_writer_test.go:365: EOF ok FAIL FAIL compress/flate 9.319s ok compress/gzip 0.057s ok compress/lzw 0.128s ...
This unfortunate case I encountered is the failures from the tests in the standard libraries. The above error was because I have no permission to write to the GOROOT. I think that's not a rare setup so running standard library tests doesn't seem to be a right choice.