package ghostty import ( "os" "path/filepath" "slices" "strings" "testing" ) // TestLiveGhostty runs every command ghosttyconf uses against the installed // Ghostty and checks that the output is still understood. It is meant for a // new Ghostty release and only runs when asked for: // // GHOSTTYCONF_LIVE_TEST=1 go test -run Live -v ./internal/ghostty func TestLiveGhostty(t *testing.T) { if os.Getenv("GHOSTTYCONF_LIVE_TEST") == "" { t.Skip("set GHOSTTYCONF_LIVE_TEST=1 to run against the installed Ghostty") } g, err := Find(os.Getenv("GHOSTTYCONF_GHOSTTY")) if err != nil { t.Fatal(err) } if g.Version == "" { t.Fatal("+version: no version found") } t.Logf("Ghostty %s at %s", g.Version, g.Bin) docs, err := g.DefaultsWithDocs() if err != nil { t.Fatal(err) } for _, want := range []string{"\nfont-family = ", "\nkeybind = ", "\n# "} { if !strings.Contains(docs, want) { t.Errorf("+show-config --default --docs: no %q", want) } } themes, err := g.Themes() if err != nil { t.Fatal(err) } if len(themes) < 100 || !slices.Contains(themes, "Catppuccin Mocha") { t.Errorf("+list-themes: %d themes, Catppuccin Mocha missing or too few", len(themes)) } for _, name := range themes { if strings.HasSuffix(name, " (resources)") || strings.HasSuffix(name, " (user)") { t.Errorf("+list-themes: location left on %q", name) break } } th, err := g.LoadTheme("Catppuccin Mocha") if err != nil { t.Fatalf("theme file: %v", err) } if th.Background == "" || th.Palette[15] == "" { t.Errorf("theme file: %+v", th) } fonts, err := g.Fonts() if err != nil || len(fonts) == 0 { t.Errorf("+list-fonts: %d fonts, %v", len(fonts), err) } actions, err := g.Actions() if err != nil { t.Fatal(err) } byName := map[string]Action{} for _, a := range actions { byName[a.Name] = a } if a := byName["new_split"]; len(actions) < 50 || a.Summary == "" || !strings.Contains(a.Doc, "right") { t.Errorf("+list-actions --docs: %d actions, new_split = %+v", len(actions), a) } conf := filepath.Join(t.TempDir(), "config") if err := os.WriteFile(conf, []byte("font-size = 14\nfont-size = abc\nbogus-key = 1\n"), 0o644); err != nil { t.Fatal(err) } errs, err := g.Validate(conf) if err != nil { t.Fatal(err) } if len(errs) != 2 || errs[0].Line != 2 || errs[1].Line != 3 { t.Errorf("+validate-config: %v", errs) } }