Compile tests - check for breakages


When editing a lot of areas of the Juju source code, sometimes you just want to know did I break any other tests inside Juju without running go test -v ./... -check.v in the root of the project.

One solution that I’m playing around with is taking advantage of -c argument to go test.

The following script runs and compiles the test code without running any tests:
Note: the script will use all your CPUs minus 1, so your system won’t come to a halt.

# Copyright 2019 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.
go_test () {
	go test -c -run=nope $1
export -f go_test
MAX_CPU="$(($(nproc --all)-1))"
go list -f '{{.Dir}}' | xargs -n 1 -P $MAX_CPU bash -c 'go_test "$@"' --

Although it’s slow, it’s still faster than running CI to check the damage or using go test -v ./... -check.v


Is there a reason you need -run when you are running ‘-c’, I thought it never ran anything anyway, just compiled it.


Couldn’t get it to work… no idea why