kr / diff Goto Github PK
View Code? Open in Web Editor NEWPrint differences between two Go values.
Home Page: https://kr.dev/diff
License: MIT License
Print differences between two Go values.
Home Page: https://kr.dev/diff
License: MIT License
These tests fail due to stack overflows:
func TestSOs(t *testing.T) {
t.Run("T to []T", func(t *testing.T) {
diff.Test(t, t.Errorf, "a", "b", diff.Transform(func(s string) any {
return []string{s}
}))
})
t.Run("T to struct{V T}", func(t *testing.T) {
diff.Test(t, t.Errorf, "a", "b", diff.Transform(func(s string) any {
return struct{ S string }{s}
}))
})
}
Go Version
go version go1.18.2 darwin/arm64
Current kr.dev/diff commit 6c69dcc
I'm using diff.Test with a map[string]someStruct
and seeing this panic:
diff % go test
--- FAIL: TestBug (0.00s)
panic: reflect.Value.UnsafeAddr of unaddressable value [recovered]
panic: reflect.Value.UnsafeAddr of unaddressable value
goroutine 321 [running]:
testing.tRunner.func1.2({0x10119ed80, 0x1011ea1d0})
/usr/local/go/src/testing/testing.go:1389 +0x1c8
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1392 +0x384
panic({0x10119ed80, 0x1011ea1d0})
/usr/local/go/src/runtime/panic.go:838 +0x204
reflect.Value.UnsafeAddr(...)
/usr/local/go/src/reflect/value.go:2528
kr.dev/diff.access({0x10119e380?, 0x1400029fbc0?, 0x1400029fbc0?})
/Users/bmizerany/src/diff/diff.go:494 +0x90
kr.dev/diff.(*differ).walk(0x1400029d580, {0x1011ecd20, 0x140002e24e0}, {0x1011b7f60?, 0x1400029fbc0?, 0x1400029fbc8?}, {0x1011b7f60?, 0x1400029fbc8?, 0x14000050b68?}, 0x1, ...)
/Users/bmizerany/src/diff/diff.go:330 +0x239c
kr.dev/diff.(*differ).walk(0x1400029d580, {0x1011ecd20, 0x140002e2340}, {0x1011adc40?, 0x14000010bd8?, 0x1011ba660?}, {0x1011adc40?, 0x14000010be0?, 0x14000043e78?}, 0x1, ...)
/Users/bmizerany/src/diff/diff.go:360 +0x2110
kr.dev/diff.(*differ).each(0x1400029d580, {0x1011adc40, 0x140002e40c0}, {0x1011adc40?, 0x140002e40f0})
/Users/bmizerany/src/diff/diff.go:242 +0x27c
kr.dev/diff.Test({0x1011eb408, 0x140002dc680}, 0x101131ee0?, {0x1011adc40, 0x140002e40c0}, {0x1011adc40, 0x140002e40f0}, {0x0, 0x0, 0x0})
/Users/bmizerany/src/diff/diff.go:75 +0x138
kr.dev/diff_test.TestBug(0x140002dc680)
/Users/bmizerany/src/diff/diff_test.go:388 +0xe4
testing.tRunner(0x140002dc680, 0x1011e94d0)
/usr/local/go/src/testing/testing.go:1439 +0x110
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1486 +0x300
exit status 2
FAIL kr.dev/diff 0.160s
A minimal test to reproduce:
func TestBug(t *testing.T) {
type T struct {
F int
}
got := map[string]T{
"k": {},
}
want := map[string]T{
"k": {},
}
diff.Test(t, t.Errorf, got, want)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.