gkampitakis / go-snaps

Jest-like snapshot testing in Golang πŸ“Έ
https://pkg.go.dev/github.com/gkampitakis/go-snaps
MIT License
146 stars 6 forks source link

fix: replace `Print` with `Println` #94

Closed G-Rath closed 5 months ago

G-Rath commented 5 months ago

This is a weird one I'm still digging into but since adding go-snaps we're getting newlines in our test output:

osv-detector on ξ‚  use-go-snaps [!?] via 🐹 v1.21.5 via  v20.11.0 took 3s
❯ make test
go test ./...
?       github.com/g-rath/osv-detector/internal [no test files]
?       github.com/g-rath/osv-detector/internal/cachedregexp    [no test files]

ok      github.com/g-rath/osv-detector  3.341s
ok      github.com/g-rath/osv-detector/internal/configer        (cached)
ok      github.com/g-rath/osv-detector/internal/reporter        (cached)
ok      github.com/g-rath/osv-detector/pkg/database     (cached)
ok      github.com/g-rath/osv-detector/pkg/lockfile     (cached)
ok      github.com/g-rath/osv-detector/pkg/semantic     (cached)

I've traced this down to the use of snaps.Clean and specifically this fmt.Print call - weirdly, if I replace it with this change the newline goes away but not if I do e.g. fmt.Printf(s):

osv-detector on ξ‚  use-go-snaps [!?] via 🐹 v1.21.5 via  v20.11.0 took 3s
❯ make test
go test ./...
?       github.com/g-rath/osv-detector/internal [no test files]
?       github.com/g-rath/osv-detector/internal/cachedregexp    [no test files]
ok      github.com/g-rath/osv-detector  3.172s
ok      github.com/g-rath/osv-detector/internal/configer        (cached)
ok      github.com/g-rath/osv-detector/internal/reporter        (cached)
ok      github.com/g-rath/osv-detector/pkg/database     (cached)
ok      github.com/g-rath/osv-detector/pkg/lockfile     (cached)
ok      github.com/g-rath/osv-detector/pkg/semantic     (cached)

I think this actually might be a bug in Go, but I'm not brave enough to try taking that on πŸ˜…

gkampitakis commented 5 months ago

Hey πŸ‘‹ Hm that's definitely weird. So why to we need the \n in Printf function? Will have a closer look just for my understanding but it looks good to me and tests are passing.