From cde9e354c581b57b77dc85c4db7ad1d2dfc077b1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 12 Oct 2026 18:18:46 +0200 Subject: [PATCH] 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 --- README.md | 2 +- cli/cli_test.go | 13 ++++++++----- fejkdata.go | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4cf08bb..86ac9c9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cli/cli_test.go b/cli/cli_test.go index 7f80d96..55ee115 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -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()) } } diff --git a/fejkdata.go b/fejkdata.go index 93430d5..05f88a1 100644 --- a/fejkdata.go +++ b/fejkdata.go @@ -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 {