|
1 | 1 | """Tests for distutils.sysconfig.""" |
2 | 2 | import os |
3 | 3 | import shutil |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | +import textwrap |
4 | 7 | import unittest |
5 | 8 |
|
6 | 9 | from distutils import sysconfig |
@@ -174,6 +177,25 @@ def test_SO_in_vars(self): |
174 | 177 | self.assertIsNotNone(vars['SO']) |
175 | 178 | self.assertEqual(vars['SO'], vars['EXT_SUFFIX']) |
176 | 179 |
|
| 180 | + def test_customize_compiler_before_get_config_vars(self): |
| 181 | + # Issue #21923: test that a Distribution compiler |
| 182 | + # instance can be called without an explicit call to |
| 183 | + # get_config_vars(). |
| 184 | + with open(TESTFN, 'w') as f: |
| 185 | + f.writelines(textwrap.dedent('''\ |
| 186 | + from distutils.core import Distribution |
| 187 | + config = Distribution().get_command_obj('config') |
| 188 | + # try_compile may pass or it may fail if no compiler |
| 189 | + # is found but it should not raise an exception. |
| 190 | + rc = config.try_compile('int x;') |
| 191 | + ''')) |
| 192 | + p = subprocess.Popen([str(sys.executable), TESTFN], |
| 193 | + stdout=subprocess.PIPE, |
| 194 | + stderr=subprocess.STDOUT, |
| 195 | + universal_newlines=True) |
| 196 | + outs, errs = p.communicate() |
| 197 | + self.assertEqual(0, p.returncode, "Subprocess failed: " + outs) |
| 198 | + |
177 | 199 |
|
178 | 200 | def test_suite(): |
179 | 201 | suite = unittest.TestSuite() |
|
0 commit comments