Pin readField's unheld-path panic past the trace check, and fail the gathered-reads test when nothing traced

This commit is contained in:
2026-09-29 01:15:22 +02:00
committed by Lillem4n
parent 77f79de443
commit 5a87dc04d3
2 changed files with 10 additions and 5 deletions
+9 -4
View File
@@ -61,8 +61,9 @@ func fenceRoots(t *testing.T, f *Generator) ([]fenceRoot, map[string]*table) {
func TestEveryReadARenderMakesIsGathered(t *testing.T) {
f := fenceCorpus(t)
roots, tables := fenceRoots(t, f)
traced := 0
for _, root := range roots {
wantGathered(t, tables, root.label, renderDraws(root.t).reads, func(trace renderTrace) { renderRoot(f.rand, root.t, trace) })
traced += wantGathered(t, tables, root.label, renderDraws(root.t).reads, func(trace renderTrace) { renderRoot(f.rand, root.t, trace) })
if !root.t.isRecord || len(root.t.fields) == 0 {
continue
}
@@ -70,11 +71,14 @@ func TestEveryReadARenderMakesIsGathered(t *testing.T) {
if err != nil {
t.Fatalf("%s: recordOf = %v", root.label, err)
}
wantGathered(t, tables, root.label+" as a record", columnDraws(root.t, sortedNames(root.t.fields)).reads, func(trace renderTrace) { renderRecordRoot(f.rand, root.t, columns, trace) })
traced += wantGathered(t, tables, root.label+" as a record", columnDraws(root.t, sortedNames(root.t.fields)).reads, func(trace renderTrace) { renderRecordRoot(f.rand, root.t, columns, trace) })
}
if traced == 0 {
t.Error("no render traced a reference read, so the comparison proved nothing")
}
}
func wantGathered(t *testing.T, tables map[string]*table, label string, gathered []pathRead, renderOnce func(renderTrace)) {
func wantGathered(t *testing.T, tables map[string]*table, label string, gathered []pathRead, renderWith func(renderTrace)) int {
t.Helper()
var reads []pathRead
type traceKey struct {
@@ -96,13 +100,14 @@ func wantGathered(t *testing.T, tables map[string]*table, label string, gathered
}
}
for i := 0; i < 5; i++ {
renderOnce(trace)
renderWith(trace)
}
for _, r := range reads {
if !gathers(gathered, r) {
t.Errorf("%s: the render read {%s} in draw group %q from %s, and drawWalk gathered no such read", label, r.a.spelling, r.at.group, spellPins(&r.at.pins))
}
}
return len(reads)
}
func gathers(gathered []pathRead, r pathRead) bool {
+1 -1
View File
@@ -766,6 +766,6 @@ func TestReadFieldPanicsOnAnUnheldPath(t *testing.T) {
t.Fatal("not a template")
}
mustPanic(t, "unheld arm with a path", func() {
readField(engine(1).rand, tm, nil, renderScope{}, arm{spelling: "w.x", key: "w", tail: []string{"x"}, path: "w.x"})
readField(engine(1).rand, tm, nil, renderScope{set: &holdSet{}}, arm{spelling: "w.x", key: "w", tail: []string{"x"}, path: "w.x"})
})
}