Skip to content

Commit 80fc384

Browse files
committed
[#3732] Meson: Add gtest.cc compiler check to detect crashes
1 parent 53342bf commit 80fc384

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

compiler-checks/gtest.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <gtest/gtest.h>
2+
3+
// musl's mallocng memory allocator stupidly crash for test names that are
4+
// lengthier than 16 characters. Hence the long test name.
5+
TEST(Fixture, testWithLongLongLongName) {
6+
EXPECT_LT(1, 2);
7+
}
8+
9+
int main() {
10+
testing::InitGoogleTest();
11+
return RUN_ALL_TESTS();
12+
}

meson.build

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,22 @@ if netconf_opt.enabled() and NETCONF_DEP.get_variable(
244244
error('Dependency not found: NETCONF.')
245245
endif
246246

247-
GTEST_DEP = dependency(
248-
'gtest',
249-
fallback: ['gtest', 'gtest_dep'],
250-
required: TESTS_OPT.enabled() or FUZZ_OPT.enabled(),
251-
)
247+
# Google Test
248+
GTEST_DEP = dependency('gtest', required: TESTS_OPT.enabled() or FUZZ_OPT.enabled())
249+
if GTEST_DEP.found()
250+
result = cpp.run(
251+
fs.read('compiler-checks/gtest.cc'),
252+
name: 'Check if a simple GTest test runs.',
253+
dependencies: [GTEST_DEP],
254+
)
255+
if result.returncode() != 0
256+
GTEST_DEP = disabler()
257+
gtest_subproject = subproject('gtest', required: false)
258+
if gtest_subproject.found()
259+
GTEST_DEP = gtest_subproject.get_variable('gtest_dep')
260+
endif
261+
endif
262+
endif
252263

253264
# Crypto
254265
if crypto_opt == 'botan'

0 commit comments

Comments
 (0)