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
#![allow(deprecated)]
#![allow(clippy::unwrap_used)] // Tests can use unwrap() for simplicity
#![allow(clippy::expect_used)]
//! REPL Test Harness
//!
//! Task: REPL-002-003 - Create REPL test harness with assert_cmd
//!
//! This file provides reusable test infrastructure for REPL testing.
//! All REPL CLI tests should use these patterns.
//!
//! Quality Standards:
//! - MANDATORY: Use assert_cmd::Command for all CLI tests
//! - Test naming: test_<TASK_ID>_<feature>_<scenario>
//! - Property tests: 100+ cases per component
//! - Mutation score: ≥90% kill rate
//!
//! References:
//! - CLAUDE.md - CLI Testing Protocol (MANDATORY)
//! - REPL-DEBUGGER-ROADMAP.yaml - REPL-002-003
#![allow(non_snake_case)] // Test naming convention uses TASK_ID format
use assert_cmd::Command;
use predicates::prelude::*;
/// Helper function to create bashrs REPL command
///
/// # Example
///
/// ```no_run
/// use assert_cmd::Command;
///
/// fn bashrs_repl() -> Command {
/// assert_cmd::cargo_bin_cmd!("bashrs").arg("repl")
/// }
///
/// #[test]
/// fn test_REPL_002_003_repl_starts() {
/// bashrs_repl()
/// .write_stdin(":quit\n")
/// .assert()
/// .success();
/// }
/// ```
pub fn bashrs_repl() -> Command {
let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
cmd.arg("repl");
cmd
}
/// Helper function to create bashrs REPL with debug mode
pub fn bashrs_repl_debug() -> Command {
let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
cmd.arg("repl").arg("--debug");
cmd
}
/// Helper function to create bashrs REPL with custom config
pub fn bashrs_repl_custom(max_memory: &str, timeout: &str, max_depth: &str) -> Command {
let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
cmd.arg("repl")
.arg("--max-memory")
.arg(max_memory)
.arg("--timeout")
.arg(timeout)
.arg("--max-depth")
.arg(max_depth);
cmd
}
// ===== REPL-002-003: Test Harness Verification =====
/// Test: REPL-002-003-001 - Verify REPL starts successfully
#[test]
fn test_REPL_002_003_repl_starts() {
bashrs_repl()
.write_stdin("quit\n")
.assert()
.success()
.stdout(predicate::str::contains("bashrs"));
}
/// Test: REPL-002-003-002 - Verify debug mode works
#[test]
fn test_REPL_002_003_repl_debug_mode() {
bashrs_repl_debug()
.write_stdin("quit\n")
.assert()
.success()
.stdout(predicate::str::contains("bashrs"));
}
/// Test: REPL-002-003-003 - Verify custom config works
#[test]
fn test_REPL_002_003_repl_custom_config() {
bashrs_repl_custom("200", "60", "200")
.write_stdin("quit\n")
.assert()
.success()
.stdout(predicate::str::contains("bashrs"));
}
/// Test: REPL-002-003-004 - Verify REPL handles quit command
#[test]
fn test_REPL_002_003_repl_quit() {
bashrs_repl()
.write_stdin("quit\n")
.assert()
.success()
.stdout(predicate::str::contains("Goodbye!"));
}
/// Test: REPL-002-003-005 - Verify REPL handles exit command
#[test]
fn test_REPL_002_003_repl_exit() {
bashrs_repl()
.write_stdin("exit\n")
.assert()
.success()
.stdout(predicate::str::contains("Goodbye!"));
}
/// Test: REPL-002-003-006 - Verify REPL handles EOF
#[test]
fn test_REPL_002_003_repl_eof() {
bashrs_repl()
.write_stdin("") // Empty input simulates EOF
.assert()
.success()
.stdout(predicate::str::contains("EOF"));
}
/// Test: REPL-002-003-007 - Verify REPL mode switching
///
/// NOTE: This is a template test demonstrating mode switching verification.
/// Actual mode switching implementation is tracked in separate sprint tasks.
#[test]
#[ignore = "Template test - mode switching tested in REPL-003-004"]
fn test_REPL_002_003_mode_switching() {
bashrs_repl()
.write_stdin(":mode parse\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("parse"));
}
/// Test: REPL-002-003-008 - Verify REPL help command
#[test]
fn test_REPL_002_003_help_command() {
bashrs_repl()
.write_stdin("help\nquit\n")
.assert()
.success()
.stdout(predicate::str::contains("OVERVIEW"));
}
// ===== Documentation Examples =====
/// Example: Basic REPL test
///
/// ```no_run
/// use assert_cmd::Command;
/// use predicates::prelude::*;
///
/// #[test]
/// fn test_example_basic_repl() {
/// let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
/// cmd.arg("repl")
/// .write_stdin("quit\n")
/// .assert()
/// .success()
/// .stdout(predicate::str::contains("bashrs"));
/// }
/// ```
#[allow(dead_code)]
fn example_basic_repl_test() {}
/// Example: REPL with mode switching
///
/// ```no_run
/// use assert_cmd::Command;
/// use predicates::prelude::*;
///
/// #[test]
/// fn test_example_mode_switching() {
/// let mut cmd = assert_cmd::cargo_bin_cmd!("bashrs");
/// cmd.arg("repl")
/// .write_stdin(":mode purify\nmkdir /tmp/test\nquit\n")
/// .assert()
/// .success()
/// .stdout(predicate::str::contains("purify"))
/// .stdout(predicate::str::contains("mkdir -p"));
/// }
/// ```
#[allow(dead_code)]
fn example_mode_switching_test() {}
// ===== Property Tests (using example from roadmap) =====
#[cfg(test)]
mod property_tests {
use super::*;
use proptest::prelude::*;
// Property test: REPL always exits cleanly with valid quit commands
proptest! {
#[test]
fn prop_REPL_002_003_quit_commands_always_work(
quit_cmd in prop::sample::select(vec!["quit", "exit", ":quit", ":exit"])
) {
let cmd_with_newline = format!("{}\n", quit_cmd);
bashrs_repl()
.write_stdin(cmd_with_newline.as_str())
.assert()
.success();
}
}
// Property test: REPL handles empty lines gracefully
proptest! {
#[test]
fn prop_REPL_002_003_empty_input_handled(
empty_count in 1usize..10
) {
let empty_input = "\n".repeat(empty_count) + "quit\n";
bashrs_repl()
.write_stdin(empty_input.as_str())
.assert()
.success();
}
}
}