Test that New without WithSeed fails naming it, that the CLI without --seed draws afresh each run, and seed every test's New

This commit is contained in:
2026-10-12 18:10:57 +02:00
committed by Lillem4n
parent 1a5b632b90
commit 3ae8b9f1b1
19 changed files with 91 additions and 87 deletions
+6 -6
View File
@@ -187,12 +187,12 @@ func TestRepeatProductAlongAPathIsCapped(t *testing.T) {
"b": `{"format":"x","repeat":2048}`,
},
} {
_, err := New(WithDataPath(writeData(t, files)))
_, err := New(WithSeed(1), WithDataPath(writeData(t, files)))
if err == nil || !strings.Contains(err.Error(), "repeat") || !strings.Contains(err.Error(), "1048576") {
t.Errorf("%s: New = %v, want the repeat product rejected naming the maximum", name, err)
}
}
if _, err := New(WithDataPath(writeData(t, map[string]string{
if _, err := New(WithSeed(1), WithDataPath(writeData(t, map[string]string{
"cat": `{"format":"{a}{c}","repeat":1024,"a":{"format":"{b}","repeat":1024,"b":"x"},"c":{"format":"y","repeat":1024}}`,
}))); err != nil {
t.Errorf("New = %v, want 1024 x 1024 along one path accepted", err)
@@ -205,11 +205,11 @@ func TestNewErrors(t *testing.T) {
if err := os.WriteFile(file, []byte("{}"), 0o644); err != nil {
t.Fatal(err)
}
if _, err := New(WithDataPath(file)); err == nil || !strings.Contains(err.Error(), "xx_XX: not a directory") {
if _, err := New(WithSeed(1), WithDataPath(file)); err == nil || !strings.Contains(err.Error(), "xx_XX: not a directory") {
t.Errorf("New(file) = %v, want not-a-directory error", err)
}
// Invalid JSON in a category file fails.
if _, err := New(WithDataPath(writeData(t, map[string]string{"broken": `{ not json`}))); err == nil {
if _, err := New(WithSeed(1), WithDataPath(writeData(t, map[string]string{"broken": `{ not json`}))); err == nil {
t.Error("New(invalid JSON) = nil error")
}
// An option that cannot take effect, and a category or folder no dot path can
@@ -300,7 +300,7 @@ func TestNewErrors(t *testing.T) {
},
}
for name, c := range rejected {
_, err := New(WithDataPath(writeData(t, c.files)))
_, err := New(WithSeed(1), WithDataPath(writeData(t, c.files)))
if err == nil {
t.Errorf("%s: New = nil error, want it rejected at load", name)
continue
@@ -328,7 +328,7 @@ func TestNewErrors(t *testing.T) {
"repeated reference arm": {map[string]string{"a": `"x"`, "b": `"{/a|/a}"`}, "b", "x"},
}
for name, c := range accepted {
f, err := New(WithDataPath(writeData(t, c.files)))
f, err := New(WithSeed(1), WithDataPath(writeData(t, c.files)))
if err != nil {
t.Errorf("%s: New = %v, want it accepted", name, err)
continue