mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:28:38 +00:00
On a non-English Windows (Spanish here), PowerShell writes stderr in the console code page. text=True decodes with the locale encoding, the reader thread raises UnicodeDecodeError, result.stderr is None and all five subtests fail with a TypeError. Decode as UTF-8 with replacement; the strings the test looks for are ASCII. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "build_llvm_mc.ps1"
|
|
|
|
|
|
@unittest.skipUnless(os.name == "nt", "Windows LLVM installer")
|
|
class InstallDestinationTest(unittest.TestCase):
|
|
def test_cleanup_boundary_before_build(self):
|
|
cases = [
|
|
("work", False, True),
|
|
("WORK/bin", False, True),
|
|
("other/../work/bin", False, True),
|
|
("work-installed", False, False),
|
|
("work/bin", True, False),
|
|
]
|
|
with tempfile.TemporaryDirectory() as cwd:
|
|
for dest, keep, rejected in cases:
|
|
with self.subTest(dest=dest, keep=keep):
|
|
cmd = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass",
|
|
"-File", str(SCRIPT), "-Temp", "work", "-Dest", dest, "-NoEnv"]
|
|
if keep:
|
|
cmd.append("-Keep")
|
|
# An accepted path reaches the prerequisite check. Stop there.
|
|
result = subprocess.run(cmd, cwd=cwd, env={**os.environ, "PATH": ""},
|
|
capture_output=True, text=True,
|
|
encoding="utf-8", errors="replace") # localized PowerShell output is not UTF-8
|
|
self.assertNotEqual(result.returncode, 0)
|
|
expected = "Cleanup would delete" if rejected else "git wasn't found"
|
|
self.assertIn(expected, result.stderr)
|
|
self.assertEqual(list(Path(cwd).iterdir()), [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|