Print the names of test packages as they are compiled

Viewed 164

Running go build or go install with -v will "print the names of packages as they are compiled". How do I get the same when I run go test? -v there means to output test information. When running tests on some packages, they can unexpectedly take a long time, due to long compiles for some dependencies. I'd like some visibility in to that process.

The best option I can think of is to try something like go build -v ./..., but I don't know if that will include building the dependencies of tests, and it's a separate step.

1 Answers

Using go build is not viable:

When compiling packages, build ignores files that end in '_test.go'.

The test command doesn't have the flag to print package names. -v has a different meaning than build.

A roundabout solution is to use the debug flag -x and pipe the output to grep. The output of -x is unwieldy, because it's debug and it's not meant to be used in actual command pipelines.

go test -x ./... 2>&1 | grep -E "^cd"

The lines that start with cd are those containing the packages that are being compiled, as it cd's into them.

This includes the dependencies of those tests and back and forth between test packages and the working dir .. Not a perfect solution, but it's something.

Related