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()