12// Benchmark to measure CPU efficiency
13func BenchmarkShellQuickCommands(b *testing.B) {
14 shell := NewShell(&Options{WorkingDir: b.TempDir()})
19 _, _, err := shell.Exec(context.Background(), "echo test")
20 exitCode := ExitCode(err)
21 if err != nil || exitCode != 0 {
22 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
27func TestTestTimeout(t *testing.T) {
28 // XXX(@andreynering): This fails on Windows. Address once possible.
29 if runtime.GOOS == "windows" {
30 t.Skip("Skipping test on Windows")
33 ctx, cancel := context.WithTimeout(t.Context(), time.Millisecond)
36 shell := NewShell(&Options{WorkingDir: t.TempDir()})
37 _, _, err := shell.Exec(ctx, "sleep 10")
38 if status := ExitCode(err); status == 0 {
39 t.Fatalf("Expected non-zero exit status, got %d", status)
41 if !IsInterrupt(err) {
42 t.Fatalf("Expected command to be interrupted, but it was not")
45 t.Fatalf("Expected an error due to timeout, but got none")
49func TestTestCancel(t *testing.T) {
50 ctx, cancel := context.WithCancel(t.Context())
51 cancel() // immediately cancel the context
53 shell := NewShell(&Options{WorkingDir: t.TempDir()})
54 _, _, err := shell.Exec(ctx, "sleep 10")
55 if status := ExitCode(err); status == 0 {
56 t.Fatalf("Expected non-zero exit status, got %d", status)
58 if !IsInterrupt(err) {
59 t.Fatalf("Expected command to be interrupted, but it was not")
62 t.Fatalf("Expected an error due to cancel, but got none")
66func TestRunCommandError(t *testing.T) {
67 shell := NewShell(&Options{WorkingDir: t.TempDir()})
68 _, _, err := shell.Exec(t.Context(), "nopenopenope")
69 if status := ExitCode(err); status == 0 {
70 t.Fatalf("Expected non-zero exit status, got %d", status)
73 t.Fatalf("Expected command to not be interrupted, but it was")
76 t.Fatalf("Expected an error, got nil")
80func TestRunContinuity(t *testing.T) {
81 tempDir1 := t.TempDir()
82 tempDir2 := t.TempDir()
84 shell := NewShell(&Options{WorkingDir: tempDir1})
85 if _, _, err := shell.Exec(t.Context(), "export FOO=bar"); err != nil {
86 t.Fatalf("failed to set env: %v", err)
88 if _, _, err := shell.Exec(t.Context(), "cd "+filepath.ToSlash(tempDir2)); err != nil {
89 t.Fatalf("failed to change directory: %v", err)
91 out, _, err := shell.Exec(t.Context(), "echo $FOO ; pwd")
93 t.Fatalf("failed to echo: %v", err)
95 expect := "bar\n" + tempDir2 + "\n"
97 t.Fatalf("expected output %q, got %q", expect, out)
101func TestCrossPlatformExecution(t *testing.T) {
102 shell := NewShell(&Options{WorkingDir: "."})
103 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
106 // Test a simple command that should work on all platforms
107 stdout, stderr, err := shell.Exec(ctx, "echo hello")
109 t.Fatalf("Echo command failed: %v, stderr: %s", err, stderr)
113 t.Error("Echo command produced no output")
116 // The output should contain "hello" regardless of platform
117 if !strings.Contains(strings.ToLower(stdout), "hello") {
118 t.Errorf("Echo output should contain 'hello', got: %q", stdout)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list