Answer architecture round 2: New's doc comment wraps whole, the README's stream needs no seeded, and the system-seed test reports each run's exit code and stderr

This commit is contained in:
2026-10-12 18:18:46 +02:00
committed by Lillem4n
parent 8e8fa92e77
commit cde9e354c5
3 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -431,7 +431,7 @@ error on every later call; a `datatype` in a tag other than the one its Go type
refused, naming that type.
A `*Generator` is safe for concurrent use; a sequence is reproducible only
when drawn from one goroutine. Changing how a value is composed shifts the seeded
when drawn from one goroutine. Changing how a value is composed shifts the
stream for that value and everything drawn after it.
### Your own CLI
+8 -5
View File
@@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
@@ -129,10 +128,14 @@ func TestRunDotPath(t *testing.T) {
}
func TestRunWithoutASeedTakesTheSystemSeed(t *testing.T) {
var drawn, seeded bytes.Buffer
run("fejkdata", shipped, nil, 42, strings.NewReader("{uuid()}"), &drawn, io.Discard)
run("fejkdata", shipped, []string{"--seed", "42"}, 7, strings.NewReader("{uuid()}"), &seeded, io.Discard)
if drawn.String() == "" || drawn.String() != seeded.String() {
var drawn, seeded, errb bytes.Buffer
if code := run("fejkdata", shipped, nil, 42, strings.NewReader("{uuid()}"), &drawn, &errb); code != 0 {
t.Fatalf("run with system seed 42 = %d, stderr=%q", code, errb.String())
}
if code := run("fejkdata", shipped, []string{"--seed", "42"}, 7, strings.NewReader("{uuid()}"), &seeded, &errb); code != 0 {
t.Fatalf("run --seed 42 = %d, stderr=%q", code, errb.String())
}
if drawn.String() != seeded.String() {
t.Fatalf("run with system seed 42 = %q, run --seed 42 = %q; want the same draw", drawn.String(), seeded.String())
}
}
+2 -2
View File
@@ -96,8 +96,8 @@ func (loadError) Is(target error) bool { return target == ErrLoad }
// It errors on a missing directory, invalid JSON or invalid data. Given only
// WithDataFS() with no modules, New loads no data, and the generator renders templates
// that read none. A source whose .fejkdata.json carries an index, as each shipped
// module's does, loads each category on the first call reaching it. Data failing to load, in New or on that first call, gives an error matching
// [ErrLoad].
// module's does, loads each category on the first call reaching it. Data failing to
// load, in New or on that first call, gives an error matching [ErrLoad].
func New(opts ...Option) (*Generator, error) {
var c config
for _, opt := range opts {