summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-05-29 09:28:37 -0700
committerEli Schwartz <eschwartz93@gmail.com>2025-06-05 16:20:44 -0400
commit75f79fc234437ee5f95686432619397e936bcd92 (patch)
tree6fab1b669d7d254f0a1ef744ad3fa9d090c1e70e
parentf4918374d972e4680ea46ee00796d8fec21a6adf (diff)
downloadmeson-75f79fc234437ee5f95686432619397e936bcd92.tar.gz
unittests: Handle missing compiler support in test_compiler_detection
This wraps all of the compiler detections in this test case in try/except blocks. These blocks will return a skipTest for Python >= 3.11 (where subTest and skipTest interact correctly), and continue if they do not. For Meson CI runs they will fail the specific subtest, which is also an improvement as it can help pinpoint exactly which subtest failed. Fixes: #14579
-rw-r--r--unittests/allplatformstests.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index bc4c72e4f..c441b3982 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -1100,12 +1100,21 @@ class AllPlatformTests(BasePlatformTests):
# Detect with evar and do sanity checks on that
if evar in os.environ:
with self.subTest(lang=lang, evar=evar):
- ecc = compiler_from_language(env, lang, MachineChoice.HOST)
+ try:
+ ecc = compiler_from_language(env, lang, MachineChoice.HOST)
+ except EnvironmentException:
+ # always raise in ci, we expect to have a valid ObjC and ObjC++ compiler of some kind
+ if is_ci():
+ self.fail(f'Could not find a compiler for {lang}')
+ if sys.version_info < (3, 11):
+ continue
+ self.skipTest(f'No valid compiler for {lang}.')
+ finally:
+ # Pop it so we don't use it for the next detection
+ evalue = os.environ.pop(evar)
assert ecc is not None, "Something went really wrong"
self.assertTrue(ecc.version)
elinker = detect_static_linker(env, ecc)
- # Pop it so we don't use it for the next detection
- evalue = os.environ.pop(evar)
# Very rough/strict heuristics. Would never work for actual
# compiler detection, but should be ok for the tests.
ebase = os.path.basename(evalue)
@@ -1131,7 +1140,15 @@ class AllPlatformTests(BasePlatformTests):
# Do auto-detection of compiler based on platform, PATH, etc.
with self.subTest(lang=lang):
- cc = compiler_from_language(env, lang, MachineChoice.HOST)
+ try:
+ cc = compiler_from_language(env, lang, MachineChoice.HOST)
+ except EnvironmentException:
+ # always raise in ci, we expect to have a valid ObjC and ObjC++ compiler of some kind
+ if is_ci():
+ self.fail(f'Could not find a compiler for {lang}')
+ if sys.version_info < (3, 11):
+ continue
+ self.skipTest(f'No valid compiler for {lang}.')
assert cc is not None, "Something went really wrong"
self.assertTrue(cc.version)
linker = detect_static_linker(env, cc)
@@ -1196,7 +1213,15 @@ class AllPlatformTests(BasePlatformTests):
# Need a new env to re-run environment loading
env = get_fake_env(testdir, self.builddir, self.prefix)
- wcc = compiler_from_language(env, lang, MachineChoice.HOST)
+ try:
+ wcc = compiler_from_language(env, lang, MachineChoice.HOST)
+ except EnvironmentException:
+ # always raise in ci, we expect to have a valid ObjC and ObjC++ compiler of some kind
+ if is_ci():
+ self.fail(f'Could not find a compiler for {lang}')
+ if sys.version_info < (3, 11):
+ continue
+ self.skipTest(f'No valid compiler for {lang}.')
wlinker = detect_static_linker(env, wcc)
del os.environ['AR']