Add googletest wrap file
With this, unit tests can be run in a standalone session.
Tested:
Standalone tests work:
```
1/4 test_systemd_parser OK 0.01s
2/4 test_systemd_signal OK 0.01s
3/4 test_hypervisor_state OK 0.01s
4/4 test_scheduled_host_transition OK 0.01s
Ok: 4
Expected Fail: 0
Fail: 0
Unexpected Pass: 0
Skipped: 0
Timeout: 0
```
Change-Id: I434320257498a891af5f15835fdee9927e7d5aee
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/meson.build b/meson.build
index ac253b4..d51a86f 100644
--- a/meson.build
+++ b/meson.build
@@ -278,13 +278,28 @@
# If test coverage of source files within the root directory are wanted,
# need to define and build the tests from here
if build_tests.allowed()
- gtest = dependency(
- 'gtest',
- main: true,
- disabler: true,
- required: build_tests,
- )
- gmock = dependency('gmock', disabler: true, required: build_tests)
+ gtest = dependency('gtest', main: true, disabler: true, required: false)
+ gmock = dependency('gmock', disabler: true, required: false)
+
+ if not gtest.found() or not gmock.found()
+ gtest_proj = import('cmake').subproject('googletest', required: false)
+ if gtest_proj.found()
+ gtest = declare_dependency(
+ dependencies: [
+ dependency('threads'),
+ gtest_proj.dependency('gtest'),
+ gtest_proj.dependency('gtest_main'),
+ ],
+ )
+ gmock = gtest_proj.dependency('gmock')
+ else
+ assert(
+ not get_option('tests').enabled(),
+ 'Googletest is required if tests are enabled',
+ )
+ endif
+ endif
+
test(
'test_systemd_parser',
executable(