Skip to content

Commit 9f0e414

Browse files
committed
tests: improve snapshot failure diff output
Prior to this commit, viewing the diffs on snapshot tests when they fail was a little rough. Very basic and no nice formatting or coloring. I've implemented a diff library (since none of the existing ones in Go seemed to do what I wanted, the way I wanted it) https://github.com/amterp/go-delta and in this commit, we pull this in and leverage it for nicer snapshot test failure output.
1 parent 162eb5a commit 9f0e414

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

core/testing/diagnostic_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,3 @@ func TestNewDiagnosticFromCheckNilCode(t *testing.T) {
224224
coreDiag := core.NewDiagnosticFromCheck(checkDiag, "test.rad")
225225
assert.Equal(t, rl.ErrGenericRuntime, coreDiag.Code)
226226
}
227-

core/testing/snapshot.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strconv"
99
"strings"
1010
"testing"
11+
12+
gd "github.com/amterp/go-delta"
1113
)
1214

1315
// UpdateSnapshots is set by the -update flag to regenerate expected outputs
@@ -380,15 +382,15 @@ func CompareSnapshotResult(t *testing.T, tc *SnapshotCase, actual SnapshotResult
380382
if actual.Stdout != tc.Stdout {
381383
needsUpdate = true
382384
if !*UpdateSnapshots {
383-
t.Errorf("Stdout mismatch\nExpected:\n%q\nActual:\n%q", tc.Stdout, actual.Stdout)
385+
t.Errorf("Stdout mismatch:\n%s", gd.DiffWith(tc.Stdout, actual.Stdout, gd.WithColor(true), gd.WithLayout(gd.LayoutPreferSideBySide), gd.WithWidth(120)))
384386
}
385387
}
386388

387389
// Compare stderr
388390
if actual.Stderr != tc.Stderr {
389391
needsUpdate = true
390392
if !*UpdateSnapshots {
391-
t.Errorf("Stderr mismatch\nExpected:\n%q\nActual:\n%q", tc.Stderr, actual.Stderr)
393+
t.Errorf("Stderr mismatch:\n%s", gd.DiffWith(tc.Stderr, actual.Stderr, gd.WithColor(true), gd.WithLayout(gd.LayoutPreferSideBySide), gd.WithWidth(120)))
392394
}
393395
}
394396

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module github.com/amterp/rad
22

3-
go 1.24.2
3+
go 1.25.6
44

55
require (
66
github.com/BurntSushi/toml v1.5.0
77
github.com/amterp/color v1.20.1
88
github.com/amterp/flexid v1.3.0
9+
github.com/amterp/go-delta v0.1.5
910
github.com/amterp/go-tbl v0.12.0
1011
github.com/amterp/jsoncolor v0.4.0
1112
github.com/amterp/ra v0.4.3
@@ -20,7 +21,7 @@ require (
2021
github.com/stretchr/testify v1.11.1
2122
github.com/tree-sitter/go-tree-sitter v0.25.0
2223
go.uber.org/zap v1.27.0
23-
golang.org/x/term v0.37.0
24+
golang.org/x/term v0.39.0
2425
)
2526

2627
require (
@@ -35,13 +36,15 @@ require (
3536
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
3637
github.com/charmbracelet/x/exp/strings v0.0.0-20250904123553-b4e2667e5ad5 // indirect
3738
github.com/charmbracelet/x/term v0.2.1 // indirect
39+
github.com/clipperhouse/stringish v0.1.1 // indirect
40+
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
3841
github.com/davecgh/go-spew v1.1.1 // indirect
3942
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
4043
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4144
github.com/mattn/go-colorable v0.1.14 // indirect
4245
github.com/mattn/go-localereader v0.0.1 // indirect
4346
github.com/mattn/go-pointer v0.0.1 // indirect
44-
github.com/mattn/go-runewidth v0.0.16 // indirect
47+
github.com/mattn/go-runewidth v0.0.19 // indirect
4548
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
4649
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
4750
github.com/muesli/cancelreader v0.2.2 // indirect
@@ -50,7 +53,7 @@ require (
5053
github.com/rivo/uniseg v0.4.7 // indirect
5154
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
5255
go.uber.org/multierr v1.11.0 // indirect
53-
golang.org/x/sys v0.38.0 // indirect
56+
golang.org/x/sys v0.40.0 // indirect
5457
golang.org/x/text v0.33.0 // indirect
5558
gopkg.in/yaml.v3 v3.0.1 // indirect
5659
)

go.sum

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/amterp/color v1.20.1 h1:YDjwZ0X6IfK0OuZl8P2KLkV0WuH2pvttrEwr+ZbRbYU=
66
github.com/amterp/color v1.20.1/go.mod h1:XRJ2OonPd9eRKRg6ddVJc6Yv/rvjzMhn+qdIDHKjE04=
77
github.com/amterp/flexid v1.3.0 h1:J3TpTgH3M70JX5bBvsgJ9DHtRcqK6ssQtGreRDd1vgk=
88
github.com/amterp/flexid v1.3.0/go.mod h1:hT0latK+160p/DMRO062K4bLc9ruA3w4P5oASSZ1kME=
9+
github.com/amterp/go-delta v0.1.5 h1:7KcmHhn92aBAj6xtcZvClWdAR/UmChVUnAwaL6M80cc=
10+
github.com/amterp/go-delta v0.1.5/go.mod h1:kvMjMJP/v/KI2qromcrkdoOM+kfNnV2TkUWmiRgASds=
911
github.com/amterp/go-tbl v0.12.0 h1:on3p/pZmfxMObGiauDaf3pwg/gfKbyW6qXiluH/MOuk=
1012
github.com/amterp/go-tbl v0.12.0/go.mod h1:o6DcTIAfB1EvEy5iiwoXbOrKer7/Y2bV9743Q3CJCPI=
1113
github.com/amterp/jsoncolor v0.4.0 h1:X8QegRunhKC0HZ4PBQbUsSa5mfMqMIai9a3ipQbi+uc=
@@ -50,6 +52,10 @@ github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8
5052
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
5153
github.com/charmbracelet/x/xpty v0.1.2 h1:Pqmu4TEJ8KeA9uSkISKMU3f+C1F6OGBn8ABuGlqCbtI=
5254
github.com/charmbracelet/x/xpty v0.1.2/go.mod h1:XK2Z0id5rtLWcpeNiMYBccNNBrP2IJnzHI0Lq13Xzq4=
55+
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
56+
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
57+
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
58+
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
5359
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
5460
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
5561
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -73,8 +79,8 @@ github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2J
7379
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
7480
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
7581
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
76-
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
77-
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
82+
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
83+
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
7884
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
7985
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
8086
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
@@ -86,7 +92,6 @@ github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3
8692
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8793
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8894
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
89-
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
9095
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
9196
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
9297
github.com/samber/lo v1.51.0 h1:kysRYLbHy/MB7kQZf5DSN50JHmMsNEdeY24VzJFu7wI=
@@ -136,10 +141,10 @@ golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM
136141
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
137142
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
138143
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
139-
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
140-
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
141-
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
142-
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
144+
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
145+
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
146+
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
147+
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
143148
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
144149
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
145150
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

0 commit comments

Comments
 (0)