• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(MiscFunctions)
2
3####
4# Temporary workaround for VS toolset changes in 2017
5# We need to disable <UseFullPaths> property, but CMake doesn't support it
6# until 3.13 (not yet released)
7####
8if (MSVC)
9configure_file(${CATCH_DIR}/misc/SelfTest.vcxproj.user
10               ${CMAKE_BINARY_DIR}/projects
11               COPYONLY)
12endif(MSVC) #Temporary workaround
13
14
15# define the sources of the self test
16# Please keep these ordered alphabetically
17set(TEST_SOURCES
18        ${SELF_TEST_DIR}/TestMain.cpp
19        ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp
20        ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp
21        ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp
22        ${SELF_TEST_DIR}/IntrospectiveTests/TagAlias.tests.cpp
23        ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp
24        ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp
25        ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp
26        ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp
27        ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp
28        ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp
29        ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp
30        ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp
31        ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp
32        ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp
33        ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp
34        ${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp
35        ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp
36        ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp
37        ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp
38        ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp
39        ${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp
40        ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp
41        ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp
42        ${SELF_TEST_DIR}/UsageTests/ToStringVariant.tests.cpp
43        ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp
44        ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp
45        ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp
46        ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp
47        ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp
48        )
49CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
50
51# A set of impl files that just #include a single header
52# Please keep these ordered alphabetically
53set(SURROGATE_SOURCES
54        ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
55        ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
56        ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
57        ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
58        ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
59        ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
60        ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
61        ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
62        )
63CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
64
65
66# Please keep these ordered alphabetically
67set(TOP_LEVEL_HEADERS
68        ${HEADER_DIR}/catch.hpp
69        ${HEADER_DIR}/catch_with_main.hpp
70        )
71CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
72
73# Please keep these ordered alphabetically
74set(EXTERNAL_HEADERS
75        ${HEADER_DIR}/external/clara.hpp
76        )
77CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
78
79
80# Please keep these ordered alphabetically
81set(INTERNAL_HEADERS
82        ${HEADER_DIR}/internal/catch_approx.h
83        ${HEADER_DIR}/internal/catch_assertionhandler.h
84        ${HEADER_DIR}/internal/catch_assertioninfo.h
85        ${HEADER_DIR}/internal/catch_assertionresult.h
86        ${HEADER_DIR}/internal/catch_capture.hpp
87        ${HEADER_DIR}/internal/catch_capture_matchers.h
88        ${HEADER_DIR}/internal/catch_clara.h
89        ${HEADER_DIR}/internal/catch_commandline.h
90        ${HEADER_DIR}/internal/catch_common.h
91        ${HEADER_DIR}/internal/catch_compiler_capabilities.h
92        ${HEADER_DIR}/internal/catch_config.hpp
93        ${HEADER_DIR}/internal/catch_console_colour.h
94        ${HEADER_DIR}/internal/catch_context.h
95        ${HEADER_DIR}/internal/catch_debug_console.h
96        ${HEADER_DIR}/internal/catch_debugger.h
97        ${HEADER_DIR}/internal/catch_decomposer.h
98        ${HEADER_DIR}/internal/catch_default_main.hpp
99        ${HEADER_DIR}/internal/catch_enforce.h
100        ${HEADER_DIR}/internal/catch_errno_guard.h
101        ${HEADER_DIR}/internal/catch_exception_translator_registry.h
102        ${HEADER_DIR}/internal/catch_external_interfaces.h
103        ${HEADER_DIR}/internal/catch_fatal_condition.h
104        ${HEADER_DIR}/internal/catch_generators.hpp
105        ${HEADER_DIR}/internal/catch_generators_generic.hpp
106        ${HEADER_DIR}/internal/catch_generators_specific.hpp
107        ${HEADER_DIR}/internal/catch_impl.hpp
108        ${HEADER_DIR}/internal/catch_interfaces_capture.h
109        ${HEADER_DIR}/internal/catch_interfaces_config.h
110        ${HEADER_DIR}/internal/catch_interfaces_exception.h
111        ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
112        ${HEADER_DIR}/internal/catch_interfaces_reporter.h
113        ${HEADER_DIR}/internal/catch_interfaces_runner.h
114        ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
115        ${HEADER_DIR}/internal/catch_interfaces_testcase.h
116        ${HEADER_DIR}/internal/catch_leak_detector.h
117        ${HEADER_DIR}/internal/catch_list.h
118        ${HEADER_DIR}/internal/catch_matchers.h
119        ${HEADER_DIR}/internal/catch_matchers_floating.h
120        ${HEADER_DIR}/internal/catch_matchers_generic.hpp
121        ${HEADER_DIR}/internal/catch_matchers_string.h
122        ${HEADER_DIR}/internal/catch_matchers_vector.h
123        ${HEADER_DIR}/internal/catch_message.h
124        ${HEADER_DIR}/internal/catch_meta.hpp
125        ${HEADER_DIR}/internal/catch_objc.hpp
126        ${HEADER_DIR}/internal/catch_objc_arc.hpp
127        ${HEADER_DIR}/internal/catch_option.hpp
128        ${HEADER_DIR}/internal/catch_output_redirect.h
129        ${HEADER_DIR}/internal/catch_platform.h
130        ${HEADER_DIR}/internal/catch_polyfills.hpp
131        ${HEADER_DIR}/internal/catch_preprocessor.hpp
132        ${HEADER_DIR}/internal/catch_random_number_generator.h
133        ${HEADER_DIR}/internal/catch_reenable_warnings.h
134        ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
135        ${HEADER_DIR}/internal/catch_reporter_registry.h
136        ${HEADER_DIR}/internal/catch_result_type.h
137        ${HEADER_DIR}/internal/catch_run_context.h
138        ${HEADER_DIR}/internal/catch_benchmark.h
139        ${HEADER_DIR}/internal/catch_section.h
140        ${HEADER_DIR}/internal/catch_section_info.h
141        ${HEADER_DIR}/internal/catch_session.h
142        ${HEADER_DIR}/internal/catch_singletons.hpp
143        ${HEADER_DIR}/internal/catch_startup_exception_registry.h
144        ${HEADER_DIR}/internal/catch_stream.h
145        ${HEADER_DIR}/internal/catch_stringref.h
146        ${HEADER_DIR}/internal/catch_string_manip.h
147        ${HEADER_DIR}/internal/catch_suppress_warnings.h
148        ${HEADER_DIR}/internal/catch_tag_alias.h
149        ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h
150        ${HEADER_DIR}/internal/catch_tag_alias_registry.h
151        ${HEADER_DIR}/internal/catch_test_case_info.h
152        ${HEADER_DIR}/internal/catch_test_case_registry_impl.h
153        ${HEADER_DIR}/internal/catch_test_case_tracker.h
154        ${HEADER_DIR}/internal/catch_test_registry.h
155        ${HEADER_DIR}/internal/catch_test_spec.h
156        ${HEADER_DIR}/internal/catch_test_spec_parser.h
157        ${HEADER_DIR}/internal/catch_text.h
158        ${HEADER_DIR}/internal/catch_timer.h
159        ${HEADER_DIR}/internal/catch_to_string.hpp
160        ${HEADER_DIR}/internal/catch_tostring.h
161        ${HEADER_DIR}/internal/catch_totals.h
162        ${HEADER_DIR}/internal/catch_type_traits.hpp
163        ${HEADER_DIR}/internal/catch_uncaught_exceptions.h
164        ${HEADER_DIR}/internal/catch_user_interfaces.h
165        ${HEADER_DIR}/internal/catch_version.h
166        ${HEADER_DIR}/internal/catch_wildcard_pattern.h
167        ${HEADER_DIR}/internal/catch_windows_h_proxy.h
168        ${HEADER_DIR}/internal/catch_xmlwriter.h
169        )
170set(IMPL_SOURCES
171        ${HEADER_DIR}/internal/catch_approx.cpp
172        ${HEADER_DIR}/internal/catch_assertionhandler.cpp
173        ${HEADER_DIR}/internal/catch_assertionresult.cpp
174        ${HEADER_DIR}/internal/catch_benchmark.cpp
175        ${HEADER_DIR}/internal/catch_capture_matchers.cpp
176        ${HEADER_DIR}/internal/catch_commandline.cpp
177        ${HEADER_DIR}/internal/catch_common.cpp
178        ${HEADER_DIR}/internal/catch_config.cpp
179        ${HEADER_DIR}/internal/catch_console_colour.cpp
180        ${HEADER_DIR}/internal/catch_context.cpp
181        ${HEADER_DIR}/internal/catch_debug_console.cpp
182        ${HEADER_DIR}/internal/catch_debugger.cpp
183        ${HEADER_DIR}/internal/catch_decomposer.cpp
184        ${HEADER_DIR}/internal/catch_enforce.cpp
185        ${HEADER_DIR}/internal/catch_errno_guard.cpp
186        ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp
187        ${HEADER_DIR}/internal/catch_fatal_condition.cpp
188        ${HEADER_DIR}/internal/catch_generators.cpp
189        ${HEADER_DIR}/internal/catch_interfaces_capture.cpp
190        ${HEADER_DIR}/internal/catch_interfaces_config.cpp
191        ${HEADER_DIR}/internal/catch_interfaces_exception.cpp
192        ${HEADER_DIR}/internal/catch_interfaces_generatortracker.h
193        ${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp
194        ${HEADER_DIR}/internal/catch_interfaces_runner.cpp
195        ${HEADER_DIR}/internal/catch_interfaces_testcase.cpp
196        ${HEADER_DIR}/internal/catch_list.cpp
197        ${HEADER_DIR}/internal/catch_leak_detector.cpp
198        ${HEADER_DIR}/internal/catch_matchers.cpp
199        ${HEADER_DIR}/internal/catch_matchers_floating.cpp
200        ${HEADER_DIR}/internal/catch_matchers_generic.cpp
201        ${HEADER_DIR}/internal/catch_matchers_string.cpp
202        ${HEADER_DIR}/internal/catch_message.cpp
203        ${HEADER_DIR}/internal/catch_output_redirect.cpp
204        ${HEADER_DIR}/internal/catch_registry_hub.cpp
205        ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp
206        ${HEADER_DIR}/internal/catch_polyfills.cpp
207        ${HEADER_DIR}/internal/catch_random_number_generator.cpp
208        ${HEADER_DIR}/internal/catch_reporter_registry.cpp
209        ${HEADER_DIR}/internal/catch_result_type.cpp
210        ${HEADER_DIR}/internal/catch_run_context.cpp
211        ${HEADER_DIR}/internal/catch_section.cpp
212        ${HEADER_DIR}/internal/catch_section_info.cpp
213        ${HEADER_DIR}/internal/catch_session.cpp
214        ${HEADER_DIR}/internal/catch_singletons.cpp
215        ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp
216        ${HEADER_DIR}/internal/catch_stream.cpp
217        ${HEADER_DIR}/internal/catch_stringref.cpp
218        ${HEADER_DIR}/internal/catch_string_manip.cpp
219        ${HEADER_DIR}/internal/catch_tag_alias.cpp
220        ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp
221        ${HEADER_DIR}/internal/catch_tag_alias_registry.cpp
222        ${HEADER_DIR}/internal/catch_test_case_info.cpp
223        ${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp
224        ${HEADER_DIR}/internal/catch_test_case_tracker.cpp
225        ${HEADER_DIR}/internal/catch_test_registry.cpp
226        ${HEADER_DIR}/internal/catch_test_spec.cpp
227        ${HEADER_DIR}/internal/catch_test_spec_parser.cpp
228        ${HEADER_DIR}/internal/catch_timer.cpp
229        ${HEADER_DIR}/internal/catch_tostring.cpp
230        ${HEADER_DIR}/internal/catch_totals.cpp
231        ${HEADER_DIR}/internal/catch_uncaught_exceptions.cpp
232        ${HEADER_DIR}/internal/catch_version.cpp
233        ${HEADER_DIR}/internal/catch_wildcard_pattern.cpp
234        ${HEADER_DIR}/internal/catch_xmlwriter.cpp
235        )
236set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS})
237CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal)
238
239# Please keep these ordered alphabetically
240set(REPORTER_HEADERS
241        ${HEADER_DIR}/reporters/catch_reporter_automake.hpp
242        ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
243        ${HEADER_DIR}/reporters/catch_reporter_compact.h
244        ${HEADER_DIR}/reporters/catch_reporter_console.h
245        ${HEADER_DIR}/reporters/catch_reporter_junit.h
246        ${HEADER_DIR}/reporters/catch_reporter_listening.h
247        ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
248        ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
249        ${HEADER_DIR}/reporters/catch_reporter_xml.h
250        )
251set(REPORTER_SOURCES
252        ${HEADER_DIR}/reporters/catch_reporter_bases.cpp
253        ${HEADER_DIR}/reporters/catch_reporter_compact.cpp
254        ${HEADER_DIR}/reporters/catch_reporter_console.cpp
255        ${HEADER_DIR}/reporters/catch_reporter_junit.cpp
256        ${HEADER_DIR}/reporters/catch_reporter_listening.cpp
257        ${HEADER_DIR}/reporters/catch_reporter_xml.cpp
258        )
259set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES})
260CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters)
261
262# Specify the headers, too, so CLion recognises them as project files
263set(HEADERS
264        ${TOP_LEVEL_HEADERS}
265        ${EXTERNAL_HEADERS}
266        ${INTERNAL_HEADERS}
267        ${REPORTER_HEADERS}
268        )
269
270# Provide some groupings for IDEs
271SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
272SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES})
273
274include(CTest)
275
276add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS})
277target_include_directories(SelfTest PRIVATE ${HEADER_DIR})
278
279if(USE_CPP17)
280    message(STATUS "Enabling C++17")
281    set_property(TARGET SelfTest PROPERTY CXX_STANDARD 17)
282elseif(USE_CPP14)
283    message(STATUS "Enabling C++14")
284    set_property(TARGET SelfTest PROPERTY CXX_STANDARD 14)
285else()
286    message(STATUS "Enabling C++11")
287    set_property(TARGET SelfTest PROPERTY CXX_STANDARD 11)
288endif()
289
290set_property(TARGET SelfTest PROPERTY CXX_STANDARD_REQUIRED ON)
291set_property(TARGET SelfTest PROPERTY CXX_EXTENSIONS OFF)
292
293if (CATCH_ENABLE_COVERAGE)
294    set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
295    find_package(codecov)
296    add_coverage(SelfTest)
297    list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
298    coverage_evaluate()
299endif()
300
301# Add per compiler options
302if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
303    target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic -Wmissing-declarations )
304    if (CATCH_ENABLE_WERROR)
305        target_compile_options( SelfTest PRIVATE -Werror)
306    endif()
307endif()
308# Clang specific options go here
309if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
310    target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
311endif()
312if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
313    STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
314    target_compile_options( SelfTest PRIVATE /w44265 /w44061 /w44062 /w45038 )
315    if (CATCH_ENABLE_WERROR)
316        target_compile_options( SelfTest PRIVATE /WX)
317    endif()
318    # Force MSVC to consider everything as encoded in utf-8
319    target_compile_options( SelfTest PRIVATE /utf-8 )
320endif()
321
322
323# configure unit tests via CTest
324add_test(NAME RunTests COMMAND $<TARGET_FILE:SelfTest>)
325
326add_test(NAME ListTests COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
327set_tests_properties(ListTests PROPERTIES
328    PASS_REGULAR_EXPRESSION "[0-9]+ test cases"
329    FAIL_REGULAR_EXPRESSION "Hidden Test"
330)
331
332add_test(NAME ListTags COMMAND $<TARGET_FILE:SelfTest> --list-tags)
333set_tests_properties(ListTags PROPERTIES
334    PASS_REGULAR_EXPRESSION "[0-9]+ tags"
335    FAIL_REGULAR_EXPRESSION "\\[\\.\\]")
336
337add_test(NAME ListReporters COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
338set_tests_properties(ListReporters PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:")
339
340add_test(NAME ListTestNamesOnly COMMAND $<TARGET_FILE:SelfTest> --list-test-names-only)
341set_tests_properties(ListTestNamesOnly PROPERTIES
342    PASS_REGULAR_EXPRESSION "Regex string matcher"
343    FAIL_REGULAR_EXPRESSION "Hidden Test")
344
345add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions)
346set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")
347
348add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> -w NoTests "___nonexistent_test___")
349set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched")
350
351add_test(NAME FilteredSection-1 COMMAND $<TARGET_FILE:SelfTest> \#1394 -c RunSection)
352set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
353add_test(NAME FilteredSection-2 COMMAND $<TARGET_FILE:SelfTest> \#1394\ nested -c NestedRunSection -c s1)
354set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
355
356# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
357add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
358set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
359
360
361if (CATCH_USE_VALGRIND)
362    add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)
363    add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
364    set_tests_properties(ValgrindListTests PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks")
365    add_test(NAME ValgrindListTags COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tags)
366    set_tests_properties(ValgrindListTags PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks")
367endif()
368