|
1 | 1 | """The E2E helper selects payloads from the effective mcpp registry.""" |
2 | 2 | import os |
3 | 3 | from pathlib import Path |
| 4 | +import shutil |
4 | 5 | import subprocess |
5 | 6 | import tempfile |
6 | 7 | import unittest |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 | class ToolchainRegistry(unittest.TestCase): |
| 13 | + def test_real_gcc_compiles_after_helper_without_losing_user_prefix(self): |
| 14 | + compiler = os.environ.get('MCPP_E2E_GCC_DRIVER') or shutil.which('g++') |
| 15 | + if not compiler: |
| 16 | + self.skipTest('a real GCC C++ driver is unavailable') |
| 17 | + version = subprocess.run([compiler, '--version'], capture_output=True, text=True, check=True) |
| 18 | + if 'clang' in version.stdout.lower(): |
| 19 | + self.skipTest('g++ is a Clang alias') |
| 20 | + with tempfile.TemporaryDirectory() as directory: |
| 21 | + root = Path(directory) |
| 22 | + source = root / 'probe.cpp' |
| 23 | + source.write_text('int answer() { return 42; }\n') |
| 24 | + env = dict(os.environ, MCPP_HOME=str(root / 'cold-home')) |
| 25 | + env.pop('GCC_ROOT', None) |
| 26 | + args = [compiler, '-c', str(source), '-o', str(root / 'probe.o')] |
| 27 | + clean = subprocess.run(args, env=env, capture_output=True, text=True) |
| 28 | + self.assertEqual(clean.returncode, 0, clean.stderr) |
| 29 | + # A nonexistent explicit compiler prefix reproduces the exact |
| 30 | + # missing-cc1plus failure from the isolated Windows fixture. |
| 31 | + bad_env = dict(env, GCC_ROOT=str(root / 'missing-gcc-root')) |
| 32 | + bad = subprocess.run(args, env=bad_env, capture_output=True, text=True) |
| 33 | + self.assertNotEqual(bad.returncode, 0) |
| 34 | + self.assertIn('cc1plus', bad.stderr) |
| 35 | + for context, expected in ((env, 0), (bad_env, bad.returncode)): |
| 36 | + after = subprocess.run( |
| 37 | + ['bash', '-c', 'source "$1"; shift; "$@"', 'bash', str(HELPER), *args], |
| 38 | + env=context, capture_output=True, text=True) |
| 39 | + self.assertEqual(after.returncode, expected, after.stderr) |
| 40 | + |
| 41 | + def test_fixture_paths_do_not_change_gcc_child_process_prefix(self): |
| 42 | + # GCC interprets GCC_ROOT itself; exporting a fixture registry root |
| 43 | + # makes a cold MinGW driver search another installation for cc1plus. |
| 44 | + for existing in (None, '/explicit/compiler/root'): |
| 45 | + with self.subTest(existing=existing), tempfile.TemporaryDirectory() as directory: |
| 46 | + env = dict(os.environ, MCPP_HOME=directory) |
| 47 | + env.pop('GCC_ROOT', None) |
| 48 | + if existing is not None: |
| 49 | + env['GCC_ROOT'] = existing |
| 50 | + result = subprocess.run( |
| 51 | + ['bash', '-c', 'source "$1"; bash -c \'printf "%s" "${GCC_ROOT-unset}"\'', |
| 52 | + 'bash', str(HELPER)], env=env, capture_output=True, text=True, check=True) |
| 53 | + self.assertEqual(result.stdout, existing if existing is not None else 'unset') |
| 54 | + |
12 | 55 | def test_explicit_home_outranks_home_and_userprofile(self): |
13 | 56 | with tempfile.TemporaryDirectory() as directory: |
14 | 57 | root = Path(directory) |
|
0 commit comments