Skip to content

Commit 7ff22f5

Browse files
authored
Merge pull request swiftlang#25266 from drodriguez/windows-fix-python-tests
[windows] Fix Python tests in Windows.
2 parents defd518 + 3fb9a2a commit 7ff22f5

File tree

13 files changed

+110
-23
lines changed

13 files changed

+110
-23
lines changed

test/lit.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@ if run_vendor == 'apple':
895895

896896
elif run_os in ['windows-msvc']:
897897
lit_config.note('Testing Windows ' + config.variant_triple)
898+
config.environment['NUMBER_OF_PROCESSORS'] = os.environ['NUMBER_OF_PROCESSORS']
899+
if 'PROCESSOR_ARCHITEW6432' in os.environ:
900+
config.environment['PROCESSOR_ARCHITEW6432'] = os.environ['PROCESSOR_ARCHITEW6432']
901+
if 'PROCESSOR_ARCHITECTURE' in os.environ:
902+
config.environment['PROCESSOR_ARCHITECTURE'] = os.environ['PROCESSOR_ARCHITECTURE']
903+
if 'PROCESSOR_IDENTIFIER' in os.environ:
904+
config.environment['PROCESSOR_IDENTIFIER'] = os.environ['PROCESSOR_IDENTIFIER']
905+
config.environment['PYTHON_EXECUTABLE'] = sys.executable
898906
config.target_object_format = 'coff'
899907
config.target_shared_library_prefix = ''
900908
config.target_shared_library_suffix = '.dll'

utils/build_swift/tests/argparse/test_types.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
import os.path
11+
import platform
1112

1213
from ..utils import TestCase
1314
from ...argparse import ArgumentTypeError, types
@@ -139,13 +140,16 @@ def test_expands_path(self):
139140
path_type = types.PathType()
140141

141142
path = path_type('/some/random/path/../')
142-
self.assertEqual('/some/random', path)
143+
self.assertEqual(self._platform_path('/some/random'), path)
143144

144145
path = path_type('~/path/to/some/file.txt')
145-
self.assertEqual(self.home_dir + '/path/to/some/file.txt', path)
146+
self.assertEqual(
147+
self._platform_path(self.home_dir + '/path/to/some/file.txt'),
148+
path)
146149

147150
path = path_type('~/path/to/some/../file.txt')
148-
self.assertEqual(self.home_dir + '/path/to/file.txt', path)
151+
self.assertEqual(
152+
self._platform_path(self.home_dir + '/path/to/file.txt'), path)
149153

150154
def test_assert_exists(self):
151155
path_type = types.PathType(assert_exists=True)
@@ -155,9 +159,14 @@ def test_assert_exists(self):
155159

156160
with self.assertRaises(ArgumentTypeError):
157161
path_type('/nonsensisal/path/')
162+
163+
with self.assertRaises(ArgumentTypeError):
158164
path_type('~/not-a-real/path to a file')
159165

160166
def test_assert_executable(self):
167+
if platform.system() == 'Windows':
168+
self.skipTest("All files are considered executable in Windows")
169+
161170
path_type = types.PathType(assert_executable=True)
162171

163172
bash_path = '/bin/bash'
@@ -168,6 +177,12 @@ def test_assert_executable(self):
168177
with self.assertRaises(ArgumentTypeError):
169178
path_type(__file__)
170179

180+
def _platform_path(self, path):
181+
if platform.system() == 'Windows':
182+
return os.path.abspath(os.path.normpath(path))
183+
else:
184+
return path
185+
171186

172187
class TestRegexType(TestCase):
173188

utils/build_swift/tests/test_driver_arguments.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
import os
11+
import platform
1112
import sys
1213
import unittest
1314
from contextlib import contextmanager
@@ -344,7 +345,10 @@ def generate_option_test(cls, option):
344345
def generate_preset_test(cls, preset_name, preset_args):
345346
def test(self):
346347
try:
347-
self.parse_default_args(preset_args, check_impl_args=True)
348+
# Windows cannot run build-script-impl to check the impl args.
349+
is_windows = platform.system() == 'Windows'
350+
self.parse_default_args(preset_args,
351+
check_impl_args=not is_windows)
348352
except ParserError as e:
349353
self.fail('failed to parse preset "{}": {}'.format(
350354
preset_name, e))

utils/swift_build_support/swift_build_support/tar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def tar(source, destination):
2525
# - We wish to explicitly set the owner and group of the archive.
2626
args = ['tar', '-c', '-z', '-f', destination]
2727

28-
if platform.system() != 'Darwin':
28+
if platform.system() != 'Darwin' and platform.system() != 'Windows':
2929
args += ['--owner=0', '--group=0']
3030

3131
# Discard stderr output such as 'tar: Failed to open ...'. We'll detect

utils/swift_build_support/swift_build_support/which.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def which(cmd):
3535
been backported to Python 2.7, which we support.
3636
"""
3737
out = shell.capture(['which', cmd],
38-
dry_run=False, echo=False, optional=True)
38+
dry_run=False, echo=False,
39+
optional=True, stderr=shell.DEVNULL)
3940
if out is None:
4041
return None
4142
return out.rstrip()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ echo off
2+
IF NOT DEFINED PYTHON_EXECUTABLE SET PYTHON_EXECUTABLE=python
3+
"%PYTHON_EXECUTABLE%" "%~dp0\mock-distcc" %*

utils/swift_build_support/tests/products/test_ninja.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ def test_build(self):
119119
+ pushd {build_dir}
120120
+ {expect_env}{python} configure.py --bootstrap
121121
+ popd
122-
""".format(source_dir=self.workspace.source_dir('ninja'),
123-
build_dir=self.workspace.build_dir('build', 'ninja'),
122+
""".format(source_dir=self._platform_quote(
123+
self.workspace.source_dir('ninja')),
124+
build_dir=self._platform_quote(
125+
self.workspace.build_dir('build', 'ninja')),
124126
expect_env=expect_env,
125-
python=sys.executable))
127+
python=self._platform_quote(sys.executable)))
128+
129+
def _platform_quote(self, path):
130+
if platform.system() == 'Windows':
131+
return "'{}'".format(path)
132+
else:
133+
return path

utils/swift_build_support/tests/test_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import argparse
1414
import os
15+
import platform
1516
import sys
1617
import unittest
1718
try:
@@ -85,6 +86,9 @@ def test_clang_compiler_version(self):
8586
"1..2")
8687

8788
def test_executable(self):
89+
if platform.system() == 'Windows':
90+
self.skipTest('Every file is considered executable in Windows')
91+
8892
python = sys.executable
8993
self.assertTrue(os.path.isabs(argtype.executable(python)))
9094

utils/swift_build_support/tests/test_cmake.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010

1111
import os
12+
import platform
1213
import unittest
1314
from argparse import Namespace
1415

@@ -22,8 +23,11 @@ class CMakeTestCase(unittest.TestCase):
2223
def mock_distcc_path(self):
2324
"""Return a path string of mock distcc executable
2425
"""
25-
return os.path.join(os.path.dirname(__file__),
26-
'mock-distcc')
26+
if platform.system() == 'Windows':
27+
executable = 'mock-distcc.cmd'
28+
else:
29+
executable = 'mock-distcc'
30+
return os.path.join(os.path.dirname(__file__), executable)
2731

2832
def default_args(self):
2933
"""Return new args object with default values

utils/swift_build_support/tests/test_migration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import argparse
1212
import os
13+
import platform
1314
import unittest
1415

1516
from swift_build_support import migration
@@ -54,6 +55,10 @@ def test_no_unknown_args(self):
5455
build_script_impl_args=[]))
5556

5657
def test_check_impl_args(self):
58+
if platform.system() == 'Windows':
59+
self.skipTest("build-script-impl cannot run in Windows")
60+
return
61+
5762
# Assuming file locations:
5863
# utils/swift_build_support/tests/test_migration.py
5964
# utils/build-script-impl

0 commit comments

Comments
 (0)