This commit is contained in:
parent
09fceca2f9
commit
40e5379eb3
11 changed files with 250 additions and 2 deletions
25
cmds/golines/recovery_test.go
Normal file
25
cmds/golines/recovery_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFormatterPanicRecovery(t *testing.T) {
|
||||
// go/format accepts fragments, but dst v0.27.3 panics when golines
|
||||
// attempts to decorate this function without a package declaration.
|
||||
source := `func example() {
|
||||
println("first argument", "second argument", "third argument", "fourth argument")
|
||||
}`
|
||||
output, err := formatSource(source, 40)
|
||||
if err == nil || !strings.Contains(err.Error(), "internal panic") {
|
||||
t.Fatalf("expected recovered dependency panic, got output %q, error %v", output, err)
|
||||
}
|
||||
if output != nil {
|
||||
t.Fatalf("unexpected output after panic: %q", output)
|
||||
}
|
||||
output, err = formatSource("package main\n"+source, 40)
|
||||
if err != nil || !strings.Contains(string(output), "func example()") {
|
||||
t.Fatalf("formatting after panic failed: output %q, error %v", output, err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue