added an example with concurrent threads doing assertions - relates #4 (currently ctest fails on it...)
diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt
index 1b9cfbe..8d6e489 100644
--- a/examples/all_features/CMakeLists.txt
+++ b/examples/all_features/CMakeLists.txt
@@ -10,7 +10,7 @@
## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE
################################################################################
-set(files
+set(files_with_output
main.cpp
doctest_proxy.h
header.h
@@ -24,8 +24,14 @@
asserts_used_outside_of_tests.cpp
)
+set(files_all
+ ${files_with_output}
+ concurrency.cpp
+ ../../scripts/coverage_maxout.cpp
+)
+
# add the executable
-doctest_add_executable(${PROJECT_NAME} ${files} ../../scripts/coverage_maxout.cpp)
+doctest_add_executable(${PROJECT_NAME} ${files_all})
# easy way to fix test coverage - disable colors and crash handling
target_compile_definitions(${PROJECT_NAME} PRIVATE
@@ -37,10 +43,13 @@
set(common_args COMMAND $<TARGET_FILE:${PROJECT_NAME}> --no-skipped-summary --no-version --reporters=console)
# add per-file tests
-foreach(f ${files})
+foreach(f ${files_with_output})
doctest_add_test(NAME ${f} ${common_args} -sf=*${f})
endforeach()
+# add this separately since it shouldn't have output compared to reference output - due to concurrency
+doctest_add_test(NO_OUTPUT NAME concurrency.cpp ${common_args} -sf=*concurrency.cpp)
+
# add this separately since the file has a non-straightforward path
doctest_add_test(NAME coverage_maxout.cpp ${common_args} -sf=*coverage_maxout.cpp)
@@ -71,7 +80,7 @@
return() # do not continue with the disabled example
endif()
-doctest_add_executable(disabled ${files})
+doctest_add_executable(disabled ${files_all})
target_compile_definitions(disabled PRIVATE DOCTEST_CONFIG_DISABLE)
doctest_add_test(NAME disabled COMMAND $<TARGET_FILE:disabled>)
diff --git a/examples/all_features/concurrency.cpp b/examples/all_features/concurrency.cpp
new file mode 100644
index 0000000..864cc32
--- /dev/null
+++ b/examples/all_features/concurrency.cpp
@@ -0,0 +1,19 @@
+#include "doctest.h"
+
+DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
+#include <thread>
+DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
+
+static void call_from_thread() {
+ INFO("trololo");
+ CHECK(1 == 1);
+ CHECK(1 == 2);
+}
+
+TEST_CASE("threads...") {
+ std::thread t1(call_from_thread);
+ std::thread t2(call_from_thread);
+
+ t1.join();
+ t2.join();
+}
diff --git a/examples/all_features/test_output/filter_2.txt b/examples/all_features/test_output/filter_2.txt
index ce53ed0..87e39cb 100644
--- a/examples/all_features/test_output/filter_2.txt
+++ b/examples/all_features/test_output/filter_2.txt
@@ -1,6 +1,6 @@
[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 0 | 0 passed | 0 failed | 70 skipped
+[doctest] test cases: 0 | 0 passed | 0 failed | 71 skipped
[doctest] assertions: 0 | 0 passed | 0 failed |
[doctest] Status: SUCCESS!
Program code.