diff --git a/scripts/diff_truth.py b/scripts/diff_truth.py index b4a1ab2b..916e845e 100644 --- a/scripts/diff_truth.py +++ b/scripts/diff_truth.py @@ -168,12 +168,19 @@ def main() -> None: "--all", action="store_true", help="diff all registered platforms" ) group.add_argument("--platform", help="diff a single platform") - parser.add_argument( + # One output form: --json beside --format markdown printed JSON and + # dropped the markdown without a word. + output = parser.add_mutually_exclusive_group() + output.add_argument( "--json", action="store_true", dest="json_output", help="JSON output" ) - parser.add_argument( + output.add_argument( "--format", choices=["terminal", "markdown"], default="terminal" ) + output.add_argument( + "--markdown", action="store_const", const="markdown", dest="format", + help="same as --format markdown, the spelling validate_pr uses", + ) parser.add_argument("--truth-dir", default="dist/truth") parser.add_argument("--platforms-dir", default="platforms") parser.add_argument( diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 44274d58..c50f892d 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -4401,5 +4401,25 @@ class VerifyAllSummaryNamesWhatIsWrong(unittest.TestCase): self.assertIn("0 critical,", summary) + +class OneOutputFormPerRun(unittest.TestCase): + """`diff_truth.py --json --format markdown` printed JSON with rc 0, the + markdown asked for dropped without a word.""" + + def test_json_and_markdown_are_refused_together(self): + for script, argv in ( + ("diff_truth.py", ["--platform", "romm", "--json", "--format", "markdown"]), + ("diff_truth.py", ["--platform", "romm", "--json", "--markdown"]), + ("validate_pr.py", ["--json", "--markdown", "bios/Sony/PlayStation/scph5501.bin"]), + ): + with self.subTest(script=script, argv=argv): + proc = subprocess.run( + [sys.executable, f"scripts/{script}", *argv], capture_output=True, + text=True, cwd=str(ROOT), timeout=120, check=False, + ) + self.assertEqual(proc.returncode, 2, proc.stdout[-300:]) + self.assertIn("not allowed with", proc.stderr) + + if __name__ == "__main__": unittest.main() diff --git a/wiki/tools.md b/wiki/tools.md index 74c00b2a..e98651a0 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -597,7 +597,7 @@ Further options, by script: | `check_freshness.py` | `--cache-dir`, `--native-cache-dir` (originals of the native export) and `--truth-dir` move the caches it reads | | `check_release.py` | `--tag`, `--sums dist/SHA256SUMS.txt`, `--record` (default `release.json`), `--json` | | `check_release_assets.py` | `--gitignore` (the asset registry), `--db`, `--notes FILE`, `--json` | -| `diff_truth.py` | `--format markdown`, `--truth-dir`, `--target` | +| `diff_truth.py` | `--format markdown` (or `--markdown`), `--json`, one of them; `--truth-dir`, `--target` | | `download.py` | `--list`, `--info ` shows a pack's file name, size and parts without downloading | | `export_native.py` | `--truth-dir`, `--upstream-dir` (where the platforms' own files are cached) | | `find_pinned_revision.py` | `--repo URL --path FILE --md5 HASH`, `--write PATH`, `--cache-dir` |