From b8a679c30c5caa881d7617d47db73f363c0f2b26 Mon Sep 17 00:00:00 2001 From: gastown/crew/dennis Date: Tue, 20 Jan 2026 14:16:45 -0800 Subject: [PATCH] test: add cross-platform build verification test Verifies the codebase compiles for all supported platforms (Linux, macOS, Windows, FreeBSD on amd64/arm64). This catches cases where platform-specific code is called without providing stubs for all platforms. From PR #781. Co-Authored-By: Claude Opus 4.5 --- cmd/gt/build_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cmd/gt/build_test.go diff --git a/cmd/gt/build_test.go b/cmd/gt/build_test.go new file mode 100644 index 00000000..8cd7c33a --- /dev/null +++ b/cmd/gt/build_test.go @@ -0,0 +1,57 @@ +package main + +import ( + "os" + "os/exec" + "runtime" + "testing" +) + +// TestCrossPlatformBuild verifies that the codebase compiles for all supported +// platforms. This catches cases where platform-specific code (using build tags +// like //go:build !windows) is called from platform-agnostic code without +// providing stubs for all platforms. +func TestCrossPlatformBuild(t *testing.T) { + if testing.Short() { + t.Skip("skipping cross-platform build test in short mode") + } + + // Skip if not running on a platform that can cross-compile + // (need Go toolchain, not just running tests) + if os.Getenv("CI") == "" && runtime.GOOS != "darwin" && runtime.GOOS != "linux" { + t.Skip("skipping cross-platform build test on unsupported platform") + } + + platforms := []struct { + goos string + goarch string + cgo string + }{ + {"linux", "amd64", "0"}, + {"linux", "arm64", "0"}, + {"darwin", "amd64", "0"}, + {"darwin", "arm64", "0"}, + {"windows", "amd64", "0"}, + {"freebsd", "amd64", "0"}, + } + + for _, p := range platforms { + p := p // capture range variable + t.Run(p.goos+"_"+p.goarch, func(t *testing.T) { + t.Parallel() + + cmd := exec.Command("go", "build", "-o", os.DevNull, ".") + cmd.Dir = "." + cmd.Env = append(os.Environ(), + "GOOS="+p.goos, + "GOARCH="+p.goarch, + "CGO_ENABLED="+p.cgo, + ) + + output, err := cmd.CombinedOutput() + if err != nil { + t.Errorf("build failed for %s/%s:\n%s", p.goos, p.goarch, string(output)) + } + }) + } +}