blob: 031712162031d22c9b2d19aa81fe594b77e8c587 [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 III458aeae2021-06-14 15:07:16 -070024 'cancel',
William A. Kennington III9a70f4e2021-05-01 17:16:57 -070025 'exception',
William A. Kennington IIIe847ef82018-11-02 17:29:15 -070026 'handle/copyable',
William A. Kennington III7a5e2322018-11-02 17:28:35 -070027 'handle/managed',
William A. Kennington IIIbff0b0f2018-11-16 19:56:10 -080028 'util/cexec',
William A. Kennington III4ef36e72019-06-27 12:48:59 -070029 'util/string',
William A. Kennington III15982f62019-01-31 14:43:41 -080030]
31
William A. Kennington IIId7acddd2022-07-13 16:41:11 -070032gtest_deps = [
33 stdplus_dep,
34 gtest,
35 gmock,
36]
37
William A. Kennington III5a528022021-04-28 12:52:43 -070038if has_dl
39 gtests += [
40 'dl',
41 ]
William A. Kennington IIId7acddd2022-07-13 16:41:11 -070042
43 gtest_deps += [
44 stdplus_dl_dep,
45 ]
William A. Kennington III5a528022021-04-28 12:52:43 -070046elif build_tests.enabled()
47 error('Not testing libdl feature')
48else
49 warning('Not testing libdl feature')
50endif
51
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070052if has_fd
53 gtests += [
54 'fd/dupable',
55 'fd/managed',
56 'fd/intf',
57 'fd/impl',
William A. Kennington III891e6a32022-05-17 16:35:03 -070058 'fd/mmap',
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070059 'fd/mock',
60 'fd/ops',
61 ]
William A. Kennington IIId7acddd2022-07-13 16:41:11 -070062
63 gtest_deps += [
64 stdplus_fd_dep,
65 ]
William A. Kennington III45754242021-04-28 12:48:31 -070066elif build_tests.enabled()
67 error('Not testing file descriptor feature')
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070068else
69 warning('Not testing file descriptor feature')
70endif
71
William A. Kennington III5c20da22021-06-18 16:44:55 -070072if has_io_uring
73 gtests += [
74 'io_uring',
75 ]
William A. Kennington IIId7acddd2022-07-13 16:41:11 -070076
77 gtest_deps += [
78 stdplus_io_uring_dep,
79 ]
William A. Kennington III5c20da22021-06-18 16:44:55 -070080elif build_tests.enabled()
81 error('Not testing io_uring feature')
82else
83 warning('Not testing io_uring feature')
84endif
85
William A. Kennington III83af3fa2021-01-31 15:22:54 -080086if gtest.found() and gmock.found()
87 foreach t : gtests
88 test(t, executable(t.underscorify(), t + '.cpp',
89 build_by_default: false,
90 implicit_include_directories: false,
William A. Kennington IIId7acddd2022-07-13 16:41:11 -070091 dependencies: gtest_deps))
William A. Kennington III83af3fa2021-01-31 15:22:54 -080092 endforeach
93endif
William A. Kennington III245495e2020-02-13 13:07:30 -080094
William A. Kennington III01db6622021-01-31 15:24:13 -080095# Switch to `catch2-with-main.pc` when 2.x supports it
96catch2 = dependency('catch2-with-main', required: false)
97if not catch2.found()
98 catch2 = dependency('catch2', required: false)
99 if catch2.found()
100 catch2_main = meson.get_compiler('cpp').find_library(
101 'Catch2WithMain', required: false)
102 if catch2_main.found()
103 catch2 = declare_dependency(
104 dependencies: [
105 catch2,
106 catch2_main,
107 ])
108 else
109 catch2 = declare_dependency(
110 link_with: static_library(
111 'catch2', 'catch2_main.cpp',
112 implicit_include_directories: false,
113 build_by_default: false,
114 dependencies: catch2),
115 dependencies: catch2)
116 endif
117 endif
118endif
119if not catch2.found()
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -0700120 catch2_opts = import('cmake').subproject_options()
121 catch2_opts.add_cmake_defines({
122 'BUILD_TESTING': 'OFF',
123 'CMAKE_CXX_FLAGS': '-Wno-non-virtual-dtor',
124 })
William A. Kennington III245495e2020-02-13 13:07:30 -0800125 catch2_proj = import('cmake').subproject(
126 'Catch2',
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -0700127 options: catch2_opts,
William A. Kennington III245495e2020-02-13 13:07:30 -0800128 required: false)
129 if catch2_proj.found()
William A. Kennington III01db6622021-01-31 15:24:13 -0800130 catch2 = declare_dependency(
131 dependencies: [
132 catch2_proj.dependency('Catch2'),
133 catch2_proj.dependency('Catch2WithMain'),
134 ])
William A. Kennington III245495e2020-02-13 13:07:30 -0800135 else
136 assert(not build_tests.enabled(), 'Catch2 is required')
137 endif
138endif
139
140catch2_tests = [
William A. Kennington III770c5562020-02-13 13:07:42 -0800141 'signal',
William A. Kennington IIIe0990382019-10-18 02:10:25 -0700142 'raw',
William A. Kennington III245495e2020-02-13 13:07:30 -0800143]
144
William A. Kennington III01db6622021-01-31 15:24:13 -0800145if catch2.found()
William A. Kennington III245495e2020-02-13 13:07:30 -0800146 foreach t : catch2_tests
147 test(t, executable(t.underscorify(), t + '.cpp',
William A. Kennington III31422352020-02-19 13:21:56 -0800148 build_by_default: false,
William A. Kennington III245495e2020-02-13 13:07:30 -0800149 implicit_include_directories: false,
William A. Kennington III3acf92b2021-04-16 13:33:50 -0700150 dependencies: [stdplus_dep, catch2]))
William A. Kennington III245495e2020-02-13 13:07:30 -0800151 endforeach
152endif