gtest: Add a testcase wrapper for handling tmpdirs
This makes it trivial to have a pristine temp directory on every test
case execution. Just derive from the provided class.
Change-Id: I5355914cdedc482eddd0749a9ccc10fc93de6571
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/meson.build b/test/meson.build
index 0317121..1f284a5 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,25 +1,3 @@
-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_opts = import('cmake').subproject_options()
- gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
- gtest_proj = import('cmake').subproject(
- 'googletest',
- options: gtest_opts,
- 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 build_tests.enabled(), 'Googletest is required')
- endif
-endif
-
gtests = [
'cancel',
'exception',
@@ -31,8 +9,8 @@
gtest_deps = [
stdplus_dep,
- gtest,
- gmock,
+ gtest_main_dep,
+ gmock_dep,
]
if has_dl
@@ -83,12 +61,31 @@
warning('Not testing io_uring feature')
endif
-if gtest.found() and gmock.found()
+if has_gtest
+ gtests += [
+ 'gtest/tmp',
+ ]
+
+ gtest_deps += [
+ stdplus_gtest_dep,
+ ]
+elif build_tests.enabled()
+ error('Not testing gtest lib feature')
+else
+ warning('Not testing gtest lib feature')
+endif
+
+if gtest_dep.found() and gmock_dep.found()
foreach t : gtests
- test(t, executable(t.underscorify(), t + '.cpp',
- build_by_default: false,
- implicit_include_directories: false,
- dependencies: gtest_deps))
+ test(
+ t,
+ files('run_with_tmp.sh'),
+ env: {'TMPTMPL': 'stdplus-test.XXXXXXXXXX'},
+ args: executable(
+ t.underscorify(), t + '.cpp',
+ build_by_default: false,
+ implicit_include_directories: false,
+ dependencies: gtest_deps))
endforeach
endif