| | @@ -0,0 +1,104 @@ |
| 1 | +추가: import os |
| 2 | +추가: from pathlib import Path |
| 3 | +추가: import shutil |
| 4 | +추가: import subprocess |
| 5 | +추가: import tempfile |
| 6 | +추가: import unittest |
| 7 | +추가: |
| 8 | +추가: ROOT = Path(__file__).resolve().parents[2] |
| 9 | +추가: |
| 10 | +추가: |
| 11 | +추가: class IconBuildTests(unittest.TestCase): |
| 12 | +추가: @classmethod |
| 13 | +추가: def setUpClass(cls): |
| 14 | +추가: cls.scratch = tempfile.TemporaryDirectory(dir=ROOT / "tests/work") |
| 15 | +추가: cls.addClassCleanup(cls.scratch.cleanup) |
| 16 | +추가: cls.root = Path(cls.scratch.name) |
| 17 | +추가: cls.builder = cls.root / "build.exe" |
| 18 | +추가: cls.compiler = cls.root / "fake-rc.exe" |
| 19 | +추가: fake = cls.root / "fake.rs" |
| 20 | +추가: fake.write_text('''fn main() { |
| 21 | +추가: if std::env::var_os("FAKE_RC_FAIL").is_some() { |
| 22 | +추가: std::process::exit(1); |
| 23 | +추가: } |
| 24 | +추가: let output = std::env::args().find_map(|arg| arg.strip_prefix("/fo").map(str::to_owned)).unwrap(); |
| 25 | +추가: std::fs::write(output, std::env::current_exe().unwrap().to_string_lossy().as_bytes()).unwrap(); |
| 26 | +추가: } |
| 27 | +추가: ''') |
| 28 | +추가: for source, output in ((ROOT / "experiments/rust-ui-memory-app/build.rs", cls.builder), |
| 29 | +추가: (fake, cls.compiler)): |
| 30 | +추가: subprocess.run(["rustc", "+1.99.1", "--edition=2024", str(source), "-o", str(output)], |
| 31 | +추가: check=True, capture_output=True, text=True) |
| 32 | +추가: |
| 33 | +추가: def setUp(self): |
| 34 | +추가: self.directory = tempfile.TemporaryDirectory(dir=self.root) |
| 35 | +추가: self.addCleanup(self.directory.cleanup) |
| 36 | +추가: self.work = Path(self.directory.name) |
| 37 | +추가: self.output = self.work / "out" |
| 38 | +추가: self.output.mkdir() |
| 39 | +추가: self.programs = self.work / "Program Files (x86)" |
| 40 | +추가: |
| 41 | +추가: def sdk(self, version): |
| 42 | +추가: path = self.programs / "Windows Kits/10/bin" / version / "x64/rc.exe" |
| 43 | +추가: path.parent.mkdir(parents=True) |
| 44 | +추가: shutil.copy2(self.compiler, path) |
| 45 | +추가: return path |
| 46 | +추가: |
| 47 | +추가: def run_build(self, target="msvc", **overrides): |
| 48 | +추가: environment = dict(os.environ) |
| 49 | +추가: for key in ("RC", "ProgramFiles", "ProgramFiles(x86)", "FAKE_RC_FAIL"): |
| 50 | +추가: environment.pop(key, None) |
| 51 | +추가: environment.update({"CARGO_CFG_TARGET_OS": "windows", "CARGO_CFG_TARGET_ENV": target, |
| 52 | +추가: "CARGO_FEATURE_UI": "1", "OUT_DIR": str(self.output), |
| 53 | +추가: "CARGO_MANIFEST_DIR": str(ROOT / "experiments/rust-ui-memory-app"), |
| 54 | +추가: "ProgramFiles(x86)": str(self.programs), "PATH": ""}) |
| 55 | +추가: environment.update(overrides) |
| 56 | +추가: return subprocess.run([str(self.builder)], env=environment, capture_output=True, text=True) |
| 57 | +추가: |
| 58 | +추가: def test_sdk_uses_highest_numeric_version_with_x64_compiler(self): |
| 59 | +추가: self.sdk("10.0.9.0") |
| 60 | +추가: latest = self.sdk("10.0.10.0") |
| 61 | +추가: (self.programs / "Windows Kits/10/bin/10.0.99.0/x64").mkdir(parents=True) |
| 62 | +추가: result = self.run_build() |
| 63 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 64 | +추가: self.assertIn("cargo:rustc-link-arg-bin=", result.stdout) |
| 65 | +추가: self.assertEqual((self.output / "zipelo.res").read_text(), str(latest)) |
| 66 | +추가: |
| 67 | +추가: def test_explicit_rc_overrides_sdk(self): |
| 68 | +추가: self.sdk("10.0.99.0") |
| 69 | +추가: result = self.run_build(RC=str(self.compiler)) |
| 70 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 71 | +추가: self.assertEqual((self.output / "zipelo.res").read_text(), str(self.compiler)) |
| 72 | +추가: |
| 73 | +추가: def test_path_compiler_remains_available_without_sdk(self): |
| 74 | +추가: path = self.work / "bin/rc.exe" |
| 75 | +추가: path.parent.mkdir() |
| 76 | +추가: shutil.copy2(self.compiler, path) |
| 77 | +추가: result = self.run_build(PATH=str(path.parent)) |
| 78 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 79 | +추가: self.assertEqual((self.output / "zipelo.res").read_text(), str(path)) |
| 80 | +추가: |
| 81 | +추가: def test_missing_msvc_compiler_warns_without_linking(self): |
| 82 | +추가: result = self.run_build() |
| 83 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 84 | +추가: self.assertIn("cargo:warning=아이콘 없이 빌드", result.stdout) |
| 85 | +추가: self.assertNotIn("cargo:rustc-link-arg-bin=", result.stdout) |
| 86 | +추가: self.assertFalse((self.output / "zipelo.res").exists()) |
| 87 | +추가: |
| 88 | +추가: def test_msvc_compiler_failure_warns_without_linking(self): |
| 89 | +추가: result = self.run_build(RC=str(self.compiler), FAKE_RC_FAIL="1") |
| 90 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 91 | +추가: self.assertIn("cargo:warning=아이콘 없이 빌드", result.stdout) |
| 92 | +추가: self.assertNotIn("cargo:rustc-link-arg-bin=", result.stdout) |
| 93 | +추가: |
| 94 | +추가: def test_invalid_explicit_rc_does_not_fall_back_to_sdk(self): |
| 95 | +추가: self.sdk("10.0.99.0") |
| 96 | +추가: result = self.run_build(RC=str(self.work / "missing.exe")) |
| 97 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 98 | +추가: self.assertIn("cargo:warning=아이콘 없이 빌드", result.stdout) |
| 99 | +추가: self.assertNotIn("cargo:rustc-link-arg-bin=", result.stdout) |
| 100 | +추가: |
| 101 | +추가: def test_missing_gnu_compiler_remains_a_build_failure(self): |
| 102 | +추가: result = self.run_build(target="gnu", RC=str(self.work / "missing.exe")) |
| 103 | +추가: self.assertNotEqual(result.returncode, 0) |
| 104 | +추가: self.assertNotIn("cargo:warning=아이콘 없이 빌드", result.stdout) |