1package shell
 2
 3import (
 4	"testing"
 5	"time"
 6
 7	"github.com/stretchr/testify/require"
 8)
 9
10func TestShellPerformanceComparison(t *testing.T) {
11	shell := NewShell(&Options{WorkingDir: t.TempDir()})
12
13	// Test quick command
14	start := time.Now()
15	stdout, stderr, err := shell.Exec(t.Context(), "echo 'hello'")
16	exitCode := ExitCode(err)
17	duration := time.Since(start)
18
19	require.NoError(t, err)
20	require.Equal(t, 0, exitCode)
21	require.Contains(t, stdout, "hello")
22	require.Empty(t, stderr)
23
24	t.Logf("Quick command took: %v", duration)
25}
26
27// Benchmark CPU usage during polling
28func BenchmarkShellPolling(b *testing.B) {
29	shell := NewShell(&Options{WorkingDir: b.TempDir()})
30
31	b.ReportAllocs()
32
33	for b.Loop() {
34		// Use a short sleep to measure polling overhead
35		_, _, err := shell.Exec(b.Context(), "sleep 0.02")
36		exitCode := ExitCode(err)
37		if err != nil || exitCode != 0 {
38			b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
39		}
40	}
41}