diff options
| author | DanielDeGiorgio <102986566+DanielDeGiorgio@users.noreply.github.com> | 2026-11-22 21:31:21 +0100 |
|---|---|---|
| committer | DanielDeGiorgio <102986566+DanielDeGiorgio@users.noreply.github.com> | 2026-11-22 21:31:21 +0100 |
| commit | 6566ed34253fd32fc50adad0f769f33dbca3ca85 (patch) | |
| tree | 3d5037198c6b74363c588010fa0f3799028fc767 /tests/test_mc_command.py | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Preserve literal quotes in LLVM command arguments
Diffstat (limited to 'tests/test_mc_command.py')
| -rw-r--r-- | tests/test_mc_command.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_mc_command.py b/tests/test_mc_command.py index f579e9dc5..7f908c0c5 100644 --- a/tests/test_mc_command.py +++ b/tests/test_mc_command.py | |||
| @@ -6,7 +6,9 @@ Windows runs llvm-mc through WSL (the official Windows LLVM build has no AMDGPU | |||
| 6 | 6 | ||
| 7 | python -I tests/test_mc_command.py | 7 | python -I tests/test_mc_command.py |
| 8 | """ | 8 | """ |
| 9 | import json | ||
| 9 | import os | 10 | import os |
| 11 | import shlex | ||
| 10 | import subprocess | 12 | import subprocess |
| 11 | import sys | 13 | import sys |
| 12 | import tempfile | 14 | import tempfile |
| @@ -40,6 +42,26 @@ class SplitCommandTest(unittest.TestCase): | |||
| 40 | want = ["/opt/llvm 21/bin/llvm-mc", "--version"] | 42 | want = ["/opt/llvm 21/bin/llvm-mc", "--version"] |
| 41 | self.assertEqual(mc_command.split_command(raw), want) | 43 | self.assertEqual(mc_command.split_command(raw), want) |
| 42 | 44 | ||
| 45 | def test_windows_backslashes_and_literal_quotes_round_trip(self): | ||
| 46 | argv = [r"C:\Program Files\LLVM\bin\llvm-mc.exe", "", 'label="wide value"', | ||
| 47 | "C:\\output folder\\", r"plain\path", 'a\\"b'] | ||
| 48 | with mock.patch.object(mc_command.os, "name", "nt"): | ||
| 49 | self.assertEqual(mc_command.split_command(subprocess.list2cmdline(argv)), argv) | ||
| 50 | self.assertEqual(mc_command.split_command('llvm-mc "a""b"'), ["llvm-mc", 'a"b']) | ||
| 51 | |||
| 52 | def test_posix_keeps_quotes_that_are_part_of_an_argument(self): | ||
| 53 | argv = ["llvm-mc", '"literal quotes"', "", '--label="wide value"'] | ||
| 54 | with mock.patch.object(mc_command.os, "name", "posix"): | ||
| 55 | self.assertEqual(mc_command.split_command(shlex.join(argv)), argv) | ||
| 56 | |||
| 57 | @unittest.skipUnless(os.name == "nt", "Windows command line and subprocess") | ||
| 58 | def test_windows_subprocess_receives_literal_quotes_and_a_trailing_backslash(self): | ||
| 59 | want = ['"keep these quotes"', "C:\\output folder\\", ""] | ||
| 60 | command = [sys.executable, "-c", "import json, sys; print(json.dumps(sys.argv[1:]))", *want] | ||
| 61 | args = mc_command.split_command(subprocess.list2cmdline(command)) | ||
| 62 | result = mc_command.run(args, capture_output=True, check=True, text=True) | ||
| 63 | self.assertEqual(json.loads(result.stdout), want) | ||
| 64 | |||
| 43 | def test_windows_quoted_option_value_keeps_spaces_and_backslashes(self) -> None: | 65 | def test_windows_quoted_option_value_keeps_spaces_and_backslashes(self) -> None: |
| 44 | executable = r"C:\Program Files\LLVM\bin\llvm-mc.exe" | 66 | executable = r"C:\Program Files\LLVM\bin\llvm-mc.exe" |
| 45 | output = r"C:\shader builds\listing.s" | 67 | output = r"C:\shader builds\listing.s" |