unittests: move get_convincing_fake_env_and_cc to run_tests.py

pull/9989/head
Marvin Scholz 3 years ago
parent 9e597ce905
commit 34ea8fdf98
  1. 13
      run_tests.py
  2. 17
      unittests/allplatformstests.py

@ -40,7 +40,7 @@ from mesonbuild import mesonlib
from mesonbuild import mesonmain from mesonbuild import mesonmain
from mesonbuild import mtest from mesonbuild import mtest
from mesonbuild import mlog from mesonbuild import mlog
from mesonbuild.environment import Environment, detect_ninja from mesonbuild.environment import Environment, detect_ninja, detect_machine_info
from mesonbuild.coredata import backendlist, version as meson_version from mesonbuild.coredata import backendlist, version as meson_version
from mesonbuild.mesonlib import OptionKey, setup_vsenv from mesonbuild.mesonlib import OptionKey, setup_vsenv
@ -153,6 +153,17 @@ def get_fake_env(sdir='', bdir=None, prefix='', opts=None):
env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library
return env return env
def get_convincing_fake_env_and_cc(bdir, prefix):
'''
Return a fake env and C compiler with the fake env
machine info properly detected using that compiler.
Useful for running compiler checks in the unit tests.
'''
env = get_fake_env('', bdir, prefix)
cc = compilers.detect_c_compiler(env, mesonlib.MachineChoice.HOST)
# Detect machine info
env.machines.host = detect_machine_info({'c':cc})
return (env, cc)
Backend = Enum('Backend', 'ninja vs xcode') Backend = Enum('Backend', 'ninja vs xcode')

@ -60,7 +60,7 @@ from mesonbuild.scripts import destdir_join
from mesonbuild.wrap.wrap import PackageDefinition, WrapException from mesonbuild.wrap.wrap import PackageDefinition, WrapException
from run_tests import ( from run_tests import (
Backend, exe_suffix, get_fake_env Backend, exe_suffix, get_fake_env, get_convincing_fake_env_and_cc
) )
from .baseplatformtests import BasePlatformTests from .baseplatformtests import BasePlatformTests
@ -1546,23 +1546,12 @@ class AllPlatformTests(BasePlatformTests):
self.build() self.build()
self.run_tests() self.run_tests()
def get_convincing_fake_env_and_cc(self) -> None:
'''
Return a fake env and C compiler with the fake env
machine info properly detected using that compiler.
'''
env = get_fake_env('', self.builddir, self.prefix)
cc = detect_c_compiler(env, MachineChoice.HOST)
# Detect machine info
env.machines.host = mesonbuild.environment.detect_machine_info({'c':cc})
return (env, cc)
def test_underscore_prefix_detection_list(self) -> None: def test_underscore_prefix_detection_list(self) -> None:
''' '''
Test the underscore detection hardcoded lookup list Test the underscore detection hardcoded lookup list
against what was detected in the binary. against what was detected in the binary.
''' '''
env, cc = self.get_convincing_fake_env_and_cc() env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix)
expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env)
list_uscore = cc._symbols_have_underscore_prefix_list(env) list_uscore = cc._symbols_have_underscore_prefix_list(env)
if list_uscore is not None: if list_uscore is not None:
@ -1575,7 +1564,7 @@ class AllPlatformTests(BasePlatformTests):
Test the underscore detection based on compiler-defined preprocessor macro Test the underscore detection based on compiler-defined preprocessor macro
against what was detected in the binary. against what was detected in the binary.
''' '''
env, cc = self.get_convincing_fake_env_and_cc() env, cc = get_convincing_fake_env_and_cc(self.builddir, self.prefix)
expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env) expected_uscore = cc._symbols_have_underscore_prefix_searchbin(env)
define_uscore = cc._symbols_have_underscore_prefix_define(env) define_uscore = cc._symbols_have_underscore_prefix_define(env)
if define_uscore is not None: if define_uscore is not None:

Loading…
Cancel
Save