mesh-build-node kept the first fifteen lines of node --test's output, so a passing line of the first file stood for the failure. Both build modules now parse through the SDK (go test -json, node --test's TAP report written to a file, the type-check and go vet as console failures), name themselves in the result, and run the SDK's captured cases; the catalogue check failurekit refuses a node-build-* module with a test step whose tests do not run the kit.
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package failurekit
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// 1901/AC7: a build module with a test step and no kit is refused, one that runs the kit passes, one with no test step is
|
|
// exempt, and a module that claims no node-build-* seat is not judged.
|
|
func TestABuildModuleWithATestStepMustRunTheKit(t *testing.T) {
|
|
root := t.TempDir()
|
|
kit := "package main\n\nimport \"git.novox.be/novox/mesh-sdk/go/buildstep/conformance\"\n\nfunc TestKit(t *testing.T) { conformance.Run(t, conformance.GoTest, nil) }\n"
|
|
for path, body := range map[string]string{
|
|
"modules/a/module.json": `{"claims":[{"name":"node-build-a"}],"tools":["build_a_fetch","build_a_test"]}`,
|
|
"modules/a/cmd/a/check_test.go": "package main\n",
|
|
"modules/b/module.json": `{"claims":[{"name":"node-build-b"}],"tools":[{"name":"build_b_test"}]}`,
|
|
"modules/b/cmd/b/kit_test.go": kit,
|
|
"modules/c/module.json": `{"claims":[{"name":"node-build-c"}],"tools":["build_c_build"]}`,
|
|
"modules/d/module.json": `{"claims":[{"name":"other"}],"tools":["d_test"]}`,
|
|
"modules/e/module.json": `{"claims":[{"name":"node-build-e"}],"tools":["build_e_test"]}`,
|
|
"modules/e/cmd/e/kit.go": kit, // not a test file
|
|
} {
|
|
p := filepath.Join(root, path)
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(p, []byte(body), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
got, err := Judge(root)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := map[string]string{"a": "refused", "b": "passes", "c": "exempt", "e": "refused"}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("judged %+v, want a, b, c and e", got)
|
|
}
|
|
for _, j := range got {
|
|
is := "passes"
|
|
if j.Refused != "" {
|
|
is = "refused"
|
|
} else if j.Exempt != "" {
|
|
is = "exempt"
|
|
}
|
|
if is != want[j.Module] {
|
|
t.Errorf("%s %s (%+v), want it %s", j.Module, is, j, want[j.Module])
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every build module of this catalogue with a test step runs the kit.
|
|
func TestTheCataloguesBuildModulesRunTheKit(t *testing.T) {
|
|
got, err := Judge(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) == 0 {
|
|
t.Fatal("no module claims a node-build-* seat: the check reads the wrong tree")
|
|
}
|
|
for _, j := range got {
|
|
switch {
|
|
case j.Refused != "":
|
|
t.Errorf("%s: %s", j.Module, j.Refused)
|
|
case j.Exempt != "":
|
|
t.Logf("%s is exempt: %s", j.Module, j.Exempt)
|
|
}
|
|
}
|
|
}
|