github.com/jingweno/gh@v2.1.1-0.20221007190738-04a7985fa9a1+incompatible/github/crash_report_test.go (about) 1 package github 2 3 import ( 4 "github.com/bmizerany/assert" 5 "github.com/jingweno/gh/git" 6 "testing" 7 ) 8 9 func TestStackRemoveSelfAndPanic(t *testing.T) { 10 actual := `goroutine 1 [running]: 11 runtime.panic(0x2bca00, 0x665b8a) 12 /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6 13 github.com/jingweno/gh/github.ReportCrash(0xc2000b5000, 0xc2000b49c0) 14 /Users/calavera/github/go/src/github.com/jingweno/gh/github/crash_report.go:16 +0x97 15 github.com/jingweno/gh/commands.create(0x47f8a0, 0xc2000cf770) 16 /Users/calavera/github/go/src/github.com/jingweno/gh/commands/create.go:54 +0x63 17 github.com/jingweno/gh/commands.(*Runner).Execute(0xc200094640, 0xc200094640, 0x21, 0xc2000b0a40) 18 /Users/calavera/github/go/src/github.com/jingweno/gh/commands/runner.go:72 +0x3b7 19 main.main() 20 /Users/calavera/github/go/src/github.com/jingweno/gh/main.go:10 +0xad` 21 22 expected := `goroutine 1 [running]: 23 github.com/jingweno/gh/commands.create(0x47f8a0, 0xc2000cf770) 24 /Users/calavera/github/go/src/github.com/jingweno/gh/commands/create.go:54 +0x63 25 github.com/jingweno/gh/commands.(*Runner).Execute(0xc200094640, 0xc200094640, 0x21, 0xc2000b0a40) 26 /Users/calavera/github/go/src/github.com/jingweno/gh/commands/runner.go:72 +0x3b7 27 main.main() 28 /Users/calavera/github/go/src/github.com/jingweno/gh/main.go:10 +0xad` 29 30 s := formatStack([]byte(actual)) 31 assert.Equal(t, expected, s) 32 } 33 34 func TestSaveAlwaysReportOption(t *testing.T) { 35 checkSavedReportCrashOption(t, true, "a", "always") 36 checkSavedReportCrashOption(t, true, "always", "always") 37 } 38 39 func TestSaveNeverReportOption(t *testing.T) { 40 checkSavedReportCrashOption(t, false, "e", "never") 41 checkSavedReportCrashOption(t, false, "never", "never") 42 } 43 44 func TestDoesntSaveYesReportOption(t *testing.T) { 45 checkSavedReportCrashOption(t, false, "y", "") 46 checkSavedReportCrashOption(t, false, "yes", "") 47 } 48 49 func TestDoesntSaveNoReportOption(t *testing.T) { 50 checkSavedReportCrashOption(t, false, "n", "") 51 checkSavedReportCrashOption(t, false, "no", "") 52 } 53 54 func checkSavedReportCrashOption(t *testing.T, always bool, confirm, expected string) { 55 defer git.UnsetGlobalConfig(ghReportCrashConfig) 56 57 saveReportConfiguration(confirm, always) 58 assert.Equal(t, expected, reportCrashConfig()) 59 }