Skip to content

Commit 0e9f1b1

Browse files
committed
test(cli): add help flag smoke test for exit code and output
1 parent 9658f02 commit 0e9f1b1

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

run_test.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,36 @@ def run_analyzer_on_file(c_path: Path) -> str:
7878
return output
7979

8080

81+
def check_help_flags() -> bool:
82+
"""
83+
Vérifie que -h et --help affichent l'aide sur stdout et retournent 0.
84+
"""
85+
print("=== Testing help flags ===")
86+
ok = True
87+
for flag in ["-h", "--help"]:
88+
result = subprocess.run(
89+
[str(ANALYZER), flag],
90+
capture_output=True,
91+
text=True,
92+
)
93+
stdout = result.stdout or ""
94+
if result.returncode != 0:
95+
print(f" ❌ {flag} returned {result.returncode} (expected 0)")
96+
ok = False
97+
continue
98+
missing = []
99+
for needle in ["Stack Usage Analyzer", "Usage:", "Options:", "-h, --help", "Examples:"]:
100+
if needle not in stdout:
101+
missing.append(needle)
102+
if missing:
103+
print(f" ❌ {flag} missing help sections: {', '.join(missing)}")
104+
ok = False
105+
else:
106+
print(f" ✅ {flag} OK")
107+
print()
108+
return ok
109+
110+
81111
def check_file(c_path: Path) -> bool:
82112
"""
83113
Vérifie qu'avec ce fichier, toutes les attentes sont présentes
@@ -112,12 +142,13 @@ def check_file(c_path: Path) -> bool:
112142

113143

114144
def main() -> int:
145+
global_ok = check_help_flags()
146+
115147
c_files = sorted(TEST_DIR.glob("**/*.c"))
116148
if not c_files:
117149
print(f"No .c files found under {TEST_DIR}")
118-
return
150+
return 0 if global_ok else 1
119151

120-
global_ok = True
121152
for f in c_files:
122153
ok = check_file(f)
123154
if not ok:

0 commit comments

Comments
 (0)