package runner
import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
)
// THE RUNNER BUILDS FOR EVERY PLATFORM THE FORGE SERVES IT FOR.
//
// The downloads are built by scripts/build-linux.sh, and a runner that
// fails to build for one platform broke the whole published set
// (isolate.go called syscall.Dup2, which linux/arm64 and windows lack).
// The list is read from the script, so a platform added there is
// covered here.
func TestTheRunnerBuildsForEveryPlatformItShips(t *testing.T) {
if testing.Short() {
t.Skip("cross-builds are slow")
}
root, err := filepath.Abs("../..")
if err != nil {
t.Fatal(err)
}
script, err := os.ReadFile(filepath.Join(root, "scripts", "build-linux.sh"))
if err != nil {
t.Fatal(err)
}
m := regexp.MustCompile(`(?m)^for target in ([^;]+); do`).FindSubmatch(script)
if m == nil {
t.Fatal("FAIL: scripts/build-linux.sh has no `for target in ...; do` list to read")
}
targets := strings.Fields(string(m[1]))
if len(targets) < 2 {
t.Fatalf("FAIL: read targets %v", targets)
}
for _, target := range targets {
goos, goarch, ok := strings.Cut(target, "/")
if !ok {
t.Fatalf("FAIL: target %q is not os/arch", target)
}
cmd := exec.Command("go", "build", "-o", os.DevNull, "./cmd/quarry-runner")
cmd.Dir = root
cmd.Env = append(os.Environ(), "CGO_ENABLED=0", "GOOS="+goos, "GOARCH="+goarch)
if out, err := cmd.CombinedOutput(); err != nil {
t.Errorf("FAIL: quarry-runner does not build for %s: %v\n%s", target, err, out)
}
}
t.Logf("ok: quarry-runner builds for %v", targets)
}