Artifact 29a314bdc4faec3da3af6025f2bc74a8f86caf556801689ee621b8c5b5525683:
- File
testutil/testutil_test.go
— part of check-in
[f804878bd3]
at
2026-07-22 23:58:46
on branch trunk
— test: route every fossil-binary gate through one REQUIRE_FOSSIL_BIN helper (#125)
* test: route fossil-binary tests through one REQUIRE_FOSSIL_BIN helper
REQUIRE_FOSSIL_BIN=1 turns a missing fossil binary into a test failure instead of an invisible skip, but only internal/manifest honored it. The six other fossil-dependent sites each did their own exec.LookPath + unconditional t.Skip, so on those a run with no fossil was byte-identical to a passing one.
Add testutil.RequireFossilBin, which resolves the binary the same way FossilBinary does (FOSSIL_BIN override, then PATH) and either skips or fails based on REQUIRE_FOSSIL_BIN. Route testutil.NewTestRepo, both internal/delta CLI round-trips, the four internal/merge validation tests, the internal/xfer sanity check, and the ls-branch-tip repro through it, deleting their bespoke lookup+skip logic. CI already sets REQUIRE_FOSSIL_BIN=1 on the unit-test steps, so this makes all seven sites fail loud on absence while local runs without fossil stay opt-in.
* test: route every fossil-binary gate through RequireFossilBin
The first pass left six sites still deciding for themselves whether a missing fossil binary is a skip or a failure. Three of them (internal/sync's startFossilServer and its two integration tests, manifest's two rebuild tests, the root TestPhaseB_Integration, and hash's TestSHA1_FossilValidation) skipped unconditionally, so with REQUIRE_FOSSIL_BIN=1 and no fossil on PATH those packages still reported ok -- the exact silent pass the flag exists to prevent. The other three had hand-rolled copies of the flag check, which is the duplication that let the original drift happen.
All of them now call testutil.RequireFossilBin, and HasFossil is gone: it was a second, skip-only way to ask the same question, and it is what produced the sites that ignored the flag.
Also validate the FOSSIL_BIN override with LookPath, so a stale path reports "fossil not found" instead of surfacing later as a raw fork/exec error.
* test: resolve fossil binary via RequireFossilBin at remaining call sites
* fix: correct stale module path missed by rebase auto-merge
Three imports added by earlier commits in this branch predated the rebase target and had no corresponding line on main to conflict against, so git's auto-merge carried the old module path through verbatim. (user: [email protected], size: 1311) [annotate] [blame] [check-ins using]
package testutil import ( "os" "testing" ) func TestNewTestRepo(t *testing.T) { tr := NewTestRepo(t) if _, err := os.Stat(tr.Path); err != nil { t.Fatalf("repo file does not exist: %v", err) } } func TestFossilRebuild(t *testing.T) { tr := NewTestRepo(t) tr.FossilRebuild(t) } func TestFossilSQL(t *testing.T) { tr := NewTestRepo(t) out := tr.FossilSQL(t, "SELECT count(*) FROM blob;") if out != "1" { t.Fatalf("FossilSQL count(*) = %q, want %q", out, "1") } } func TestFossilBinary(t *testing.T) { path := RequireFossilBin(t) if _, err := os.Stat(path); err != nil { t.Fatalf("fossil binary not found at %q: %v", path, err) } } // TestRequireFossilBin verifies the found path: when a fossil binary is // resolvable, RequireFossilBin returns exactly the path FossilBinary resolves // and neither skips nor fails. The not-found branches (skip vs. Fatalf when // REQUIRE_FOSSIL_BIN=1) are exercised end-to-end by the CI test step, which // runs the whole suite with REQUIRE_FOSSIL_BIN=1 against an installed fossil. func TestRequireFossilBin(t *testing.T) { want := FossilBinary() if want == "" { // Fails under REQUIRE_FOSSIL_BIN=1, skips otherwise. RequireFossilBin(t) } got := RequireFossilBin(t) if got != want { t.Fatalf("RequireFossilBin = %q, want %q", got, want) } }