@@ -54,21 +54,32 @@ def test_cli_writes_file(tmp_path: Path, monkeypatch: MonkeyPatch, cli_args: Lis
5454
5555def test_cli_with_stdout_output () -> None :
5656 """Test CLI invocation with output directed to STDOUT."""
57- result = _invoke_isolated_cli_runner (["./" , "--output" , "-" , "--exclude-pattern" , "tests/" ])
57+ # Clean up any existing digest.txt file before test
58+ if os .path .exists (OUTPUT_FILE_NAME ):
59+ os .remove (OUTPUT_FILE_NAME )
5860
59- # ─── core expectations (stdout) ────────────────────────────────────-
60- assert result .exit_code == 0 , f"CLI exited with code { result .exit_code } , stderr: { result .stderr } "
61- assert "---" in result .stdout , "Expected file separator '---' not found in STDOUT"
62- assert "src/gitingest/cli.py" in result .stdout , "Expected content (e.g., src/gitingest/cli.py) not found in STDOUT"
63- assert not os .path .exists (OUTPUT_FILE_NAME ), f"Output file { OUTPUT_FILE_NAME } was unexpectedly created."
61+ try :
62+ result = _invoke_isolated_cli_runner (["./" , "--output" , "-" , "--exclude-pattern" , "tests/" ])
6463
65- # ─── the summary must *not* pollute STDOUT, must appear on STDERR ───
66- summary = "Analysis complete! Output sent to stdout."
67- stdout_lines = result .stdout .splitlines ()
68- stderr_lines = result .stderr .splitlines ()
69- assert summary not in stdout_lines , "Unexpected summary message found in STDOUT"
70- assert summary in stderr_lines , "Expected summary message not found in STDERR"
71- assert f"Output written to: { OUTPUT_FILE_NAME } " not in stderr_lines
64+ # ─── core expectations (stdout) ────────────────────────────────────-
65+ assert result .exit_code == 0 , f"CLI exited with code { result .exit_code } , stderr: { result .stderr } "
66+ assert "---" in result .stdout , "Expected file separator '---' not found in STDOUT"
67+ assert (
68+ "src/gitingest/cli.py" in result .stdout
69+ ), "Expected content (e.g., src/gitingest/cli.py) not found in STDOUT"
70+ assert not os .path .exists (OUTPUT_FILE_NAME ), f"Output file { OUTPUT_FILE_NAME } was unexpectedly created."
71+
72+ # ─── the summary must *not* pollute STDOUT, must appear on STDERR ───
73+ summary = "Analysis complete! Output sent to stdout."
74+ stdout_lines = result .stdout .splitlines ()
75+ stderr_lines = result .stderr .splitlines ()
76+ assert summary not in stdout_lines , "Unexpected summary message found in STDOUT"
77+ assert summary in stderr_lines , "Expected summary message not found in STDERR"
78+ assert f"Output written to: { OUTPUT_FILE_NAME } " not in stderr_lines
79+ finally :
80+ # Clean up any digest.txt file that might have been created during test
81+ if os .path .exists (OUTPUT_FILE_NAME ):
82+ os .remove (OUTPUT_FILE_NAME )
7283
7384
7485def _invoke_isolated_cli_runner (args : List [str ]) -> Result :
0 commit comments