blob: 7d2629726d20a2227e9c8c46a4366fdcfacfd180 [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 III5a528022021-04-28 12:52:43 -070032if has_dl
33 gtests += [
34 'dl',
35 ]
36elif build_tests.enabled()
37 error('Not testing libdl feature')
38else
39 warning('Not testing libdl feature')
40endif
41
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070042if has_fd
43 gtests += [
44 'fd/dupable',
45 'fd/managed',
46 'fd/intf',
47 'fd/impl',
48 'fd/mock',
49 'fd/ops',
50 ]
William A. Kennington III45754242021-04-28 12:48:31 -070051elif build_tests.enabled()
52 error('Not testing file descriptor feature')
William A. Kennington IIIeac9d472020-08-03 13:57:14 -070053else
54 warning('Not testing file descriptor feature')
55endif
56
William A. Kennington III5c20da22021-06-18 16:44:55 -070057if has_io_uring
58 gtests += [
59 'io_uring',
60 ]
61elif build_tests.enabled()
62 error('Not testing io_uring feature')
63else
64 warning('Not testing io_uring feature')
65endif
66
William A. Kennington III83af3fa2021-01-31 15:22:54 -080067if gtest.found() and gmock.found()
68 foreach t : gtests
69 test(t, executable(t.underscorify(), t + '.cpp',
70 build_by_default: false,
71 implicit_include_directories: false,
William A. Kennington III3acf92b2021-04-16 13:33:50 -070072 dependencies: [stdplus_dep, gtest, gmock]))
William A. Kennington III83af3fa2021-01-31 15:22:54 -080073 endforeach
74endif
William A. Kennington III245495e2020-02-13 13:07:30 -080075
William A. Kennington III01db6622021-01-31 15:24:13 -080076# Switch to `catch2-with-main.pc` when 2.x supports it
77catch2 = dependency('catch2-with-main', required: false)
78if not catch2.found()
79 catch2 = dependency('catch2', required: false)
80 if catch2.found()
81 catch2_main = meson.get_compiler('cpp').find_library(
82 'Catch2WithMain', required: false)
83 if catch2_main.found()
84 catch2 = declare_dependency(
85 dependencies: [
86 catch2,
87 catch2_main,
88 ])
89 else
90 catch2 = declare_dependency(
91 link_with: static_library(
92 'catch2', 'catch2_main.cpp',
93 implicit_include_directories: false,
94 build_by_default: false,
95 dependencies: catch2),
96 dependencies: catch2)
97 endif
98 endif
99endif
100if not catch2.found()
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -0700101 catch2_opts = import('cmake').subproject_options()
102 catch2_opts.add_cmake_defines({
103 'BUILD_TESTING': 'OFF',
104 'CMAKE_CXX_FLAGS': '-Wno-non-virtual-dtor',
105 })
William A. Kennington III245495e2020-02-13 13:07:30 -0800106 catch2_proj = import('cmake').subproject(
107 'Catch2',
William A. Kennington IIIb5d1c582021-04-16 13:41:39 -0700108 options: catch2_opts,
William A. Kennington III245495e2020-02-13 13:07:30 -0800109 required: false)
110 if catch2_proj.found()
William A. Kennington III01db6622021-01-31 15:24:13 -0800111 catch2 = declare_dependency(
112 dependencies: [
113 catch2_proj.dependency('Catch2'),
114 catch2_proj.dependency('Catch2WithMain'),
115 ])
William A. Kennington III245495e2020-02-13 13:07:30 -0800116 else
117 assert(not build_tests.enabled(), 'Catch2 is required')
118 endif
119endif
120
121catch2_tests = [
William A. Kennington III770c5562020-02-13 13:07:42 -0800122 'signal',
William A. Kennington IIIe0990382019-10-18 02:10:25 -0700123 'raw',
William A. Kennington III245495e2020-02-13 13:07:30 -0800124]
125
William A. Kennington III01db6622021-01-31 15:24:13 -0800126if catch2.found()
William A. Kennington III245495e2020-02-13 13:07:30 -0800127 foreach t : catch2_tests
128 test(t, executable(t.underscorify(), t + '.cpp',
William A. Kennington III31422352020-02-19 13:21:56 -0800129 build_by_default: false,
William A. Kennington III245495e2020-02-13 13:07:30 -0800130 implicit_include_directories: false,
William A. Kennington III3acf92b2021-04-16 13:33:50 -0700131 dependencies: [stdplus_dep, catch2]))
William A. Kennington III245495e2020-02-13 13:07:30 -0800132 endforeach
133endif