upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/test_mc_command.py
diff options
context:
space:
mode:
authorDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
committerDiesel <dev.diesel@proton.me>2026-11-21 22:44:07 +0100
commit5c1a1fbb6bf6f609eb4e61baa4961ce382743a4e (patch)
treeac8ad90058b97ab241fdc65edae3d4628d20ee1e /tests/test_mc_command.py
parentc45309e29f21c1d5b75678db0e2dc2dd11cff25b (diff)
parent4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff)
Merge main to include the compute Y/Z harness test fix
Diffstat (limited to 'tests/test_mc_command.py')
-rw-r--r--tests/test_mc_command.py61
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
3Windows 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"""
9import os
10import sys
11import tempfile
12import unittest
13from unittest import mock
14
15ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
16sys.path.insert(0, os.path.join(ROOT, "tools"))
17
18import mc_command # noqa: E402
19
20
21class 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
60if __name__ == "__main__":
61 unittest.main()