diff --git a/config.go b/config.go index 3d8b295..2800c1d 100644 --- a/config.go +++ b/config.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "strings" + "unicode/utf8" ) const ( @@ -37,25 +38,35 @@ type failure[T any] struct { // String implements [fmt.Stringer] for failure, allowing it to print itself in the test log. func (f failure[T]) String() string { s := &strings.Builder{} - s.WriteByte('\n') - - s.WriteString(f.cfg.title) - s.WriteByte('\n') - s.WriteString(strings.Repeat("-", len(f.cfg.title))) - s.WriteString("\n\n") + f.cfg.writeHeader(s) fmt.Fprintf(s, "Got:\t%+v\n", f.got) fmt.Fprintf(s, "Wanted:\t%+v\n", f.want) - if f.cfg.context != "" { - fmt.Fprintf(s, "\n(%s)\n", f.cfg.context) - } + f.cfg.writeFooter(s) + + return s.String() +} - if f.cfg.reason != "" { - fmt.Fprintf(s, "\nBecause: %s\n", f.cfg.reason) +// writeHeader writes the title block (leading blank line, title, underline, blank line) +// to s. The underline is sized by rune count so multi-byte titles align correctly. +func (c config) writeHeader(s *strings.Builder) { + s.WriteByte('\n') + s.WriteString(c.title) + s.WriteByte('\n') + s.WriteString(strings.Repeat("-", utf8.RuneCountInString(c.title))) + s.WriteString("\n\n") +} + +// writeFooter writes any optional context and reason lines to s. +func (c config) writeFooter(s *strings.Builder) { + if c.context != "" { + fmt.Fprintf(s, "\n(%s)\n", c.context) } - return s.String() + if c.reason != "" { + fmt.Fprintf(s, "\nBecause: %s\n", c.reason) + } } // Option is a configuration option for a test. @@ -79,7 +90,7 @@ func (o option) apply(cfg *config) error { // two floating point numbers before they are considered equal. This setting is only // used in [NearlyEqual] and [NotNearlyEqual]. // -// Setting threshold to ±math.Inf is an error and will fail the test. +// Setting threshold to ±[math.Inf] is an error and will fail the test. // // The default is 1e-8, a sensible default for most cases. func FloatEqualityThreshold(threshold float64) Option { @@ -137,12 +148,12 @@ func Title(title string) Option { // test.Ok(t, err, test.Context("something complicated failed")) func Context(format string, args ...any) Option { f := func(cfg *config) error { - if format == "" { + context := strings.TrimSpace(fmt.Sprintf(format, args...)) + if context == "" { return errors.New("cannot set context to an empty string") } - context := fmt.Sprintf(format, args...) - cfg.context = strings.TrimSpace(context) + cfg.context = context return nil } diff --git a/test.go b/test.go index 446b899..7e3122d 100644 --- a/test.go +++ b/test.go @@ -11,7 +11,7 @@ import ( "io" "math" "os" - "sync" + "strings" "testing" "go.followtheprocess.codes/diff" @@ -19,6 +19,11 @@ import ( "go.followtheprocess.codes/hue" ) +// errAny is a sentinel rendered in failure output when the caller expected +// an error but got nil — it reads more naturally than the previous +// placeholder errors.New("error") (which printed "Wanted: error"). +var errAny = errors.New("") + // ColorEnabled sets whether the output from this package is colourised. // // test defaults to automatic detection based on a number of attributes: @@ -125,7 +130,7 @@ func EqualFunc[T any](tb testing.TB, got, want T, equal func(a, b T) bool, optio } } -// NotEqualFunc is like [Equal] but accepts a custom comparator function, useful +// NotEqualFunc is like [NotEqual] but accepts a custom comparator function, useful // when the items to be compared do not implement the comparable generic constraint. // // The signature of the comparator is such that standard library functions such as @@ -133,8 +138,8 @@ func EqualFunc[T any](tb testing.TB, got, want T, equal func(a, b T) bool, optio // // The comparator should return true if the two items should be considered equal. // -// test.EqualFunc(t, []int{1, 2, 3}, []int{1, 2, 3}, slices.Equal) // Fails -// test.EqualFunc(t, []int{1, 2, 3}, []int{4, 5, 6}, slices.Equal) // Passes +// test.NotEqualFunc(t, []int{1, 2, 3}, []int{1, 2, 3}, slices.Equal) // Fails +// test.NotEqualFunc(t, []int{1, 2, 3}, []int{4, 5, 6}, slices.Equal) // Passes func NotEqualFunc[T any](tb testing.TB, got, want T, equal func(a, b T) bool, options ...Option) { tb.Helper() @@ -181,13 +186,53 @@ func NearlyEqual[T ~float32 | ~float64](tb testing.TB, got, want T, options ...O } } - diff := math.Abs(float64(got - want)) - if diff > cfg.floatEqualityThreshold { + delta := math.Abs(float64(got - want)) + if delta > cfg.floatEqualityThreshold { cfg.reason = fmt.Sprintf( "Difference %v - %v = %v exceeds maximum tolerance of %v", got, want, - diff, + delta, + cfg.floatEqualityThreshold, + ) + fail := failure[T]{ + got: got, + want: want, + cfg: cfg, + } + tb.Fatal(fail.String()) + } +} + +// NotNearlyEqual is the opposite of [NearlyEqual]. It fails when got and want +// are within the float equality threshold of each other. +// +// The threshold defaults to 1e-8 and can be configured with the +// [FloatEqualityThreshold] option. +// +// test.NotNearlyEqual(t, 3.0000001, 3.0) // Passes, different enough +// test.NotNearlyEqual(t, 3.0000000001, 3.0) // Fails, too close to be considered different +func NotNearlyEqual[T ~float32 | ~float64](tb testing.TB, got, want T, options ...Option) { + tb.Helper() + + cfg := defaultConfig() + cfg.title = "NearlyEqual" + + for _, option := range options { + if err := option.apply(&cfg); err != nil { + tb.Fatalf("NotNearlyEqual: could not apply options: %v", err) + + return + } + } + + delta := math.Abs(float64(got - want)) + if delta <= cfg.floatEqualityThreshold { + cfg.reason = fmt.Sprintf( + "Difference %v - %v = %v is within tolerance of %v", + got, + want, + delta, cfg.floatEqualityThreshold, ) fail := failure[T]{ @@ -248,7 +293,7 @@ func Err(tb testing.TB, err error, options ...Option) { if err == nil { fail := failure[error]{ got: nil, - want: errors.New("error"), + want: errAny, cfg: cfg, } tb.Fatal(fail.String()) @@ -287,7 +332,7 @@ func WantErr(tb testing.TB, err error, want bool, options ...Option) { if want { reason = fmt.Sprintf("Wanted an error but got %v", err) - wanted = errors.New("error") + wanted = errAny } else { reason = fmt.Sprintf("Got an unexpected error: %v", err) wanted = nil @@ -364,9 +409,9 @@ func False(tb testing.TB, got bool, options ...Option) { // // If either got or want do not end in a newline, one is added to avoid a // "No newline at end of file" warning in the diff which is visually distracting. -func Diff(tb testing.TB, got, want string) { +func Diff(tb testing.TB, got, want string, options ...Option) { tb.Helper() - DiffBytes(tb, []byte(got), []byte(want)) + DiffBytes(tb, []byte(got), []byte(want), options...) } // DiffBytes fails if the two []byte got and want are not equal and provides a rich @@ -374,16 +419,31 @@ func Diff(tb testing.TB, got, want string) { // // If either got or want do not end in a newline, one is added to avoid a // "No newline at end of file" warning in the diff which is visually distracting. -func DiffBytes(tb testing.TB, got, want []byte) { +func DiffBytes(tb testing.TB, got, want []byte, options ...Option) { tb.Helper() + cfg := defaultConfig() + cfg.title = "Diff" + + for _, option := range options { + if err := option.apply(&cfg); err != nil { + tb.Fatalf("DiffBytes: could not apply options: %v", err) + + return + } + } + got = fixNL(got) want = fixNL(want) d := diff.New("want", want, "got", got) if !d.Equal() { - tb.Fatalf("\nDiff\n----\n%s\n", render.Render(d)) + s := &strings.Builder{} + cfg.writeHeader(s) + s.Write(render.Render(d)) + cfg.writeFooter(s) + tb.Fatal(s.String()) } } @@ -392,20 +452,20 @@ func DiffBytes(tb testing.TB, got, want []byte) { // // If either got or want do not end in a newline, one is added to avoid // a "No newline at end of file" warning in the diff which is visually distracting. -func DiffReader(tb testing.TB, got, want io.Reader) { +func DiffReader(tb testing.TB, got, want io.Reader, options ...Option) { tb.Helper() gotData, err := io.ReadAll(got) if err != nil { - tb.Fatalf("DiffReader: could not read from got: %v\n", err) + tb.Fatalf("DiffReader: could not read from got: %v", err) } wantData, err := io.ReadAll(want) if err != nil { - tb.Fatalf("DiffReader: could not read from want: %v\n", err) + tb.Fatalf("DiffReader: could not read from want: %v", err) } - DiffBytes(tb, gotData, wantData) + DiffBytes(tb, gotData, wantData, options...) } // CaptureOutput captures and returns data printed to [os.Stdout] and [os.Stderr] by the provided function fn, allowing @@ -415,6 +475,9 @@ func DiffReader(tb testing.TB, got, want io.Reader) { // // If any error occurs capturing stdout or stderr, the test will also be failed with a descriptive log. // +// CaptureOutput replaces the process-wide [os.Stdout] and [os.Stderr] for the duration of the call, +// so it is NOT safe to use from tests marked with [testing.T.Parallel]. +// // fn := func() error { // fmt.Println("hello stdout") // return nil @@ -426,84 +489,88 @@ func DiffReader(tb testing.TB, got, want io.Reader) { func CaptureOutput(tb testing.TB, fn func() error) (stdout, stderr string) { tb.Helper() - // Take copies of the original streams oldStdout := os.Stdout oldStderr := os.Stderr - defer func() { - // Restore everything back to normal - os.Stdout = oldStdout - os.Stderr = oldStderr - }() - stdoutReader, stdoutWriter, err := os.Pipe() if err != nil { tb.Fatalf("CaptureOutput: could not construct an os.Pipe(): %v", err) + + return "", "" } stderrReader, stderrWriter, err := os.Pipe() if err != nil { + stdoutReader.Close() + stdoutWriter.Close() tb.Fatalf("CaptureOutput: could not construct an os.Pipe(): %v", err) + + return "", "" } - // Set stdout and stderr streams to the pipe writers os.Stdout = stdoutWriter os.Stderr = stderrWriter - stdoutCapture := make(chan string) - stderrCapture := make(chan string) - - var wg sync.WaitGroup - - // Copy in goroutines to avoid blocking - wg.Go(func() { - defer func() { - close(stdoutCapture) - }() - - buf := &bytes.Buffer{} - if _, err := io.Copy(buf, stdoutReader); err != nil { - tb.Fatalf("CaptureOutput: failed to copy from stdout reader: %v", err) + // Buffered so the copy goroutines can always deliver their result, even if + // the main goroutine exits early via Fatalf / runtime.Goexit / panic. + stdoutCapture := make(chan string, 1) + stderrCapture := make(chan string, 1) + + // Goroutines use Errorf rather than Fatalf — the testing contract says + // FailNow/Fatal* must only be called from the main test goroutine. + go copyInto(tb, "stdout", stdoutReader, stdoutCapture) + go copyInto(tb, "stderr", stderrReader, stderrCapture) + + // Ensure the real streams are restored and the pipe writers are closed on + // every exit path (including panic / Goexit). Closing the writers lets the + // copy goroutines see EOF and deliver their buffers to the channels. + writersClosed := false + closeWriters := func() { + if writersClosed { + return } - stdoutCapture <- buf.String() - }) + writersClosed = true - wg.Go(func() { - defer func() { - close(stderrCapture) - }() + stdoutWriter.Close() + stderrWriter.Close() + } - buf := &bytes.Buffer{} - if _, err := io.Copy(buf, stderrReader); err != nil { - tb.Fatalf("CaptureOutput: failed to copy from stderr reader: %v", err) - } + defer func() { + closeWriters() - stderrCapture <- buf.String() - }) + os.Stdout = oldStdout + os.Stderr = oldStderr + }() - // Call the test function that produces the output - if err := fn(); err != nil { - tb.Fatalf("CaptureOutput: user function returned an error: %v", err) - } + if fnErr := fn(); fnErr != nil { + tb.Fatalf("CaptureOutput: user function returned an error: %v", fnErr) - // Close the writers - stdoutCloseErr := stdoutWriter.Close() - if stdoutCloseErr != nil { - tb.Fatalf("CaptureOutput: could not close stdout pipe: %v", stdoutCloseErr) + return "", "" } - stderrCloseErr := stderrWriter.Close() - if stderrCloseErr != nil { - tb.Fatalf("CaptureOutput: could not close stderr pipe: %v", stderrCloseErr) - } + // Happy path: close writers now so we can receive the captured data before + // the defer runs (the defer's close is then a no-op). + closeWriters() + + return <-stdoutCapture, <-stderrCapture +} + +// copyInto reads from r into a buffer and sends the result on out. Any copy +// error is reported against tb via Errorf — Fatal* is unsafe from non-main +// goroutines. The send uses a buffered channel so it never blocks. +func copyInto(tb testing.TB, name string, r io.Reader, out chan<- string) { + tb.Helper() - capturedStdout := <-stdoutCapture - capturedStderr := <-stderrCapture + buf := &bytes.Buffer{} - wg.Wait() + defer func() { + out <- buf.String() + }() - return capturedStdout, capturedStderr + if _, err := io.Copy(buf, r); err != nil { + tb.Errorf("CaptureOutput: failed to copy from %s reader: %v", name, err) + } } // If data is empty or ends in \n, fixNL returns data. diff --git a/test_test.go b/test_test.go index bd40b83..cbd4cf2 100644 --- a/test_test.go +++ b/test_test.go @@ -6,6 +6,7 @@ import ( "flag" "fmt" "io" + "math" "os" "slices" "testing" @@ -240,6 +241,34 @@ func TestTest(t *testing.T) { }, wantFail: true, }, + { + name: "NotNearlyEqual/pass", + fn: func(tb testing.TB) { + test.NotNearlyEqual(tb, 3.0000001, 3.0) + }, + wantFail: false, + }, + { + name: "NotNearlyEqual/fail", + fn: func(tb testing.TB) { + test.NotNearlyEqual(tb, 3.0000000001, 3.0) + }, + wantFail: true, + }, + { + name: "NotNearlyEqual/fail custom tolerance", + fn: func(tb testing.TB) { + test.NotNearlyEqual(tb, 3.05, 3.0, test.FloatEqualityThreshold(0.1)) + }, + wantFail: true, + }, + { + name: "NotNearlyEqual/fail with context", + fn: func(tb testing.TB) { + test.NotNearlyEqual(tb, 3.0000000001, 3.0, test.Context("Numbers don't work that way")) + }, + wantFail: true, + }, { name: "Ok/pass", fn: func(tb testing.TB) { @@ -471,6 +500,59 @@ func TestTest(t *testing.T) { }, wantFail: true, }, + { + name: "Diff/fail with title", + fn: func(tb testing.TB) { + got := "Some\nstuff here in this file\nlines as well wow\nsome more stuff\n" + want := "Some\ndifferent stuff here in this file\nthis line is different\nsome more stuff\n" + test.Diff(tb, got, want, test.Title("File drift")) + }, + wantFail: true, + }, + { + name: "Diff/fail with context", + fn: func(tb testing.TB) { + got := "Some\nstuff here in this file\nlines as well wow\nsome more stuff\n" + want := "Some\ndifferent stuff here in this file\nthis line is different\nsome more stuff\n" + test.Diff(tb, got, want, test.Context("config file drifted from checked-in copy")) + }, + wantFail: true, + }, + { + name: "Option errors/Title empty", + fn: func(tb testing.TB) { + test.Equal(tb, 1, 1, test.Title("")) + }, + wantFail: true, + }, + { + name: "Option errors/Context empty", + fn: func(tb testing.TB) { + test.Equal(tb, 1, 1, test.Context("")) + }, + wantFail: true, + }, + { + name: "Option errors/Context format resolves empty", + fn: func(tb testing.TB) { + test.Equal(tb, 1, 1, test.Context("%s", "")) + }, + wantFail: true, + }, + { + name: "Option errors/FloatEqualityThreshold positive infinity", + fn: func(tb testing.TB) { + test.NearlyEqual(tb, 1.0, 1.0, test.FloatEqualityThreshold(math.Inf(1))) + }, + wantFail: true, + }, + { + name: "Option errors/FloatEqualityThreshold negative infinity", + fn: func(tb testing.TB) { + test.NearlyEqual(tb, 1.0, 1.0, test.FloatEqualityThreshold(math.Inf(-1))) + }, + wantFail: true, + }, } for _, tt := range tests { diff --git a/testdata/snapshots/TestTest/Diff/fail.snap b/testdata/snapshots/TestTest/Diff/fail.snap index 9158e73..7f78a77 100644 --- a/testdata/snapshots/TestTest/Diff/fail.snap +++ b/testdata/snapshots/TestTest/Diff/fail.snap @@ -1,10 +1,11 @@ source: test_test.go expression: buf.String() --- -|+ +| Diff ---- + diff want got --- want +++ got @@ -15,4 +16,3 @@ expression: buf.String() - this line is different + lines as well wow some more stuff - diff --git a/testdata/snapshots/TestTest/Diff/fail_no_trailing_newline.snap b/testdata/snapshots/TestTest/Diff/fail_no_trailing_newline.snap index 9158e73..7f78a77 100644 --- a/testdata/snapshots/TestTest/Diff/fail_no_trailing_newline.snap +++ b/testdata/snapshots/TestTest/Diff/fail_no_trailing_newline.snap @@ -1,10 +1,11 @@ source: test_test.go expression: buf.String() --- -|+ +| Diff ---- + diff want got --- want +++ got @@ -15,4 +16,3 @@ expression: buf.String() - this line is different + lines as well wow some more stuff - diff --git a/testdata/snapshots/TestTest/Diff/fail_with_context.snap b/testdata/snapshots/TestTest/Diff/fail_with_context.snap new file mode 100644 index 0000000..cfca7f9 --- /dev/null +++ b/testdata/snapshots/TestTest/Diff/fail_with_context.snap @@ -0,0 +1,20 @@ +source: test_test.go +expression: buf.String() +--- +| + + Diff + ---- + + diff want got + --- want + +++ got + @@ -1,4 +1,4 @@ + Some + - different stuff here in this file + + stuff here in this file + - this line is different + + lines as well wow + some more stuff + + (config file drifted from checked-in copy) diff --git a/testdata/snapshots/TestTest/Diff/fail_with_title.snap b/testdata/snapshots/TestTest/Diff/fail_with_title.snap new file mode 100644 index 0000000..2c8ec29 --- /dev/null +++ b/testdata/snapshots/TestTest/Diff/fail_with_title.snap @@ -0,0 +1,18 @@ +source: test_test.go +expression: buf.String() +--- +| + + File drift + ---------- + + diff want got + --- want + +++ got + @@ -1,4 +1,4 @@ + Some + - different stuff here in this file + + stuff here in this file + - this line is different + + lines as well wow + some more stuff diff --git a/testdata/snapshots/TestTest/DiffBytes/fail.snap b/testdata/snapshots/TestTest/DiffBytes/fail.snap index 9158e73..7f78a77 100644 --- a/testdata/snapshots/TestTest/DiffBytes/fail.snap +++ b/testdata/snapshots/TestTest/DiffBytes/fail.snap @@ -1,10 +1,11 @@ source: test_test.go expression: buf.String() --- -|+ +| Diff ---- + diff want got --- want +++ got @@ -15,4 +16,3 @@ expression: buf.String() - this line is different + lines as well wow some more stuff - diff --git a/testdata/snapshots/TestTest/DiffReader/fail.snap b/testdata/snapshots/TestTest/DiffReader/fail.snap index 9158e73..7f78a77 100644 --- a/testdata/snapshots/TestTest/DiffReader/fail.snap +++ b/testdata/snapshots/TestTest/DiffReader/fail.snap @@ -1,10 +1,11 @@ source: test_test.go expression: buf.String() --- -|+ +| Diff ---- + diff want got --- want +++ got @@ -15,4 +16,3 @@ expression: buf.String() - this line is different + lines as well wow some more stuff - diff --git a/testdata/snapshots/TestTest/Err/fail.snap b/testdata/snapshots/TestTest/Err/fail.snap index b409248..38d6194 100644 --- a/testdata/snapshots/TestTest/Err/fail.snap +++ b/testdata/snapshots/TestTest/Err/fail.snap @@ -7,4 +7,4 @@ expression: buf.String() ------- Got: - Wanted: error + Wanted: diff --git a/testdata/snapshots/TestTest/Err/fail_with_context.snap b/testdata/snapshots/TestTest/Err/fail_with_context.snap index df511ae..526d9f3 100644 --- a/testdata/snapshots/TestTest/Err/fail_with_context.snap +++ b/testdata/snapshots/TestTest/Err/fail_with_context.snap @@ -7,6 +7,6 @@ expression: buf.String() ------- Got: - Wanted: error + Wanted: (Frobnicated the baz when it should have failed) diff --git a/testdata/snapshots/TestTest/Err/fail_with_title.snap b/testdata/snapshots/TestTest/Err/fail_with_title.snap index 8cdb2e2..af5c511 100644 --- a/testdata/snapshots/TestTest/Err/fail_with_title.snap +++ b/testdata/snapshots/TestTest/Err/fail_with_title.snap @@ -7,4 +7,4 @@ expression: buf.String() ------------------- Got: - Wanted: error + Wanted: diff --git a/testdata/snapshots/TestTest/NotNearlyEqual/fail.snap b/testdata/snapshots/TestTest/NotNearlyEqual/fail.snap new file mode 100644 index 0000000..b25cd85 --- /dev/null +++ b/testdata/snapshots/TestTest/NotNearlyEqual/fail.snap @@ -0,0 +1,12 @@ +source: test_test.go +expression: buf.String() +--- +| + + NearlyEqual + ----------- + + Got: 3.0000000001 + Wanted: 3 + + Because: Difference 3.0000000001 - 3 = 1.000000082740371e-10 is within tolerance of 1e-08 diff --git a/testdata/snapshots/TestTest/NotNearlyEqual/fail_custom_tolerance.snap b/testdata/snapshots/TestTest/NotNearlyEqual/fail_custom_tolerance.snap new file mode 100644 index 0000000..67354d0 --- /dev/null +++ b/testdata/snapshots/TestTest/NotNearlyEqual/fail_custom_tolerance.snap @@ -0,0 +1,12 @@ +source: test_test.go +expression: buf.String() +--- +| + + NearlyEqual + ----------- + + Got: 3.05 + Wanted: 3 + + Because: Difference 3.05 - 3 = 0.04999999999999982 is within tolerance of 0.1 diff --git a/testdata/snapshots/TestTest/NotNearlyEqual/fail_with_context.snap b/testdata/snapshots/TestTest/NotNearlyEqual/fail_with_context.snap new file mode 100644 index 0000000..6d62fb2 --- /dev/null +++ b/testdata/snapshots/TestTest/NotNearlyEqual/fail_with_context.snap @@ -0,0 +1,14 @@ +source: test_test.go +expression: buf.String() +--- +| + + NearlyEqual + ----------- + + Got: 3.0000000001 + Wanted: 3 + + (Numbers don't work that way) + + Because: Difference 3.0000000001 - 3 = 1.000000082740371e-10 is within tolerance of 1e-08 diff --git a/testdata/snapshots/TestTest/Option_errors/Context_empty.snap b/testdata/snapshots/TestTest/Option_errors/Context_empty.snap new file mode 100644 index 0000000..0c7b0c4 --- /dev/null +++ b/testdata/snapshots/TestTest/Option_errors/Context_empty.snap @@ -0,0 +1,4 @@ +source: test_test.go +expression: buf.String() +--- +'Equal: could not apply options: cannot set context to an empty string' diff --git a/testdata/snapshots/TestTest/Option_errors/Context_format_resolves_empty.snap b/testdata/snapshots/TestTest/Option_errors/Context_format_resolves_empty.snap new file mode 100644 index 0000000..0c7b0c4 --- /dev/null +++ b/testdata/snapshots/TestTest/Option_errors/Context_format_resolves_empty.snap @@ -0,0 +1,4 @@ +source: test_test.go +expression: buf.String() +--- +'Equal: could not apply options: cannot set context to an empty string' diff --git a/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_negative_infinity.snap b/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_negative_infinity.snap new file mode 100644 index 0000000..1cab5cd --- /dev/null +++ b/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_negative_infinity.snap @@ -0,0 +1,4 @@ +source: test_test.go +expression: buf.String() +--- +'NearlyEqual: could not apply options: cannot set floating point equality threshold to ±infinity' diff --git a/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_positive_infinity.snap b/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_positive_infinity.snap new file mode 100644 index 0000000..1cab5cd --- /dev/null +++ b/testdata/snapshots/TestTest/Option_errors/FloatEqualityThreshold_positive_infinity.snap @@ -0,0 +1,4 @@ +source: test_test.go +expression: buf.String() +--- +'NearlyEqual: could not apply options: cannot set floating point equality threshold to ±infinity' diff --git a/testdata/snapshots/TestTest/Option_errors/Title_empty.snap b/testdata/snapshots/TestTest/Option_errors/Title_empty.snap new file mode 100644 index 0000000..7305a09 --- /dev/null +++ b/testdata/snapshots/TestTest/Option_errors/Title_empty.snap @@ -0,0 +1,4 @@ +source: test_test.go +expression: buf.String() +--- +'Equal: could not apply options: cannot set title to an empty string' diff --git a/testdata/snapshots/TestTest/WantErr/fail_nil.snap b/testdata/snapshots/TestTest/WantErr/fail_nil.snap index 594ae96..5cd6321 100644 --- a/testdata/snapshots/TestTest/WantErr/fail_nil.snap +++ b/testdata/snapshots/TestTest/WantErr/fail_nil.snap @@ -7,6 +7,6 @@ expression: buf.String() ------- Got: - Wanted: error + Wanted: Because: Wanted an error but got