From d307d42da5e122756dd9fa20e23fe8dc34e877db Mon Sep 17 00:00:00 2001 From: DonislawDev Date: Sun, 6 Sep 2026 21:00:46 +0200 Subject: [PATCH] guard: a build that cannot run is not a build that refused TestABuildWithoutTheBuildTagsRefusesAndSaysWhy shells out to the compiler and treats any error as the refusal it is looking for. A missing compiler arrives the same way, so on a machine with no Go it reported that the refusal "does not name build tags" - with the message empty, blaming the refusal rather than the environment. Measured on 2026-09-06: that is exactly what it did in the container tools/linux-check.py uses, which has no Go in it by design. It was the only test of the whole suite to fail there. This one cannot use the "an error means skip" shape the other ten callers of the toolchain use, because here an error is the answer. So it asks exec.LookPath first, the same idiom and for the same reason as TestABuildWithNoWindowInItSaysSoAndKeepsStandardOutputEmpty. Still passes where a compiler exists, and its existing mutation still turns it red, so the skip did not quietly make it a no-op. Co-Authored-By: Claude Opus 5 --- internal/guard/buildtags_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/guard/buildtags_test.go b/internal/guard/buildtags_test.go index fc84182..2819975 100644 --- a/internal/guard/buildtags_test.go +++ b/internal/guard/buildtags_test.go @@ -147,6 +147,22 @@ func compilesOurCode(line string) bool { // the build FAILS. A guard reading internal/format/avif for a build constraint // would stay green against a file that had stopped failing. func TestABuildWithoutTheBuildTagsRefusesAndSaysWhy(t *testing.T) { + // Asked before building, and this one cannot use the "an error means skip" + // shape the other ten callers of the toolchain use, because here an error + // is the ANSWER. A missing compiler and a compiler that refused both arrive + // as err != nil, so without this the test reads "the build failed, which is + // right" about a machine that never ran a build, and then reports that the + // message does not name build tags - with the message empty. + // + // Measured on 2026-09-06: that is exactly what it did in the container + // tools/linux-check.py uses, which has no Go in it by design. It was the + // only test of the suite to fail there, and it blamed the refusal rather + // than the environment. Same idiom and same reason as + // TestABuildWithNoWindowInItSaysSoAndKeepsStandardOutputEmpty. + if _, err := exec.LookPath("go"); err != nil { + t.Skipf("no Go toolchain here, so no build can be refused: %v", err) + } + out := filepath.Join(t.TempDir(), "untagged.bin") cmd := exec.Command("go", "build", "-o", out, "./cmd/tfg") cmd.Dir = filepath.Join("..", "..")