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
#![allow(
dead_code,
unused_imports,
unused_variables,
deprecated,
clippy::all,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
unused_mut
)]
//! End-to-end integration tests for utils commands
//!
//! **Chicago TDD Principles**:
//! - REAL CLI process execution
//! - REAL system checks (Rust, Cargo, Git)
//! - REAL environment inspection
//! - NO mocking of system state
//!
//! **Critical User Workflows (80/20)**:
//! 1. Run system diagnostics (doctor)
//! 2. Check environment variables
//! 3. Verify tool installation
use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::TempDir;
/// Helper to create ggen command
fn ggen() -> Command {
Command::cargo_bin("ggen").expect("Failed to find ggen binary")
}
#[test]
fn test_utils_doctor_runs() {
// Chicago TDD: Verify system diagnostics execute
ggen().arg("utils").arg("doctor").assert().success().stdout(
predicate::str::contains("Rust")
.or(predicate::str::contains("Cargo"))
.or(predicate::str::contains("checks")),
);
}
#[test]
fn test_utils_doctor_all() {
// Chicago TDD: Verify all checks mode
ggen()
.arg("utils")
.arg("doctor")
.arg("--all")
.assert()
.success();
}
#[test]
fn test_utils_doctor_env_format() {
// Chicago TDD: Verify environment format output
ggen()
.arg("utils")
.arg("doctor")
.arg("--format")
.arg("env")
.assert()
.success();
}
#[test]
fn test_utils_doctor_json_format() {
// Chicago TDD: Verify JSON format output
let output = ggen()
.arg("utils")
.arg("doctor")
.arg("--format")
.arg("json")
.output()
.expect("Failed to execute");
// Command should complete successfully
assert!(output.status.success(), "Doctor should succeed");
}
#[test]
fn test_utils_env_lists() {
// Chicago TDD: Verify environment listing
// Note: env command is stubbed, returns empty
ggen()
.arg("utils")
.arg("env")
.arg("--list")
.assert()
.success();
}
#[test]
fn test_utils_env_get() {
// Chicago TDD: Verify environment variable get
// Note: env command is stubbed, returns empty
ggen()
.arg("utils")
.arg("env")
.arg("--get")
.arg("PATH")
.assert()
.success();
}
#[test]
fn test_utils_env_set() {
// Chicago TDD: Verify environment variable set
// Note: env command is stubbed
ggen()
.arg("utils")
.arg("env")
.arg("--set")
.arg("TEST_VAR=test")
.assert()
.success();
}
#[test]
fn test_utils_help_shows_verbs() {
// Chicago TDD: Verify help state is comprehensive
ggen()
.arg("utils")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("doctor"))
.stdout(predicate::str::contains("env"));
}
#[test]
fn test_utils_doctor_help() {
// Chicago TDD: Verify verb-specific help
ggen()
.arg("utils")
.arg("doctor")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("diagnostic").or(predicate::str::contains("check")));
}
#[test]
fn test_utils_invalid_verb() {
// Chicago TDD: Verify error handling for invalid verbs
ggen()
.arg("utils")
.arg("invalid-verb")
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
fn test_utils_doctor_checks_system_tools() {
// Chicago TDD: Verify doctor checks for required tools
let output = ggen()
.arg("utils")
.arg("doctor")
.output()
.expect("Failed to execute");
let stdout = String::from_utf8_lossy(&output.stdout);
// Verify system tools are checked
// Output should contain information about Rust, Cargo, or Git
assert!(
stdout.contains("Rust")
|| stdout.contains("Cargo")
|| stdout.contains("Git")
|| stdout.contains("checks"),
"Doctor should check system tools"
);
}
#[test]
fn test_utils_doctor_reports_health_status() {
// Chicago TDD: Verify doctor reports overall health
let output = ggen()
.arg("utils")
.arg("doctor")
.output()
.expect("Failed to execute");
let stdout = String::from_utf8_lossy(&output.stdout);
// Verify health status reported
assert!(
stdout.contains("healthy")
|| stdout.contains("needs attention")
|| stdout.contains("status"),
"Doctor should report health status"
);
}