|
11 | 11 | from pathlib import Path |
12 | 12 |
|
13 | 13 | from gyp.generator import ninja |
| 14 | +from gyp.MSVSVersion import SelectVisualStudioVersion |
| 15 | + |
| 16 | + |
| 17 | +def _has_visual_studio(): |
| 18 | + """Check if Visual Studio can be detected by gyp's registry-based detection.""" |
| 19 | + if not sys.platform.startswith("win"): |
| 20 | + return False |
| 21 | + try: |
| 22 | + SelectVisualStudioVersion("auto", allow_fallback=False) |
| 23 | + return True |
| 24 | + except ValueError: |
| 25 | + return False |
14 | 26 |
|
15 | 27 |
|
16 | 28 | class TestPrefixesAndSuffixes(unittest.TestCase): |
| 29 | + @unittest.skipUnless( |
| 30 | + _has_visual_studio(), |
| 31 | + "requires Windows with a Visual Studio installation detected via the registry", |
| 32 | + ) |
17 | 33 | def test_BinaryNamesWindows(self): |
18 | | - # These cannot run on non-Windows as they require a VS installation to |
19 | | - # correctly handle variable expansion. |
20 | | - if sys.platform.startswith("win"): |
21 | | - writer = ninja.NinjaWriter( |
22 | | - "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win" |
23 | | - ) |
24 | | - spec = {"target_name": "wee"} |
25 | | - self.assertTrue( |
26 | | - writer.ComputeOutputFileName(spec, "executable").endswith(".exe") |
27 | | - ) |
28 | | - self.assertTrue( |
29 | | - writer.ComputeOutputFileName(spec, "shared_library").endswith(".dll") |
30 | | - ) |
31 | | - self.assertTrue( |
32 | | - writer.ComputeOutputFileName(spec, "static_library").endswith(".lib") |
33 | | - ) |
| 34 | + writer = ninja.NinjaWriter( |
| 35 | + "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win" |
| 36 | + ) |
| 37 | + spec = {"target_name": "wee"} |
| 38 | + for key, ext in { |
| 39 | + "executable": ".exe", |
| 40 | + "shared_library": ".dll", |
| 41 | + "static_library": ".lib", |
| 42 | + }: |
| 43 | + self.assertTrue(writer.ComputeOutputFileName(spec, key).endswith(ext)) |
34 | 44 |
|
35 | 45 | def test_BinaryNamesLinux(self): |
36 | 46 | writer = ninja.NinjaWriter( |
|
0 commit comments