blob: df694b6d5123608559adccb257a01dd1676bd885 [file] [log] [blame]
William A. Kennington IIIa2d67e22020-02-19 12:17:39 -08001gtest = dependency('gtest', main: true, disabler: true, required: false)
2gmock = dependency('gmock', disabler: true, required: false)
3if not gtest.found() or not gmock.found()
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -07004 gtest_opts = import('cmake').subproject_options()
5 gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
William A. Kennington III83af3fa2021-01-31 15:22:54 -08006 gtest_proj = import('cmake').subproject(
7 'googletest',
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -07008 options: gtest_opts,
William A. Kennington III83af3fa2021-01-31 15:22:54 -08009 required: false)
William A. Kennington IIIa2d67e22020-02-19 12:17:39 -080010 if gtest_proj.found()
11 gtest = declare_dependency(
12 dependencies: [
13 dependency('threads'),
14 gtest_proj.dependency('gtest'),
15 gtest_proj.dependency('gtest_main'),
16 ])
17 gmock = gtest_proj.dependency('gmock')
18 else
19 assert(not build_tests.enabled(), 'Googletest is required')
20 endif
21endif
William A. Kennington III15982f62019-01-31 14:43:41 -080022
William A. Kennington III245495e2020-02-13 13:07:30 -080023gtests = [
William A. Kennington IIIe847ef82018-11-02 17:29:15 -070024 'handle/copyable',
William A. Kennington III7a5e2322018-11-02 17:28:35 -070025 'handle/managed',
William A. Kennington IIIbff0b0f2018-11-16 19:56:10 -080026 'util/cexec',
William A. Kennington III4ef36e72019-06-27 12:48:59 -070027 'util/string',
William A. Kennington III15982f62019-01-31 14:43:41 -080028]
29
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070030if has_fd
31 gtests += [
32 'fd/dupable',
33 'fd/managed',
34 'fd/intf',
35 'fd/impl',
36 'fd/mock',
37 'fd/ops',
38 ]
William A. Kennington III45754242021-04-28 12:48:31 -070039elif build_tests.enabled()
40 error('Not testing file descriptor feature')
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070041else
42 warning('Not testing file descriptor feature')
43endif
44
William A. Kennington III83af3fa2021-01-31 15:22:54 -080045if gtest.found() and gmock.found()
46 foreach t : gtests
47 test(t, executable(t.underscorify(), t + '.cpp',
48 build_by_default: false,
49 implicit_include_directories: false,
William A. Kennington III3acf92b2021-04-16 13:33:50 -070050 dependencies: [stdplus_dep, gtest, gmock]))
William A. Kennington III83af3fa2021-01-31 15:22:54 -080051 endforeach
52endif
William A. Kennington III245495e2020-02-13 13:07:30 -080053
William A. Kennington III01db6622021-01-31 15:24:13 -080054# Switch to `catch2-with-main.pc` when 2.x supports it
55catch2 = dependency('catch2-with-main', required: false)
56if not catch2.found()
57 catch2 = dependency('catch2', required: false)
58 if catch2.found()
59 catch2_main = meson.get_compiler('cpp').find_library(
60 'Catch2WithMain', required: false)
61 if catch2_main.found()
62 catch2 = declare_dependency(
63 dependencies: [
64 catch2,
65 catch2_main,
66 ])
67 else
68 catch2 = declare_dependency(
69 link_with: static_library(
70 'catch2', 'catch2_main.cpp',
71 implicit_include_directories: false,
72 build_by_default: false,
73 dependencies: catch2),
74 dependencies: catch2)
75 endif
76 endif
77endif
78if not catch2.found()
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -070079 catch2_opts = import('cmake').subproject_options()
80 catch2_opts.add_cmake_defines({
81 'BUILD_TESTING': 'OFF',
82 'CMAKE_CXX_FLAGS': '-Wno-non-virtual-dtor',
83 })
William A. Kennington III245495e2020-02-13 13:07:30 -080084 catch2_proj = import('cmake').subproject(
85 'Catch2',
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -070086 options: catch2_opts,
William A. Kennington III245495e2020-02-13 13:07:30 -080087 required: false)
88 if catch2_proj.found()
William A. Kennington III01db6622021-01-31 15:24:13 -080089 catch2 = declare_dependency(
90 dependencies: [
91 catch2_proj.dependency('Catch2'),
92 catch2_proj.dependency('Catch2WithMain'),
93 ])
William A. Kennington III245495e2020-02-13 13:07:30 -080094 else
95 assert(not build_tests.enabled(), 'Catch2 is required')
96 endif
97endif
98
99catch2_tests = [
William A. Kennington III770c5562020-02-13 13:07:42 -0800100 'signal',
William A. Kennington IIIe0990382019-10-18 02:10:25 -0700101 'raw',
William A. Kennington III245495e2020-02-13 13:07:30 -0800102]
103
William A. Kennington III01db6622021-01-31 15:24:13 -0800104if catch2.found()
William A. Kennington III245495e2020-02-13 13:07:30 -0800105 foreach t : catch2_tests
106 test(t, executable(t.underscorify(), t + '.cpp',
William A. Kennington III31422352020-02-19 13:21:56 -0800107 build_by_default: false,
William A. Kennington III245495e2020-02-13 13:07:30 -0800108 implicit_include_directories: false,
William A. Kennington III3acf92b2021-04-16 13:33:50 -0700109 dependencies: [stdplus_dep, catch2]))
William A. Kennington III245495e2020-02-13 13:07:30 -0800110 endforeach
111endif