test: Add initial support for catch2
This will be used by future test cases in place of googletest.
Change-Id: I41bf1d4f85ebffd1353e6d33a8eaee49803cb254
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/subprojects/Catch2.wrap b/subprojects/Catch2.wrap
new file mode 100644
index 0000000..ea8939c
--- /dev/null
+++ b/subprojects/Catch2.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/catchorg/Catch2
+revision = v2.11.1
diff --git a/test/catch2_main.cpp b/test/catch2_main.cpp
new file mode 100644
index 0000000..4ed06df
--- /dev/null
+++ b/test/catch2_main.cpp
@@ -0,0 +1,2 @@
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch.hpp>
diff --git a/test/meson.build b/test/meson.build
index 4f77a56..a748b70 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -15,7 +15,7 @@
endif
endif
-tests = [
+gtests = [
'signal',
'handle/copyable',
'handle/managed',
@@ -23,8 +23,49 @@
'util/string',
]
-foreach t : tests
+foreach t : gtests
test(t, executable(t.underscorify(), t + '.cpp',
implicit_include_directories: false,
dependencies: [stdplus, gtest, gmock]))
endforeach
+
+# catch2 might not have a pkg-config. It is header only so just make
+# sure we can access the needed symbols from the header.
+catch2_dep = dependency('Catch2', required: false)
+has_catch2 = meson.get_compiler('cpp').has_header_symbol(
+ 'catch2/catch.hpp',
+ 'Approx',
+ dependencies: catch2_dep,
+ required: false)
+if not has_catch2
+ catch2_proj = import('cmake').subproject(
+ 'Catch2',
+ cmake_options: [
+ '-DBUILD_TESTING=OFF'
+ ],
+ required: false)
+ if catch2_proj.found()
+ catch2_dep = catch2_proj.dependency('Catch2')
+ has_catch2 = true
+ else
+ assert(not build_tests.enabled(), 'Catch2 is required')
+ endif
+endif
+
+catch2_tests = [
+]
+
+if has_catch2
+ libcatch2 = static_library(
+ 'catch2', 'catch2_main.cpp',
+ implicit_include_directories: false,
+ build_by_default: false,
+ dependencies: catch2_dep)
+
+ foreach t : catch2_tests
+ test(t, executable(t.underscorify(), t + '.cpp',
+ implicit_include_directories: false,
+ link_with: libcatch2,
+ dependencies: [stdplus, catch2_dep]))
+ endforeach
+endif