From b695067ca3c033784e9d11eeb16eec47ef3072ce Mon Sep 17 00:00:00 2001 From: Bonajo Date: Sun, 15 Nov 2026 10:59:10 +0100 Subject: [PATCH] fix(cli): describe -e as not failing on errors --- codestripper/cli.py | 2 +- tests/test_main.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/codestripper/cli.py b/codestripper/cli.py index a4aae3e..2170214 100644 --- a/codestripper/cli.py +++ b/codestripper/cli.py @@ -35,7 +35,7 @@ def add_commandline_arguments(parser: argparse.ArgumentParser) -> None: parser.add_argument("-w", "--working-directory", action="store", help="set the working directory for include/exclude", default=os.getcwd()) parser.add_argument("-e", "--fail-on-error", action="store_false", - help="Fail if an error occurs during code stripping") + help="do NOT fail if an error occurs during code stripping") unexpected_choices = [option.value for option in UnexpectedInputOptions] parser.add_argument("-b", "--binary", choices=unexpected_choices, default=UnexpectedInputOptions.FAIL.value, action="store", help="What to do if binary file is matched") diff --git a/tests/test_main.py b/tests/test_main.py index ed44c66..2814999 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -10,6 +10,7 @@ from _pytest.logging import LogCaptureFixture from codestripper.cli import main +from codestripper.errors import StripError test_project_dir = os.path.join(Path(__file__).parent.absolute()) @@ -97,3 +98,27 @@ def test_main_twice_does_not_strip_output(monkeypatch: pytest.MonkeyPatch, tmp_p main() found = sorted(path.relative_to(tmp_path).as_posix() for path in tmp_path.rglob("*.java")) assert found == ["a.java", "out/a.java"] + + +def test_main_help_fail_on_error(capsys: pytest.CaptureFixture): + with patch.object(sys, 'argv', ["codestripper", "--help"]): + with pytest.raises(SystemExit): + main() + # argparse wraps the help text, so compare without the line breaks + help_text = " ".join(capsys.readouterr().out.split()) + assert "-e, --fail-on-error do NOT fail if an error occurs during code stripping" in help_text + + +def test_main_fails_on_error_by_default(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): + shutil.copy(os.path.join(test_project_dir, "files", "MissingClose.java"), tmp_path) + monkeypatch.chdir(tmp_path) + with patch.object(sys, 'argv', ["codestripper", "MissingClose.java"]): + with pytest.raises(StripError): + main() + + +def test_main_fail_on_error_flag_does_not_fail(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): + shutil.copy(os.path.join(test_project_dir, "files", "MissingClose.java"), tmp_path) + monkeypatch.chdir(tmp_path) + with patch.object(sys, 'argv', ["codestripper", "-e", "MissingClose.java"]): + main()