1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#![allow(missing_docs)]
// Regression tests for GitHub Issue #85: Missing std::process::Command execution
// https://github.com/paiml/ruchy/issues/85
//
// REGRESSION INFO:
// - Working Version: None (never implemented)
// - Broken Versions: All versions prior to v3.148.0
// - Error: "Runtime error: Undefined variable: Command"
// - Type: Missing stdlib feature
//
// ROOT CAUSE: std::process::Command was never implemented
// - No Command::new() handler in eval_qualified_name
// - No Command methods (.arg, .output, .status) implemented
// - No String::from_utf8() for byte array conversion
// - Pattern matching didn't support EnumVariant for Ok/Err
//
// SOLUTION: Comprehensive std::process::Command implementation
// - Added Command::new() to eval_qualified_name (interpreter.rs:2059)
// - Implemented Command methods in eval_method_dispatch.rs:
// - .arg() builds argument list (line 240-259)
// - .output() executes and returns Result<Output, Error> (line 306-361)
// - .status() executes and returns Result<ExitStatus, Error> (line 260-305)
// - Implemented String::from_utf8() in eval_builtin.rs:2936-2976
// - Enhanced pattern matching for Ok/Err EnumVariant (eval_pattern_match.rs:195-261)
// - Added ExitStatus.success() method (eval_method_dispatch.rs:384-412)
// - All 4 regression tests pass ✅
//
// Test naming convention: test_regression_085_<scenario>
use predicates::prelude::*;
/// Test #1: Basic `Command::new()` and `output()` (minimal reproduction from Issue #85)
/// This is the exact test case reported in the GitHub issue.
#[test]
fn test_regression_085_command_basic_output() {
let code = r#"
use std::process::Command;
fun main() {
let output = Command::new("echo")
.arg("Hello from Ruchy!")
.output();
match output {
Ok(result) => {
let stdout = String::from_utf8(result.stdout);
match stdout {
Ok(text) => println!("{}", text),
Err(_) => println!("Failed to decode stdout")
}
}
Err(_) => println!("Command failed")
}
}
"#;
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("-e")
.arg(code)
.timeout(std::time::Duration::from_secs(5))
.assert()
.success()
.stdout(predicate::str::contains("Hello from Ruchy!"));
}
/// Test #2: Command with status checking
/// Verifies that Command execution returns proper status codes
#[test]
fn test_regression_085_command_status() {
let code = r#"
use std::process::Command;
fun main() {
let status = Command::new("echo")
.arg("test")
.status();
match status {
Ok(s) => {
if s.success() {
println!("Success: true");
} else {
println!("Success: false");
}
}
Err(_) => println!("Command failed")
}
}
"#;
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("-e")
.arg(code)
.timeout(std::time::Duration::from_secs(5))
.assert()
.success()
.stdout(predicate::str::contains("Success: true"));
}
/// Test #3: Command with multiple arguments
/// Verifies that Command handles multiple arguments correctly
#[test]
fn test_regression_085_command_multiple_args() {
let code = r#"
use std::process::Command;
fun main() {
let output = Command::new("printf")
.arg("%s %s\n")
.arg("Hello")
.arg("World")
.output();
match output {
Ok(result) => {
let stdout = String::from_utf8(result.stdout);
match stdout {
Ok(text) => println!("{}", text),
Err(_) => println!("Failed")
}
}
Err(_) => println!("Command failed")
}
}
"#;
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("-e")
.arg(code)
.timeout(std::time::Duration::from_secs(5))
.assert()
.success()
.stdout(predicate::str::contains("Hello World"));
}
/// Test #4: Command error handling (non-existent command)
/// Verifies that Command properly handles errors
#[test]
fn test_regression_085_command_error_handling() {
let code = r#"
use std::process::Command;
fun main() {
let output = Command::new("nonexistent_command_12345")
.output();
match output {
Ok(_) => println!("Unexpected success"),
Err(_) => println!("Error handled correctly")
}
}
"#;
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("-e")
.arg(code)
.timeout(std::time::Duration::from_secs(5))
.assert()
.success()
.stdout(predicate::str::contains("Error handled correctly"));
}