diff options
Diffstat (limited to 'tests/test_mc_command.py')
| -rw-r--r-- | tests/test_mc_command.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_mc_command.py b/tests/test_mc_command.py new file mode 100644 index 000000000..0e3c84e53 --- /dev/null +++ b/tests/test_mc_command.py | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | """LLVM_MC is one executable path or a whole command line, in every tool that reads it. | ||
| 2 | |||
| 3 | Windows runs llvm-mc through WSL (the official Windows LLVM build has no AMDGPU target): | ||
| 4 | |||
| 5 | set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc | ||
| 6 | |||
| 7 | python -I tests/test_mc_command.py | ||
| 8 | """ | ||
| 9 | import os | ||
| 10 | import sys | ||
| 11 | import tempfile | ||
| 12 | import unittest | ||
| 13 | from unittest import mock | ||
| 14 | |||
| 15 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| 16 | sys.path.insert(0, os.path.join(ROOT, "tools")) | ||
| 17 | |||
| 18 | import mc_command # noqa: E402 | ||
| 19 | |||
| 20 | |||
| 21 | class SplitCommandTest(unittest.TestCase): | ||
| 22 | def test_bare_name(self): | ||
| 23 | self.assertEqual(mc_command.split_command("llvm-mc"), ["llvm-mc"]) | ||
| 24 | |||
| 25 | def test_empty(self): | ||
| 26 | self.assertEqual(mc_command.split_command(""), []) | ||
| 27 | self.assertEqual(mc_command.split_command(" "), []) | ||
| 28 | |||
| 29 | def test_command_line(self): | ||
| 30 | self.assertEqual(mc_command.split_command("wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc"), | ||
| 31 | ["wsl", "-d", "Ubuntu", "-e", "/usr/lib/llvm-21/bin/llvm-mc"]) | ||
| 32 | |||
| 33 | def test_quoted_arguments(self): | ||
| 34 | if os.name == "nt": | ||
| 35 | raw = '"C:\\Program Files\\LLVM\\bin\\llvm-mc.exe" --version' | ||
| 36 | want = ["C:\\Program Files\\LLVM\\bin\\llvm-mc.exe", "--version"] | ||
| 37 | else: | ||
| 38 | raw = '"/opt/llvm 21/bin/llvm-mc" --version' | ||
| 39 | want = ["/opt/llvm 21/bin/llvm-mc", "--version"] | ||
| 40 | self.assertEqual(mc_command.split_command(raw), want) | ||
| 41 | |||
| 42 | def test_path_with_spaces_is_kept_whole(self): | ||
| 43 | with tempfile.TemporaryDirectory() as tmp: | ||
| 44 | path = os.path.join(tmp, "llvm mc") | ||
| 45 | with open(path, "w", encoding="utf-8") as f: | ||
| 46 | f.write("") | ||
| 47 | self.assertEqual(mc_command.split_command(path), [path]) | ||
| 48 | self.assertEqual(mc_command.split_command(f'"{path}"'), [path]) | ||
| 49 | |||
| 50 | def test_mc_command_reads_the_environment(self): | ||
| 51 | with mock.patch.dict(os.environ, {"LLVM_MC": "wsl -d Ubuntu -e /opt/llvm-21/bin/llvm-mc"}): | ||
| 52 | self.assertEqual(mc_command.mc_command(), | ||
| 53 | ["wsl", "-d", "Ubuntu", "-e", "/opt/llvm-21/bin/llvm-mc"]) | ||
| 54 | |||
| 55 | def test_mc_command_falls_back_to_the_path_name(self): | ||
| 56 | with mock.patch.dict(os.environ, {"LLVM_MC": ""}): | ||
| 57 | self.assertEqual(mc_command.mc_command(), ["llvm-mc"]) | ||
| 58 | |||
| 59 | |||
| 60 | if __name__ == "__main__": | ||
| 61 | unittest.main() | ||