Skip to content

Commit

Permalink
unittests: move get_convincing_fake_env_and_cc to run_tests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ePirat committed Mar 31, 2022
1 parent 9e597ce commit 34ea8fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
13 changes: 12 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from mesonbuild import mesonmain
from mesonbuild import mtest
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.mesonlib import OptionKey, setup_vsenv

Expand Down Expand Up @@ -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
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')

Expand Down
17 changes: 3 additions & 14 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from mesonbuild.wrap.wrap import PackageDefinition, WrapException

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
Expand Down Expand Up @@ -1546,23 +1546,12 @@ def test_prebuilt_shared_lib_rpath(self) -> None:
self.build()
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:
'''
Test the underscore detection hardcoded lookup list
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)
list_uscore = cc._symbols_have_underscore_prefix_list(env)
if list_uscore is not None:
Expand All @@ -1575,7 +1564,7 @@ def test_underscore_prefix_detection_define(self) -> None:
Test the underscore detection based on compiler-defined preprocessor macro
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)
define_uscore = cc._symbols_have_underscore_prefix_define(env)
if define_uscore is not None:
Expand Down

0 comments on commit 34ea8fd

Please sign in to comment.