package main

import (
	"runtime"
	"testing"
)

func TestIsInstalled_Unit(t *testing.T) {
	t.Parallel()
	t.Log("✓ Fast isInstalled unit test")

	tests := []struct {
		name string
		cmd  string
		want bool
	}{
		{"sh exists", "sh", true},
		{"non-existent", "nonexistentcmd123456789", false},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := isInstalled(tt.cmd)
			if got != tt.want {
				t.Errorf("isInstalled(%q) = %v, want %v", tt.cmd, got, tt.want)
			}
		})
	}
}

func TestIsInstalled_Live(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping live integration test (use without -short)")
	}
	t.Log("🧪 Running live isInstalled integration test...")

	if runtime.GOOS == "windows" {
		t.Skip("isInstalled uses /bin/sh (Unix-only)")
	}

	if !isInstalled("sh") {
		t.Error("sh should be installed on this system")
	}
	t.Log("✓ Live isInstalled test passed")
}

func TestSubExecute_Unit(t *testing.T) {
	t.Parallel()
	t.Log("✓ Fast subExecute unit test")

	_, err := subExecute("nonexistentcmd123456789")
	if err == nil {
		t.Error("expected error for non-existent command")
	}
}

func TestSubExecute_Live(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping live integration test (use without -short)")
	}
	t.Log("🧪 Running live subExecute integration test...")

	output, err := subExecute("echo", "hello from live test")
	if err != nil {
		t.Fatalf("subExecute failed: %v", err)
	}
	if len(output) == 0 {
		t.Error("expected output")
	}
	t.Log("✓ subExecute live test passed")
}
