Skip to content

Commit 6f6959b

Browse files
committed
fix(golden): make --check and --diff mutually exclusive
The parser only rejected --check + --new and --diff + --new. Passing both --check and --diff was accepted, with --diff winning on output. The docstring describes them as alternatives, so reject the combination at the parser — symmetric with the existing --new checks, and less surprise.
1 parent 0294375 commit 6f6959b

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

tests/golden/test_update_goldens.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,14 @@ def boom(*_args, **_kwargs):
102102
monkeypatch.setattr(update_goldens, "_generate", boom)
103103
rc = update_goldens.main(["--new"])
104104
assert rc == 0
105+
106+
107+
def test_check_and_diff_are_mutually_exclusive(capsys):
108+
"""--check and --diff are documented as alternatives. Reject the
109+
combination at the parser, symmetric with the existing --new mutex
110+
checks."""
111+
with pytest.raises(SystemExit) as excinfo:
112+
update_goldens.main(["--check", "--diff"])
113+
assert excinfo.value.code == 2 # argparse parser.error exits 2
114+
err = capsys.readouterr().err
115+
assert "--check and --diff are mutually exclusive" in err

tests/golden/update_goldens.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ def main(argv: Optional[List[str]] = None) -> int:
106106
parser.error("--check and --new are mutually exclusive")
107107
if args.diff and args.new:
108108
parser.error("--diff and --new are mutually exclusive")
109+
if args.check and args.diff:
110+
# The implementation tolerates this (both imply dry_run, --diff
111+
# wins on output), but the docstring describes them as
112+
# alternatives. Reject at the parser, symmetric with the --new
113+
# checks above.
114+
parser.error("--check and --diff are mutually exclusive")
109115

110116
dry_run = args.check or args.diff
111117
any_diff = False

0 commit comments

Comments
 (0)