func handlePanics() { panic_printer.UI = terminal.NewUI(os.Stdin) commandArgs := strings.Join(os.Args, " ") stackTrace := generateBacktrace() err := recover() panic_printer.DisplayCrashDialog(err, commandArgs, stackTrace) if err != nil { os.Exit(1) } }
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Panic Printer", func() { var ui *testterm.FakeUI BeforeEach(func() { panic_printer.UI = &testterm.FakeUI{} ui = panic_printer.UI.(*testterm.FakeUI) }) Describe("DisplayCrashDialog", func() { It("includes the error message when given an error", func() { panic_printer.DisplayCrashDialog(errors.New("some-error"), "some command", "some trace") Expect(len(ui.Outputs)).To(BeNumerically(">", 0)) Expect(ui.Outputs).To(ContainElement(ContainSubstring("some-error"))) }) It("includes the string when given a string that is not terminal.QuietPanic", func() { panic_printer.DisplayCrashDialog("some-error", "some command", "some trace") Expect(len(ui.Outputs)).To(BeNumerically(">", 0)) Expect(ui.Outputs).To(ContainElement(ContainSubstring("some-error"))) }) It("does not print anything when given a string that is terminal.QuietPanic", func() { err := terminal.QuietPanic panic_printer.DisplayCrashDialog(err, "some command", "some trace") Expect(len(ui.Outputs)).To(Equal(0)) })