Skip to content

Commit d307d42

Browse files
donislawdevclaude
andcommitted
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 <noreply@anthropic.com>
1 parent fe2fbdb commit d307d42

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎internal/guard/buildtags_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ func compilesOurCode(line string) bool {
147147
// the build FAILS. A guard reading internal/format/avif for a build constraint
148148
// would stay green against a file that had stopped failing.
149149
func TestABuildWithoutTheBuildTagsRefusesAndSaysWhy(t *testing.T) {
150+
// Asked before building, and this one cannot use the "an error means skip"
151+
// shape the other ten callers of the toolchain use, because here an error
152+
// is the ANSWER. A missing compiler and a compiler that refused both arrive
153+
// as err != nil, so without this the test reads "the build failed, which is
154+
// right" about a machine that never ran a build, and then reports that the
155+
// message does not name build tags - with the message empty.
156+
//
157+
// Measured on 2026-09-06: that is exactly what it did in the container
158+
// tools/linux-check.py uses, which has no Go in it by design. It was the
159+
// only test of the suite to fail there, and it blamed the refusal rather
160+
// than the environment. Same idiom and same reason as
161+
// TestABuildWithNoWindowInItSaysSoAndKeepsStandardOutputEmpty.
162+
if _, err := exec.LookPath("go"); err != nil {
163+
t.Skipf("no Go toolchain here, so no build can be refused: %v", err)
164+
}
165+
150166
out := filepath.Join(t.TempDir(), "untagged.bin")
151167
cmd := exec.Command("go", "build", "-o", out, "./cmd/tfg")
152168
cmd.Dir = filepath.Join("..", "..")

0 commit comments

Comments
 (0)