mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2026-08-24 10:14:12 -05:00
Add a separate e2e Go module that validates the shell integrations against real shells instead of only asserting generated script text: - layer 1: generate the init script per shell and feature-config overlay (base, transient, rprompt, tooltips, full) and validate it with the shell's own parser - layer 2: boot each shell interactively in a pty (ConPTY on Windows, creack/pty elsewhere) with a vt10x screen emulator, assert the prompt renders and the session exits cleanly - layer 3: feature scenarios asserting exit-code propagation, transient prompt replacement, and rprompt right-alignment Covers bash, zsh, fish, pwsh, and nu; tests skip cleanly when a shell binary is absent or the platform cannot drive it faithfully. The harness answers PSReadLine's DSR cursor queries on Unix ptys and isolates sessions from the host's cache and nu vendor autoloads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Entire-Checkpoint: 8a75c4edb40b
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package harness
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// scriptExtensions maps an omp shell name to the file extension its init script should
|
|
// be written with, so shell parsers that dispatch on extension behave correctly.
|
|
var scriptExtensions = map[string]string{
|
|
"bash": ".sh",
|
|
"zsh": ".zsh",
|
|
"fish": ".fish",
|
|
"pwsh": ".ps1",
|
|
"nu": ".nu",
|
|
}
|
|
|
|
// InitScript runs `<omp> init <shellName> --config <cfgPath> --print` with OMP_CACHE_DIR
|
|
// pointed at a fresh t.TempDir(), and returns the printed init script text.
|
|
func InitScript(t *testing.T, shellName, cfgPath string) string {
|
|
t.Helper()
|
|
|
|
bin := Binary(t)
|
|
|
|
cmd := exec.Command(bin, "init", shellName, "--config", cfgPath, "--print")
|
|
cmd.Env = append(os.Environ(), "OMP_CACHE_DIR="+t.TempDir())
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("omp init %s --config %s --print failed: %v\n%s", shellName, cfgPath, err, output)
|
|
}
|
|
|
|
return string(output)
|
|
}
|
|
|
|
// WriteScript writes script to a temp file named with the extension appropriate for
|
|
// shellName (e.g. ".sh" for bash, ".ps1" for pwsh) and returns the absolute path.
|
|
func WriteScript(t *testing.T, shellName, script string) string {
|
|
t.Helper()
|
|
|
|
ext, ok := scriptExtensions[shellName]
|
|
if !ok {
|
|
t.Fatalf("no script extension known for shell %q", shellName)
|
|
}
|
|
|
|
path := filepath.Join(t.TempDir(), "init"+ext)
|
|
if err := os.WriteFile(path, []byte(script), 0o644); err != nil {
|
|
t.Fatalf("writing init script: %v", err)
|
|
}
|
|
|
|
return path
|
|
}
|