diff options
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index fd75c8c9c..1eba4dfd6 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5634,6 +5634,28 @@ class AllPlatformTests(BasePlatformTests): matches += 1 self.assertEqual(matches, 1) + def test_env_flags_to_linker(self) -> None: + # Compilers that act as drivers should add their compiler flags to the + # linker, those that do not shouldn't + with mock.patch.dict(os.environ, {'CFLAGS': '-DCFLAG', 'LDFLAGS': '-flto'}): + env = get_fake_env() + + # Get the compiler so we know which compiler class to mock. + cc = env.detect_compiler_for('c', MachineChoice.HOST) + cc_type = type(cc) + + # Test a compiler that acts as a linker + with mock.patch.object(cc_type, 'INVOKES_LINKER', True): + cc = env.detect_compiler_for('c', MachineChoice.HOST) + link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language) + self.assertEqual(sorted(link_args), sorted(['-DCFLAG', '-flto'])) + + # And one that doesn't + with mock.patch.object(cc_type, 'INVOKES_LINKER', False): + cc = env.detect_compiler_for('c', MachineChoice.HOST) + link_args = env.coredata.get_external_link_args(cc.for_machine, cc.language) + self.assertEqual(sorted(link_args), sorted(['-flto'])) + class FailureTests(BasePlatformTests): ''' Tests that test failure conditions. Build files here should be dynamically |