Cross-version and platform test matrices
Cross-version and platform test matrices
A test matrix lists combinations of toolchain, GOOS, GOARCH, cgo mode and relevant features that you promise to support. Run tests with the oldest supported toolchain and a maintained newer toolchain; test actual operating systems where behavior differs. A cross-build proves compilation, not execution. A successful Linux race run says nothing about race-detector availability on another target. Define required cells before evaluating results, and distinguish missing from failed evidence.
package main
import ( "fmt" "strings")
type Cell struct { Toolchain, OS, Arch string CGO bool}
func matrix(versions, targets []string) []Cell { var out []Cell for _, v := range versions { for _, target := range targets { os, arch, ok := strings.Cut(target, "/") if !ok || os == "" || arch == "" { panic("bad target") } out = append(out, Cell{v, os, arch, false}) } } return out}func main() { for _, c := range matrix([]string{"go1.22.0", "go1.23.2"}, []string{"linux/amd64", "windows/amd64"}) { fmt.Println(c.Toolchain, c.OS, c.Arch, c.CGO) }}These historical versions form an illustrative matrix, not a current security support recommendation. A real plan selects maintained releases and includes cgo where required. go tool dist list lists compiler targets, not a list of environments with full support for your program. Compile tests for a foreign target with GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go test -c -o demo.test.exe .; run that executable on Windows to establish behavior. For native runs use go test -count=1 ./... and, on supported targets, go test -race -count=1 ./....
Expected output:
go1.22.0 linux amd64 falsego1.22.0 windows amd64 falsego1.23.2 linux amd64 falsego1.23.2 windows amd64 falseKeep missing execution evidence visible
package main
import ( "fmt")
type Result struct{ Built, Ran, Passed bool }
func status(r Result) string { if !r.Built { return "build-unverified-or-failed" } if !r.Ran { return "not-run" } if !r.Passed { return "fail" } return "pass"}func main() { for _, r := range []Result{{true, false, false}, {true, true, false}, {true, true, true}} { fmt.Println(status(r)) }}The toy record combines missing and failed build evidence; in a real report use separate states for those too. Keep exact compiler version, target, flags, command, exit code and logs per cell. Do not silently drop unsupported targets to make a matrix green. Here only the installed Linux Go 1.23.2 compiler can execute native fixtures; other compilers and native targets are not verified.
Expected output:
not-runfailpassTry it locally
Given required cell IDs and an evidence map, list missing or unsuccessful cells in required order. Verify that a cross-build-only cell cannot pass.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Toolchain and compatibility 07: Cross-version and platform test matrices
Check the lesson objective before moving on.
A Windows test binary builds on Linux. What evidence is missing?
What should a missing required matrix cell be reported as?