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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//! CLI Contract Tests: `ruchy property-tests`
//!
//! **Purpose**: Validate user-facing contract (exit codes, stdio, property testing)
//! **Layer 4**: CLI expectation testing (black-box validation)
//!
//! **Contract Specification**:
//! - Exit code 0: Property tests passed
//! - Exit code 1: Property tests failed OR file not found
//! - stdout: Property test report (text/json/markdown format)
//! - stderr: Error messages (test failures, missing files)
//! - Options: --cases, --seed, --format, --output
//!
//! **Reference**: docs/specifications/15-tool-improvement-spec.md (v4.0)
//! **TICR**: docs/testing/TICR-ANALYSIS.md (property-tests: 0.4 → target 0.5)
//!
//! **Note**: Most tests are lightweight and don't run full property test suites
#![allow(clippy::ignore_without_reason)] // Property tests run with --ignored flag
#![allow(missing_docs)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
/// Helper: Create ruchy command
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
/// Helper: Create temp file with content
fn create_temp_file(dir: &TempDir, name: &str, content: &str) -> std::path::PathBuf {
let path = dir.path().join(name);
fs::write(&path, content).expect("Failed to write temp file");
path
}
// ============================================================================
// CLI CONTRACT TESTS: BASIC BEHAVIOR
// ============================================================================
#[test]
fn cli_property_tests_valid_file() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "simple.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10") // Very few cases for speed
.assert();
// Just verify command runs
}
#[test]
fn cli_property_tests_missing_file_exits_nonzero() {
// FIX: CLI-CONTRACT-PROPERTY-TESTS-001 - Now handles missing files gracefully
ruchy_cmd()
.arg("property-tests")
.arg("nonexistent_xyz.ruchy")
.arg("--cases")
.arg("10")
.assert()
.failure(); // Exit code != 0
}
#[test]
fn cli_property_tests_syntax_error_exits_nonzero() {
// FIX: CLI-CONTRACT-PROPERTY-TESTS-002 - Now handles syntax errors gracefully
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "invalid.ruchy", "let x = \n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10")
.assert()
.failure(); // Exit code != 0
}
// ============================================================================
// CLI CONTRACT TESTS: OPTIONS
// ============================================================================
#[test]
fn cli_property_tests_custom_cases() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "cases_test.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("100") // Custom case count
.assert();
}
#[test]
fn cli_property_tests_invalid_cases_format() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "bad_cases.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("invalid") // Invalid number
.assert()
.failure(); // Should fail due to invalid argument
}
#[test]
fn cli_property_tests_with_seed() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "seed_test.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10")
.arg("--seed")
.arg("12345") // Reproducible seed
.assert();
}
// ============================================================================
// CLI CONTRACT TESTS: FORMAT OPTIONS
// ============================================================================
#[test]
fn cli_property_tests_text_format() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "text_format.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--format")
.arg("text")
.arg("--cases")
.arg("10")
.assert();
}
#[test]
fn cli_property_tests_json_format() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "json_format.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--format")
.arg("json")
.arg("--cases")
.arg("10")
.assert();
}
#[test]
fn cli_property_tests_markdown_format() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "markdown_format.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--format")
.arg("markdown")
.arg("--cases")
.arg("10")
.assert();
}
// ============================================================================
// CLI CONTRACT TESTS: OUTPUT FILE
// ============================================================================
#[test]
fn cli_property_tests_output_to_file() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "output_test.ruchy", "let x = 42\n");
let output_file = temp.path().join("property_report.txt");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--output")
.arg(&output_file)
.arg("--cases")
.arg("10")
.assert();
}
// ============================================================================
// CLI CONTRACT TESTS: ERROR MESSAGES
// ============================================================================
#[test]
fn cli_property_tests_missing_file_writes_stderr() {
// FIX: CLI-CONTRACT-PROPERTY-TESTS-001 - Now handles missing files gracefully
ruchy_cmd()
.arg("property-tests")
.arg("missing.ruchy")
.arg("--cases")
.arg("10")
.assert()
.failure()
.stderr(
predicate::str::contains("not found")
.or(predicate::str::contains("No such file"))
.or(predicate::str::contains("does not exist")),
);
}
#[test]
fn cli_property_tests_syntax_error_writes_stderr() {
// FIX: CLI-CONTRACT-PROPERTY-TESTS-002 - Now handles syntax errors gracefully
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "bad_syntax.ruchy", "fun f( { }\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10")
.assert()
.failure()
.stderr(predicate::str::is_empty().not()); // stderr NOT empty
}
// ============================================================================
// CLI CONTRACT TESTS: VERBOSE MODE
// ============================================================================
#[test]
fn cli_property_tests_verbose_flag() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "verbose.ruchy", "let x = 42\n");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--verbose")
.arg("--cases")
.arg("10")
.assert();
}
// ============================================================================
// CLI CONTRACT TESTS: EDGE CASES
// ============================================================================
#[test]
fn cli_property_tests_empty_file_fails() {
// FIX: CLI-CONTRACT-PROPERTY-TESTS-002 - Now handles empty files gracefully
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "empty.ruchy", "");
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10")
.assert()
.failure(); // Empty file should fail
}
#[test]
fn cli_property_tests_complex_program() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(
&temp,
"complex.ruchy",
r"
fun factorial(n) {
if n <= 1 {
1
} else {
n * factorial(n - 1)
}
}
println(factorial(5))
",
);
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("10")
.assert();
}
// ============================================================================
// CLI CONTRACT TESTS: HELP
// ============================================================================
#[test]
fn cli_property_tests_help_flag() {
ruchy_cmd()
.arg("property-tests")
.arg("--help")
.assert()
.success()
.stdout(
predicate::str::contains("property")
.or(predicate::str::contains("Property"))
.or(predicate::str::contains("cases")),
);
}
// ============================================================================
// CLI CONTRACT TESTS: ZERO CASES EDGE CASE
// ============================================================================
#[test]
fn cli_property_tests_zero_cases() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "zero_cases.ruchy", "let x = 42\n");
// Zero cases might be valid (no tests run) or invalid
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("0")
.assert();
// Just verify command handles this case
}
#[test]
fn cli_property_tests_very_large_cases() {
let temp = TempDir::new().unwrap();
let file = create_temp_file(&temp, "large_cases.ruchy", "let x = 42\n");
// Large number of cases (would take very long)
ruchy_cmd()
.arg("property-tests")
.arg(&file)
.arg("--cases")
.arg("1000000")
.timeout(std::time::Duration::from_secs(2))
.assert();
// Timeout will kill it, but tests CLI accepts the parameter
}