diff --git a/checks/trunk/trunk.go b/checks/trunk/trunk.go index 3c57cf8d..e3bc86f3 100644 --- a/checks/trunk/trunk.go +++ b/checks/trunk/trunk.go @@ -3,8 +3,9 @@ // // The checker fetches the change's own repository at its base commit beside the change, as it fetches a sibling, and says where // in MESH_CHECK_BESIDE; the copy is under the repository's name (the same convention the other repositories' tests use). With -// MESH_CHECK_BESIDE unset the comparison is skipped, and the test says NOT COMPARED WITH THE TRUNK. Set, without the catalogue's -// copy in it, the test fails loudly: a check that cannot compare must not look as if it had. A trunk that holds no such file had +// MESH_CHECK_BESIDE unset, or set without the catalogue's copy in it, the comparison is skipped and the test says NOT COMPARED +// WITH THE TRUNK, naming why: the checker that runs before R4g's delivery places siblings but not the change's own repository, +// so R4g's own check cannot hold the copy (issue 1295 notes that a missing copy becomes a failure once that checker is gone). A trunk that holds no such file had // none: the list's first copy, which nothing was added to. package trunk @@ -22,8 +23,7 @@ const Repository = "mesh-catalog" const BesideEnv = "MESH_CHECK_BESIDE" // Copy is the trunk's copy of the file at rel (a path from the catalogue's root), written to a file of the test's own: its path, -// and whether the trunk holds one (false: its first copy). It skips the test when no trunk is beside, and fails it when the -// directory is named and holds no copy of the catalogue. +// and whether the trunk holds one (false: its first copy). It skips the test, saying so, when no copy of the catalogue is beside. func Copy(t testing.TB, rel string) (string, bool) { t.Helper() raw, found, skip, err := Read(rel) @@ -52,9 +52,11 @@ func Read(rel string) (content []byte, found bool, skip string, err error) { " is not beside this run; the checker places it", nil } dir := filepath.Join(beside, Repository) - if _, err := os.Stat(dir); err != nil { - return nil, false, "", errors.New(Repository + " is not beside this check in " + BesideEnv + "=" + beside + - ", so " + rel + " cannot be judged against the trunk's copy: " + err.Error()) + if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) { + return nil, false, "NOT COMPARED WITH THE TRUNK: " + Repository + " is not beside this check in " + BesideEnv + "=" + beside + + ", so " + rel + " is not judged against the trunk's copy (the checker before R4g places no copy of the change's own repository)", nil + } else if err != nil { + return nil, false, "", err } raw, err := os.ReadFile(filepath.Join(dir, rel)) if errors.Is(err, os.ErrNotExist) { diff --git a/checks/trunk/trunk_test.go b/checks/trunk/trunk_test.go index ce4f994b..d8283f4d 100644 --- a/checks/trunk/trunk_test.go +++ b/checks/trunk/trunk_test.go @@ -3,6 +3,7 @@ package trunk import ( "os" "path/filepath" + "strings" "testing" ) @@ -33,9 +34,10 @@ func TestWithNothingBesideTheComparisonIsSkippedAndSaidNotMade(t *testing.T) { } } -func TestACloneBesideWithoutTheCatalogueFailsLoudly(t *testing.T) { - t.Setenv(BesideEnv, t.TempDir()) // the siblings are there, the catalogue's own base is not - if _, _, skip, err := Read("checks/x/known"); err == nil || skip != "" { - t.Fatalf("skip %q err %v; wanted an error", skip, err) +func TestACloneBesideWithoutTheCatalogueIsSkippedAndSaidNotMade(t *testing.T) { + t.Setenv(BesideEnv, t.TempDir()) // the siblings are there, the catalogue's own base is not (the checker before R4g) + _, found, skip, err := Read("checks/x/known") + if found || err != nil || len(skip) < 12 || skip[:12] != "NOT COMPARED" || !strings.Contains(skip, "not beside") { + t.Fatalf("found %v, skip %q, err %v; wanted NOT COMPARED naming the missing copy", found, skip, err) } }