From 206aa80fe07a36b0980440931ec29672eb359fc3 Mon Sep 17 00:00:00 2001 From: Ehtasham-Yasin Date: Wed, 30 Sep 2026 14:04:36 +0200 Subject: [PATCH] fix: fail on unknown x.py commands Signed-off-by: Ehtasham-Yasin --- tools/test_x.py | 28 ++++++++++++++++++++++++++++ x.py | 1 + 2 files changed, 29 insertions(+) create mode 100644 tools/test_x.py diff --git a/tools/test_x.py b/tools/test_x.py new file mode 100644 index 00000000..3fa90a79 --- /dev/null +++ b/tools/test_x.py @@ -0,0 +1,28 @@ +"""Tests for the repository build driver.""" + +import subprocess +import sys +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] + + +class XPyTests(unittest.TestCase): + def test_unknown_command_fails_without_running_a_build(self): + result = subprocess.run( + [sys.executable, str(ROOT / "x.py"), "unrecognized-audit-command"], + cwd=ROOT, + capture_output=True, + text=True, + check=False, + ) + + self.assertEqual(result.returncode, 1) + self.assertIn("Unknown command: unrecognized-audit-command", result.stdout) + self.assertIn("Usage: x.py", result.stdout) + + +if __name__ == "__main__": + unittest.main() diff --git a/x.py b/x.py index ce8df546..d08cb8a7 100644 --- a/x.py +++ b/x.py @@ -1337,6 +1337,7 @@ def main(): else: print("Unknown command:", cmd) print("Usage: x.py [install | build | package | release | clean | gui] [target...]") + sys.exit(1) if __name__ == "__main__": main()