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) } }