Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/arch"
|
||||
@@ -64,3 +65,62 @@ func TestGasmEncodable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestBuildConstraint pins the //go:build reader: the constraint governs the
|
||||
// leading comment block, the first non-comment line ends it (a tag below a
|
||||
// #include governs nothing, exactly as go/build drops it), and a file
|
||||
// without one admits every target.
|
||||
func TestBuildConstraint(t *testing.T) {
|
||||
admits := func(src, goarch, goos string) bool {
|
||||
t.Helper()
|
||||
e := buildConstraint(src)
|
||||
if e == nil {
|
||||
return true
|
||||
}
|
||||
return e.Eval(constraintTags(goarch, goos))
|
||||
}
|
||||
const ret = "TEXT \xc2\xb7f(SB), NOSPLIT, $0\n\tRET\n"
|
||||
cases := []struct {
|
||||
name string
|
||||
src string
|
||||
amd64, arm64 bool
|
||||
}{
|
||||
{"no constraint", ret, true, true},
|
||||
{"x86 only", "//go:build 386 || amd64\n\n" + ret, true, false},
|
||||
{"arm64 and linux", "//go:build arm64 && linux\n\n" + ret, false, true},
|
||||
{"msan never", "//go:build msan\n\n" + ret, false, false},
|
||||
{"experiment never", "//go:build goexperiment.runtimesecret\n\n" + ret, false, false},
|
||||
{"below an include governs nothing", "#include \"textflag.h\"\n//go:build amd64\n" + ret, true, true},
|
||||
{"unparsable narrows nothing", "//go:build (amd64\n" + ret, true, true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := admits(c.src, "amd64", runtime.GOOS); got != c.amd64 {
|
||||
t.Errorf("amd64 admission = %v, want %v", got, c.amd64)
|
||||
}
|
||||
if got := admits(c.src, "arm64", runtime.GOOS); got != c.arm64 {
|
||||
t.Errorf("arm64 admission = %v, want %v", got, c.arm64)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestConstraintTags pins the tag set a plain `go build` sets: the GOOS and
|
||||
// GOARCH, gc, unix on the unix-like GOOSes; nothing else is ever true.
|
||||
func TestConstraintTags(t *testing.T) {
|
||||
ok := constraintTags("amd64", "linux")
|
||||
for _, tag := range []string{"amd64", "linux", "gc", "unix"} {
|
||||
if !ok(tag) {
|
||||
t.Errorf("tag %q = false, want true", tag)
|
||||
}
|
||||
}
|
||||
for _, tag := range []string{"arm64", "freebsd", "darwin", "cgo", "race", "msan", "goexperiment.runtimesecret"} {
|
||||
if ok(tag) {
|
||||
t.Errorf("tag %q = true, want false", tag)
|
||||
}
|
||||
}
|
||||
fb := constraintTags("arm64", "freebsd")
|
||||
if !fb("unix") {
|
||||
t.Error("unix on freebsd = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user