// Test script for process command execution functionality print("=== Process Command Execution Tests ==="); // Test 1: Basic command execution print("\n--- Test 1: Basic Command Execution ---"); let result = run_command("echo hello world"); assert_true(result.success, "Command should succeed"); assert_true(result.code == 0, "Exit code should be 0"); assert_true(result.stdout.contains("hello world"), "Output should contain 'hello world'"); print("✓ Basic command execution works"); // Test 2: Silent command execution print("\n--- Test 2: Silent Command Execution ---"); let silent_result = run_silent("echo silent test"); assert_true(silent_result.success, "Silent command should succeed"); assert_true(silent_result.stdout.contains("silent test"), "Silent output should be captured"); print("✓ Silent command execution works"); // Test 3: Builder pattern print("\n--- Test 3: Builder Pattern ---"); let builder_result = run("echo builder pattern").silent().execute(); assert_true(builder_result.success, "Builder command should succeed"); assert_true(builder_result.stdout.contains("builder pattern"), "Builder output should be captured"); print("✓ Builder pattern works"); // Test 4: Error handling with die=false print("\n--- Test 4: Error Handling (ignore_error) ---"); let error_result = run("false").ignore_error().silent().execute(); assert_true(!error_result.success, "Command should fail"); assert_true(error_result.code != 0, "Exit code should be non-zero"); print("✓ Error handling with ignore_error works"); // Test 5: Multiline script execution print("\n--- Test 5: Multiline Script Execution ---"); let script = ` echo "Line 1" echo "Line 2" echo "Line 3" `; let script_result = run_command(script); assert_true(script_result.success, "Script should succeed"); assert_true(script_result.stdout.contains("Line 1"), "Should contain Line 1"); assert_true(script_result.stdout.contains("Line 2"), "Should contain Line 2"); assert_true(script_result.stdout.contains("Line 3"), "Should contain Line 3"); print("✓ Multiline script execution works"); // Test 6: Command with arguments print("\n--- Test 6: Command with Arguments ---"); let args_result = run_command("echo arg1 arg2 arg3"); assert_true(args_result.success, "Command with args should succeed"); assert_true(args_result.stdout.contains("arg1 arg2 arg3"), "Should contain all arguments"); print("✓ Command with arguments works"); // Test 7: Builder with logging print("\n--- Test 7: Builder with Logging ---"); let log_result = run("echo log test").log().silent().execute(); assert_true(log_result.success, "Logged command should succeed"); assert_true(log_result.stdout.contains("log test"), "Logged output should be captured"); print("✓ Builder with logging works"); // Test 8: Run with options map print("\n--- Test 8: Run with Options Map ---"); let options = #{ silent: true, die: false, log: false }; let options_result = run("echo options test", options); assert_true(options_result.success, "Options command should succeed"); assert_true(options_result.stdout.contains("options test"), "Options output should be captured"); print("✓ Run with options map works"); // Test 9: Complex script with variables print("\n--- Test 9: Complex Script with Variables ---"); let var_script = ` VAR="test_variable" echo "Variable value: $VAR" `; let var_result = run_command(var_script); assert_true(var_result.success, "Variable script should succeed"); assert_true(var_result.stdout.contains("Variable value: test_variable"), "Should expand variables"); print("✓ Complex script with variables works"); // Test 10: Script with conditionals print("\n--- Test 10: Script with Conditionals ---"); let cond_script = ` if [ "hello" = "hello" ]; then echo "Condition passed" else echo "Condition failed" fi `; let cond_result = run_command(cond_script); assert_true(cond_result.success, "Conditional script should succeed"); assert_true(cond_result.stdout.contains("Condition passed"), "Condition should pass"); print("✓ Script with conditionals works"); // Test 11: Builder method chaining print("\n--- Test 11: Builder Method Chaining ---"); let chain_result = run("echo chaining test") .silent() .ignore_error() .log() .execute(); assert_true(chain_result.success, "Chained command should succeed"); assert_true(chain_result.stdout.contains("chaining test"), "Chained output should be captured"); print("✓ Builder method chaining works"); // Test 12: CommandResult properties print("\n--- Test 12: CommandResult Properties ---"); let prop_result = run_command("echo property test"); assert_true(prop_result.success, "Property test command should succeed"); assert_true(prop_result.code == 0, "Exit code property should be 0"); assert_true(prop_result.stdout.len() > 0, "Stdout property should not be empty"); assert_true(prop_result.stderr.len() >= 0, "Stderr property should exist"); print("✓ CommandResult properties work"); print("\n=== All Command Execution Tests Passed! ===");