Skip to content

bug: richgo panics on extra output #36

@ashanbrown

Description

@ashanbrown

Summary

The latest version of richgo panics when there is extra data at the beginning of the test output.

To reproduce

Consider this output:

blah blah blah
=== RUN   TestFoo
--- PASS: TestFoo (5.23s)
PASS
ok  	github.com/foo/bar	10.780s

This now results in a panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1118106]

goroutine 18 [running]:
github.com/kyoh86/richgo/config.(*Style).Apply(0x0, 0xc00001e150, 0x15, 0xc000020300, 0xe)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/config/style.go:77 +0x26
github.com/kyoh86/richgo/editor/test.(*test).Edit.func13(0xc000020300, 0xe, 0x2, 0x2)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/editor/test/test.go:217 +0x149
regexp.(*Regexp).ReplaceAllStringFunc.func1(0x0, 0x0, 0x0, 0xc000020310, 0x2, 0x2, 0xc000020300, 0xf, 0x0)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/regexp/regexp.go:596 +0x93
regexp.(*Regexp).replaceAll(0xc00012dc20, 0x0, 0x0, 0x0, 0xc000020300, 0xf, 0x2, 0xc000079ae8, 0x1139e00, 0xf, ...)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/regexp/regexp.go:634 +0x303
regexp.(*Regexp).ReplaceAllStringFunc(0xc00012dc20, 0xc000020300, 0xf, 0xc00005e210, 0x100d9d8, 0x10)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/regexp/regexp.go:595 +0x9d
github.com/kyoh86/richgo/editor.Replaces(0xc000020300, 0xf, 0xc000079bc8, 0x1, 0x1, 0xc000020300, 0xf)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/editor/regexp_flow.go:18 +0x8f
github.com/kyoh86/richgo/editor/test.(*test).Edit(0xc00011c7a0, 0xc0000200a0, 0xf, 0xc0000200a0, 0xf, 0xc00001a0e0, 0xe)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/editor/test/test.go:210 +0x645
github.com/kyoh86/richgo/editor.(*stream).writeLines(0xc000118880, 0xc000288000, 0x5, 0x6, 0x1, 0x1)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/editor/editor.go:29 +0x98
github.com/kyoh86/richgo/editor.(*stream).Write(0xc000118880, 0xc000200000, 0x60, 0x8000, 0x60, 0x0, 0x0)
	/Users/andrewbrown/code/go/pkg/mod/github.com/kyoh86/richgo@v0.3.7/editor/editor.go:46 +0x145
io.copyBuffer(0x17a0a58, 0xc000118880, 0x1183d88, 0xc0001120c0, 0xc000200000, 0x8000, 0x8000, 0x0, 0x0, 0x0)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/io/io.go:425 +0x21c
io.Copy(...)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/io/io.go:382
os/exec.(*Cmd).writerDescriptor.func1(0x0, 0x0)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/os/exec/exec.go:311 +0x65
os/exec.(*Cmd).Start.func1(0xc00017c000, 0xc00011c7c0)
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/os/exec/exec.go:441 +0x27
created by os/exec.(*Cmd).Start
	/Users/andrewbrown/.gvm/gos/go1.16.4/src/os/exec/exec.go:440 +0x630

Expected behavior

Previously we'd get:

     | blah blah blah
START| Foo
PASS | Foo (5.23s)
PASS
PASS | github.com/foo/bar

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions