cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / e2e / crash_test.go
crash_test.go 2.4K
1package e2e23import (4 "os"5 "path/filepath"6 "strings"7 "testing"89 ghostty "go.mitchellh.com/libghostty"10)1112// A panic stops 012 with the terminal restored (the primary screen, the13// cursor shown), the unsaved work kept, and a report written, their14// paths printed. Opening the file again offers the work back. The15// binary is built with -tags crashtest, where F12 panics where16// O12_CRASH_TEST says (internal/ui/crashtest.go).17func TestPanicKeepsWork(t *testing.T) {18 t.Parallel()19 for _, where := range []string{"update", "command", "view"} {20 t.Run(where, func(t *testing.T) {21 dir := t.TempDir()22 o := options{dir: dir, env: []string{"O12_CRASH_TEST=" + where}}23 s := startWith(t, o, "budget.012")24 s.keys("kept", "<enter>")25 s.waitFor("kept")26 s.keys("<f12>")27 s.waitExit()28 if scr := s.activeScreen(); scr != ghostty.ScreenPrimary {29 t.Errorf("active screen after the crash = %v, want primary", scr)30 }31 s.mu.Lock()32 visible, _ := s.vt.CursorVisible()33 s.mu.Unlock()34 if !visible {35 t.Error("the cursor is hidden after the crash")36 }37 // The lines wrap at the terminal's width, dropping the space a38 // line ends on, so compare without whitespace.39 flat := func(s string) string { return strings.Join(strings.Fields(s), "") }40 text := flat(s.screen())41 recovery, _ := filepath.Glob(filepath.Join(dir, ".config", "012", "recovery", "*budget-*.012"))42 reports, _ := filepath.Glob(filepath.Join(dir, ".config", "012", "crashes", "crash-*.txt"))43 if len(recovery) != 1 || len(reports) != 1 {44 t.Fatalf("recovery files %v, reports %v; screen:\n%s", recovery, reports, s.screen())45 }46 for _, want := range []string{"012: stopped on an internal error (a panic in " + strings.Replace(where, "command", "a command", 1), "unsaved changes kept in " + recovery[0] + "; open budget.012 again to restore them",47 "a report is in " + reports[0]} {48 if !strings.Contains(text, flat(want)) {49 t.Errorf("the screen lacks %q:\n%s", want, s.screen())50 }51 }52 report, _ := os.ReadFile(reports[0])53 if !strings.Contains(string(report), "Panic: crash test in ") {54 t.Errorf("report:\n%s", report)55 }5657 r := startWith(t, options{dir: dir, startsOn: "Unsaved changes to budget.012 were kept."}, "budget.012")58 r.keys("<enter>")59 r.waitFor("Restored the kept changes")60 if !strings.Contains(r.line(gridRow1), "kept") {61 t.Errorf("A1 after restoring: %q", r.line(gridRow1))62 }63 })64 }65}