diff --git a/tools/get_maintainer.py b/tools/get_maintainer.py index 91043c27..6481e24a 100644 --- a/tools/get_maintainer.py +++ b/tools/get_maintainer.py @@ -27,11 +27,12 @@ import sys import os +from pathlib import Path -MAINTAINERS_FILE = "MAINTAINERS" +MAINTAINERS_FILE = Path(__file__).resolve().parent.parent / "MAINTAINERS" if not os.path.exists(MAINTAINERS_FILE): - print("Error: MAINTAINERS file not found.") + print(f"Error: MAINTAINERS file not found at {MAINTAINERS_FILE}.") sys.exit(1) if len(sys.argv) < 2: diff --git a/tools/test_get_maintainer.py b/tools/test_get_maintainer.py new file mode 100644 index 00000000..e5a4b03b --- /dev/null +++ b/tools/test_get_maintainer.py @@ -0,0 +1,29 @@ +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parent.parent +SCRIPT = ROOT / "tools" / "get_maintainer.py" + + +class TestGetMaintainer(unittest.TestCase): + def test_invocation_outside_repository_root(self): + with tempfile.TemporaryDirectory() as cwd: + result = subprocess.run( + [sys.executable, str(SCRIPT), "front/parser/ast.rs"], + cwd=cwd, + capture_output=True, + text=True, + check=False, + ) + + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("Maintainers to CC:", result.stdout) + self.assertNotIn("MAINTAINERS file not found", result.stdout) + + +if __name__ == "__main__": + unittest.main()