- added an undocumented flag to omit the "skipped" part in the output summary - for convenience for the all_features example
- grouped examples by project
- changed names of output from tests
- added source files for some features without examples
diff --git a/doc/markdown/roadmap.md b/doc/markdown/roadmap.md
index 87ac31c..df9a92b 100644
--- a/doc/markdown/roadmap.md
+++ b/doc/markdown/roadmap.md
@@ -10,6 +10,7 @@
### For 1.2:
+- print current test suite when logging a test case
- Value-Parameterized test cases - https://github.com/onqtam/doctest/issues/38
- decorators for test cases - like in boost test
- description
diff --git a/doctest/doctest.h b/doctest/doctest.h
index 7207073..361251a 100644
--- a/doctest/doctest.h
+++ b/doctest/doctest.h
@@ -3151,6 +3151,7 @@
bool no_breaks; // to not break into the debugger
bool no_path_in_filenames; // if the path to files should be removed from the output
bool no_line_numbers; // if source code line numbers should be omitted from the output
+ bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!!
bool help; // to print the help
bool version; // to print the version
@@ -4693,9 +4694,8 @@
printf(" -l, --last=<int> the last test passing the filters to\n");
printf(" execute - for range-based execution\n");
printf(" -aa, --abort-after=<int> stop after <int> failed assertions\n");
- printf(" -scfl,--subcase-filter-levels=<int> apply filters for the first <int> "
- "levels\n\n");
- DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
+ printf(" -scfl,--subcase-filter-levels=<int> apply filters for the first <int> levels\n");
+ DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan);
printf("Bool options - can be used like flags and true is assumed. Available:\n\n");
printf(" -s, --success=<bool> include successful assertions in output\n");
printf(" -cs, --case-sensitive=<bool> filters being treated as case sensitive\n");
@@ -4708,11 +4708,10 @@
printf(" -fc, --force-colors=<bool> use colors even when not in a tty\n");
printf(" -nb, --no-breaks=<bool> disables breakpoints in debuggers\n");
printf(" -npf, --no-path-filenames=<bool> only filenames and no paths in output\n");
- printf(" -nln, --no-line-numbers=<bool> 0 instead of real line numbers in "
- "output\n\n");
+ printf(" -nln, --no-line-numbers=<bool> 0 instead of real line numbers in output\n");
// ==================================================================================== << 79
- DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
+ DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan);
printf("for more information visit the project documentation\n\n");
}
@@ -4743,10 +4742,13 @@
DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | ");
DOCTEST_PRINTF_COLORED(buff, Color::None);
- DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%4d skipped\n",
- static_cast<unsigned>(getRegisteredTests().size()) -
- p->numTestsPassingFilters);
- DOCTEST_PRINTF_COLORED(buff, Color::None);
+ if(p->no_skipped_summary == false) {
+ DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%4d skipped",
+ static_cast<unsigned>(getRegisteredTests().size()) -
+ p->numTestsPassingFilters);
+ DOCTEST_PRINTF_COLORED(buff, Color::None);
+ }
+ DOCTEST_PRINTF_COLORED("\n", Color::None);
DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
@@ -4852,6 +4854,7 @@
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-breaks, dt-nb, no_breaks, 0);
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-path-filenames, dt-npf, no_path_in_filenames, 0);
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-line-numbers, dt-nln, no_line_numbers, 0);
+ DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-skipped-summary, dt-no-skipped-summary, no_skipped_summary, 0);
// clang-format on
#undef DOCTEST_PARSE_STR_OPTION
diff --git a/doctest/parts/doctest_impl.h b/doctest/parts/doctest_impl.h
index 1f885cc..589f532 100644
--- a/doctest/parts/doctest_impl.h
+++ b/doctest/parts/doctest_impl.h
@@ -270,6 +270,7 @@
bool no_breaks; // to not break into the debugger
bool no_path_in_filenames; // if the path to files should be removed from the output
bool no_line_numbers; // if source code line numbers should be omitted from the output
+ bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!!
bool help; // to print the help
bool version; // to print the version
@@ -1812,9 +1813,8 @@
printf(" -l, --last=<int> the last test passing the filters to\n");
printf(" execute - for range-based execution\n");
printf(" -aa, --abort-after=<int> stop after <int> failed assertions\n");
- printf(" -scfl,--subcase-filter-levels=<int> apply filters for the first <int> "
- "levels\n\n");
- DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
+ printf(" -scfl,--subcase-filter-levels=<int> apply filters for the first <int> levels\n");
+ DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan);
printf("Bool options - can be used like flags and true is assumed. Available:\n\n");
printf(" -s, --success=<bool> include successful assertions in output\n");
printf(" -cs, --case-sensitive=<bool> filters being treated as case sensitive\n");
@@ -1827,11 +1827,10 @@
printf(" -fc, --force-colors=<bool> use colors even when not in a tty\n");
printf(" -nb, --no-breaks=<bool> disables breakpoints in debuggers\n");
printf(" -npf, --no-path-filenames=<bool> only filenames and no paths in output\n");
- printf(" -nln, --no-line-numbers=<bool> 0 instead of real line numbers in "
- "output\n\n");
+ printf(" -nln, --no-line-numbers=<bool> 0 instead of real line numbers in output\n");
// ==================================================================================== << 79
- DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
+ DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan);
printf("for more information visit the project documentation\n\n");
}
@@ -1862,10 +1861,13 @@
DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | ");
DOCTEST_PRINTF_COLORED(buff, Color::None);
- DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%4d skipped\n",
- static_cast<unsigned>(getRegisteredTests().size()) -
- p->numTestsPassingFilters);
- DOCTEST_PRINTF_COLORED(buff, Color::None);
+ if(p->no_skipped_summary == false) {
+ DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%4d skipped",
+ static_cast<unsigned>(getRegisteredTests().size()) -
+ p->numTestsPassingFilters);
+ DOCTEST_PRINTF_COLORED(buff, Color::None);
+ }
+ DOCTEST_PRINTF_COLORED("\n", Color::None);
DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan);
@@ -1971,6 +1973,7 @@
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-breaks, dt-nb, no_breaks, 0);
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-path-filenames, dt-npf, no_path_in_filenames, 0);
DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-line-numbers, dt-nln, no_line_numbers, 0);
+ DOCTEST_PARSE_AS_BOOL_OR_FLAG(dt-no-skipped-summary, dt-no-skipped-summary, no_skipped_summary, 0);
// clang-format on
#undef DOCTEST_PARSE_STR_OPTION
diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt
index d47b7ab..68e089d 100644
--- a/examples/all_features/CMakeLists.txt
+++ b/examples/all_features/CMakeLists.txt
@@ -9,6 +9,9 @@
assertion_macros.cpp
stringification.cpp
subcases.cpp
+ logging.cpp
+ templated_test_cases.cpp
+ test_suites.cpp
)
# add the normal build
@@ -18,7 +21,7 @@
# add per-file tests
foreach(f ${files})
- doctest_add_test(NAME ${PROJECT_NAME}.${f} COMMAND $<TARGET_FILE:${PROJECT_NAME}> --source-file=*${f})
+ doctest_add_test(NAME ${f} COMMAND $<TARGET_FILE:${PROJECT_NAME}> --dt-no-skipped-summary=1 --source-file=*${f})
endforeach()
## queries
diff --git a/examples/all_features/logging.cpp b/examples/all_features/logging.cpp
new file mode 100644
index 0000000..9a66397
--- /dev/null
+++ b/examples/all_features/logging.cpp
@@ -0,0 +1,110 @@
+#include "doctest.h"
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+static int throws(bool in) {
+ if(in)
+#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
+ throw 5;
+#else // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 0;
+#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 42;
+}
+
+TEST_CASE("lots of nested subcases") {
+ cout << endl << "root" << endl;
+ SUBCASE("") {
+ cout << "1" << endl;
+ SUBCASE("") { cout << "1.1" << endl; }
+ }
+ SUBCASE("") {
+ cout << "2" << endl;
+ SUBCASE("") { cout << "2.1" << endl; }
+ SUBCASE("") {
+ // whops! all the subcases below shouldn't be discovered and executed!
+ throws(true);
+
+ cout << "2.2" << endl;
+ SUBCASE("") {
+ cout << "2.2.1" << endl;
+ SUBCASE("") { cout << "2.2.1.1" << endl; }
+ SUBCASE("") { cout << "2.2.1.2" << endl; }
+ }
+ }
+ SUBCASE("") { cout << "2.3" << endl; }
+ SUBCASE("") { cout << "2.4" << endl; }
+ }
+}
+
+SCENARIO("vectors can be sized and resized") {
+ GIVEN("A vector with some items") {
+ std::vector<int> v(5);
+
+ REQUIRE(v.size() == 5);
+ REQUIRE(v.capacity() >= 5);
+
+ WHEN("the size is increased") {
+ v.resize(10);
+
+ THEN("the size and capacity change") {
+ CHECK(v.size() == 20);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("the size is reduced") {
+ v.resize(0);
+
+ THEN("the size changes but not capacity") {
+ CHECK(v.size() == 0);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ WHEN("more capacity is reserved") {
+ v.reserve(10);
+
+ THEN("the capacity changes but not the size") {
+ CHECK(v.size() == 5);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("less capacity is reserved") {
+ v.reserve(0);
+
+ THEN("neither size nor capacity are changed") {
+ CHECK(v.size() == 10);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ }
+}
+
+// to silence GCC warnings when inheriting from the class TheFixture which has no virtual destructor
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic ignored "-Weffc++"
+#endif // __GNUC__
+
+struct TheFixture
+{
+ int data;
+ TheFixture()
+ : data(42) {
+ // setup here
+ }
+
+ ~TheFixture() {
+ // teardown here
+ }
+};
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 1") {
+ data /= 2;
+ CHECK(data == 21);
+}
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 2") {
+ data *= 2;
+ CHECK(data == 85);
+}
diff --git a/examples/all_features/main.cpp b/examples/all_features/main.cpp
index 8dd9e36..63bf98e 100644
--- a/examples/all_features/main.cpp
+++ b/examples/all_features/main.cpp
@@ -29,8 +29,6 @@
return res + client_stuff_return_code; // the result from doctest is propagated here as well
}
-#include <string>
-
TEST_CASE("[string] testing std::string") {
std::string a("omg");
CHECK(a == "omg");
diff --git a/examples/all_features/templated_test_cases.cpp b/examples/all_features/templated_test_cases.cpp
new file mode 100644
index 0000000..9a66397
--- /dev/null
+++ b/examples/all_features/templated_test_cases.cpp
@@ -0,0 +1,110 @@
+#include "doctest.h"
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+static int throws(bool in) {
+ if(in)
+#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
+ throw 5;
+#else // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 0;
+#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 42;
+}
+
+TEST_CASE("lots of nested subcases") {
+ cout << endl << "root" << endl;
+ SUBCASE("") {
+ cout << "1" << endl;
+ SUBCASE("") { cout << "1.1" << endl; }
+ }
+ SUBCASE("") {
+ cout << "2" << endl;
+ SUBCASE("") { cout << "2.1" << endl; }
+ SUBCASE("") {
+ // whops! all the subcases below shouldn't be discovered and executed!
+ throws(true);
+
+ cout << "2.2" << endl;
+ SUBCASE("") {
+ cout << "2.2.1" << endl;
+ SUBCASE("") { cout << "2.2.1.1" << endl; }
+ SUBCASE("") { cout << "2.2.1.2" << endl; }
+ }
+ }
+ SUBCASE("") { cout << "2.3" << endl; }
+ SUBCASE("") { cout << "2.4" << endl; }
+ }
+}
+
+SCENARIO("vectors can be sized and resized") {
+ GIVEN("A vector with some items") {
+ std::vector<int> v(5);
+
+ REQUIRE(v.size() == 5);
+ REQUIRE(v.capacity() >= 5);
+
+ WHEN("the size is increased") {
+ v.resize(10);
+
+ THEN("the size and capacity change") {
+ CHECK(v.size() == 20);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("the size is reduced") {
+ v.resize(0);
+
+ THEN("the size changes but not capacity") {
+ CHECK(v.size() == 0);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ WHEN("more capacity is reserved") {
+ v.reserve(10);
+
+ THEN("the capacity changes but not the size") {
+ CHECK(v.size() == 5);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("less capacity is reserved") {
+ v.reserve(0);
+
+ THEN("neither size nor capacity are changed") {
+ CHECK(v.size() == 10);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ }
+}
+
+// to silence GCC warnings when inheriting from the class TheFixture which has no virtual destructor
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic ignored "-Weffc++"
+#endif // __GNUC__
+
+struct TheFixture
+{
+ int data;
+ TheFixture()
+ : data(42) {
+ // setup here
+ }
+
+ ~TheFixture() {
+ // teardown here
+ }
+};
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 1") {
+ data /= 2;
+ CHECK(data == 21);
+}
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 2") {
+ data *= 2;
+ CHECK(data == 85);
+}
diff --git a/examples/all_features/test_output/all_features.alternative_macros.cpp.txt b/examples/all_features/test_output/alternative_macros.cpp.txt
similarity index 73%
rename from examples/all_features/test_output/all_features.alternative_macros.cpp.txt
rename to examples/all_features/test_output/alternative_macros.cpp.txt
index c76c4b0..e20c8f4 100644
--- a/examples/all_features/test_output/all_features.alternative_macros.cpp.txt
+++ b/examples/all_features/test_output/alternative_macros.cpp.txt
@@ -1,5 +1,5 @@
[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 1 | 1 passed | 0 failed | 20 skipped
+[doctest] test cases: 1 | 1 passed | 0 failed |
[doctest] assertions: 6 | 6 passed | 0 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.assertion_macros.cpp.txt b/examples/all_features/test_output/assertion_macros.cpp.txt
similarity index 97%
rename from examples/all_features/test_output/all_features.assertion_macros.cpp.txt
rename to examples/all_features/test_output/assertion_macros.cpp.txt
index 094bcea..f114ac8 100644
--- a/examples/all_features/test_output/all_features.assertion_macros.cpp.txt
+++ b/examples/all_features/test_output/assertion_macros.cpp.txt
@@ -96,6 +96,6 @@
whops!
===============================================================================
-[doctest] test cases: 7 | 1 passed | 6 failed | 14 skipped
+[doctest] test cases: 7 | 1 passed | 6 failed |
[doctest] assertions: 24 | 12 passed | 12 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.coverage_maxout.cpp.txt b/examples/all_features/test_output/coverage_maxout.cpp.txt
similarity index 95%
rename from examples/all_features/test_output/all_features.coverage_maxout.cpp.txt
rename to examples/all_features/test_output/coverage_maxout.cpp.txt
index 45375ee..614f6c6 100644
--- a/examples/all_features/test_output/all_features.coverage_maxout.cpp.txt
+++ b/examples/all_features/test_output/coverage_maxout.cpp.txt
@@ -54,6 +54,6 @@
unknown exception
===============================================================================
-[doctest] test cases: 5 | 2 passed | 3 failed | 16 skipped
+[doctest] test cases: 5 | 2 passed | 3 failed |
[doctest] assertions: 60 | 52 passed | 8 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.doctest_proxy.h.txt b/examples/all_features/test_output/doctest_proxy.h.txt
similarity index 73%
rename from examples/all_features/test_output/all_features.doctest_proxy.h.txt
rename to examples/all_features/test_output/doctest_proxy.h.txt
index c8a806b..eca69f0 100644
--- a/examples/all_features/test_output/all_features.doctest_proxy.h.txt
+++ b/examples/all_features/test_output/doctest_proxy.h.txt
@@ -1,5 +1,5 @@
[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 0 | 0 passed | 0 failed | 21 skipped
+[doctest] test cases: 0 | 0 passed | 0 failed |
[doctest] assertions: 0 | 0 passed | 0 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.subcases.cpp.txt b/examples/all_features/test_output/logging.cpp.txt
similarity index 84%
copy from examples/all_features/test_output/all_features.subcases.cpp.txt
copy to examples/all_features/test_output/logging.cpp.txt
index 3fe1886..bf8d161 100644
--- a/examples/all_features/test_output/all_features.subcases.cpp.txt
+++ b/examples/all_features/test_output/logging.cpp.txt
@@ -11,7 +11,7 @@
root
2
== TEST CASE ==================================================================
-subcases.cpp(0)
+logging.cpp(0)
lots of nested subcases
TEST CASE FAILED!
@@ -19,39 +19,39 @@
unknown exception
== TEST CASE ==================================================================
-subcases.cpp(0)
+logging.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: the size is increased
Then: the size and capacity change
-subcases.cpp(0) ERROR!
+logging.cpp(0) ERROR!
CHECK( v.size() == 20 )
with expansion:
CHECK( 10 == 20 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+logging.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: less capacity is reserved
Then: neither size nor capacity are changed
-subcases.cpp(0) ERROR!
+logging.cpp(0) ERROR!
CHECK( v.size() == 10 )
with expansion:
CHECK( 5 == 10 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+logging.cpp(0)
test with a fixture - 2
-subcases.cpp(0) ERROR!
+logging.cpp(0) ERROR!
CHECK( data == 85 )
with expansion:
CHECK( 84 == 85 )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed | 17 skipped
+[doctest] test cases: 4 | 1 passed | 3 failed |
[doctest] assertions: 18 | 15 passed | 3 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.main.cpp.txt b/examples/all_features/test_output/main.cpp.txt
similarity index 73%
rename from examples/all_features/test_output/all_features.main.cpp.txt
rename to examples/all_features/test_output/main.cpp.txt
index 589d379..ef42e86 100644
--- a/examples/all_features/test_output/all_features.main.cpp.txt
+++ b/examples/all_features/test_output/main.cpp.txt
@@ -1,5 +1,5 @@
[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 1 | 1 passed | 0 failed | 20 skipped
+[doctest] test cases: 1 | 1 passed | 0 failed |
[doctest] assertions: 1 | 1 passed | 0 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.stringification.cpp.txt b/examples/all_features/test_output/stringification.cpp.txt
similarity index 93%
rename from examples/all_features/test_output/all_features.stringification.cpp.txt
rename to examples/all_features/test_output/stringification.cpp.txt
index 7a7bdf5..3250acb 100644
--- a/examples/all_features/test_output/all_features.stringification.cpp.txt
+++ b/examples/all_features/test_output/stringification.cpp.txt
@@ -36,6 +36,6 @@
int: 5
===============================================================================
-[doctest] test cases: 2 | 0 passed | 2 failed | 19 skipped
+[doctest] test cases: 2 | 0 passed | 2 failed |
[doctest] assertions: 4 | 0 passed | 4 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.subcases.cpp.txt b/examples/all_features/test_output/subcases.cpp.txt
similarity index 94%
rename from examples/all_features/test_output/all_features.subcases.cpp.txt
rename to examples/all_features/test_output/subcases.cpp.txt
index 3fe1886..cb1e8e7 100644
--- a/examples/all_features/test_output/all_features.subcases.cpp.txt
+++ b/examples/all_features/test_output/subcases.cpp.txt
@@ -52,6 +52,6 @@
CHECK( 84 == 85 )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed | 17 skipped
+[doctest] test cases: 4 | 1 passed | 3 failed |
[doctest] assertions: 18 | 15 passed | 3 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.subcases.cpp.txt b/examples/all_features/test_output/templated_test_cases.cpp.txt
similarity index 80%
copy from examples/all_features/test_output/all_features.subcases.cpp.txt
copy to examples/all_features/test_output/templated_test_cases.cpp.txt
index 3fe1886..5d97a25 100644
--- a/examples/all_features/test_output/all_features.subcases.cpp.txt
+++ b/examples/all_features/test_output/templated_test_cases.cpp.txt
@@ -11,7 +11,7 @@
root
2
== TEST CASE ==================================================================
-subcases.cpp(0)
+templated_test_cases.cpp(0)
lots of nested subcases
TEST CASE FAILED!
@@ -19,39 +19,39 @@
unknown exception
== TEST CASE ==================================================================
-subcases.cpp(0)
+templated_test_cases.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: the size is increased
Then: the size and capacity change
-subcases.cpp(0) ERROR!
+templated_test_cases.cpp(0) ERROR!
CHECK( v.size() == 20 )
with expansion:
CHECK( 10 == 20 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+templated_test_cases.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: less capacity is reserved
Then: neither size nor capacity are changed
-subcases.cpp(0) ERROR!
+templated_test_cases.cpp(0) ERROR!
CHECK( v.size() == 10 )
with expansion:
CHECK( 5 == 10 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+templated_test_cases.cpp(0)
test with a fixture - 2
-subcases.cpp(0) ERROR!
+templated_test_cases.cpp(0) ERROR!
CHECK( data == 85 )
with expansion:
CHECK( 84 == 85 )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed | 17 skipped
+[doctest] test cases: 4 | 1 passed | 3 failed |
[doctest] assertions: 18 | 15 passed | 3 failed |
Program code.
diff --git a/examples/all_features/test_output/all_features.subcases.cpp.txt b/examples/all_features/test_output/test_suites.cpp.txt
similarity index 84%
copy from examples/all_features/test_output/all_features.subcases.cpp.txt
copy to examples/all_features/test_output/test_suites.cpp.txt
index 3fe1886..c2f42ab 100644
--- a/examples/all_features/test_output/all_features.subcases.cpp.txt
+++ b/examples/all_features/test_output/test_suites.cpp.txt
@@ -11,7 +11,7 @@
root
2
== TEST CASE ==================================================================
-subcases.cpp(0)
+test_suites.cpp(0)
lots of nested subcases
TEST CASE FAILED!
@@ -19,39 +19,39 @@
unknown exception
== TEST CASE ==================================================================
-subcases.cpp(0)
+test_suites.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: the size is increased
Then: the size and capacity change
-subcases.cpp(0) ERROR!
+test_suites.cpp(0) ERROR!
CHECK( v.size() == 20 )
with expansion:
CHECK( 10 == 20 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+test_suites.cpp(0)
Scenario: vectors can be sized and resized
Given: A vector with some items
When: less capacity is reserved
Then: neither size nor capacity are changed
-subcases.cpp(0) ERROR!
+test_suites.cpp(0) ERROR!
CHECK( v.size() == 10 )
with expansion:
CHECK( 5 == 10 )
== TEST CASE ==================================================================
-subcases.cpp(0)
+test_suites.cpp(0)
test with a fixture - 2
-subcases.cpp(0) ERROR!
+test_suites.cpp(0) ERROR!
CHECK( data == 85 )
with expansion:
CHECK( 84 == 85 )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed | 17 skipped
+[doctest] test cases: 6 | 3 passed | 3 failed |
[doctest] assertions: 18 | 15 passed | 3 failed |
Program code.
diff --git a/examples/all_features/test_suites.cpp b/examples/all_features/test_suites.cpp
new file mode 100644
index 0000000..6efebfd
--- /dev/null
+++ b/examples/all_features/test_suites.cpp
@@ -0,0 +1,121 @@
+#include "doctest.h"
+
+TEST_SUITE("meaningless macros") {
+ TEST_CASE("an empty test that will succeed") {}
+
+ TEST_CASE("an empty test that will fail because of an exception") {
+ }
+}
+
+
+
+
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+static int throws(bool in) {
+ if(in)
+#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
+ throw 5;
+#else // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 0;
+#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 42;
+}
+
+TEST_CASE("lots of nested subcases") {
+ cout << endl << "root" << endl;
+ SUBCASE("") {
+ cout << "1" << endl;
+ SUBCASE("") { cout << "1.1" << endl; }
+ }
+ SUBCASE("") {
+ cout << "2" << endl;
+ SUBCASE("") { cout << "2.1" << endl; }
+ SUBCASE("") {
+ // whops! all the subcases below shouldn't be discovered and executed!
+ throws(true);
+
+ cout << "2.2" << endl;
+ SUBCASE("") {
+ cout << "2.2.1" << endl;
+ SUBCASE("") { cout << "2.2.1.1" << endl; }
+ SUBCASE("") { cout << "2.2.1.2" << endl; }
+ }
+ }
+ SUBCASE("") { cout << "2.3" << endl; }
+ SUBCASE("") { cout << "2.4" << endl; }
+ }
+}
+
+SCENARIO("vectors can be sized and resized") {
+ GIVEN("A vector with some items") {
+ std::vector<int> v(5);
+
+ REQUIRE(v.size() == 5);
+ REQUIRE(v.capacity() >= 5);
+
+ WHEN("the size is increased") {
+ v.resize(10);
+
+ THEN("the size and capacity change") {
+ CHECK(v.size() == 20);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("the size is reduced") {
+ v.resize(0);
+
+ THEN("the size changes but not capacity") {
+ CHECK(v.size() == 0);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ WHEN("more capacity is reserved") {
+ v.reserve(10);
+
+ THEN("the capacity changes but not the size") {
+ CHECK(v.size() == 5);
+ CHECK(v.capacity() >= 10);
+ }
+ }
+ WHEN("less capacity is reserved") {
+ v.reserve(0);
+
+ THEN("neither size nor capacity are changed") {
+ CHECK(v.size() == 10);
+ CHECK(v.capacity() >= 5);
+ }
+ }
+ }
+}
+
+// to silence GCC warnings when inheriting from the class TheFixture which has no virtual destructor
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic ignored "-Weffc++"
+#endif // __GNUC__
+
+struct TheFixture
+{
+ int data;
+ TheFixture()
+ : data(42) {
+ // setup here
+ }
+
+ ~TheFixture() {
+ // teardown here
+ }
+};
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 1") {
+ data /= 2;
+ CHECK(data == 21);
+}
+
+TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 2") {
+ data *= 2;
+ CHECK(data == 85);
+}
diff --git a/examples/exe_with_static_libs/CMakeLists.txt b/examples/exe_with_static_libs/CMakeLists.txt
index cd0eae8..5b30d51 100644
--- a/examples/exe_with_static_libs/CMakeLists.txt
+++ b/examples/exe_with_static_libs/CMakeLists.txt
@@ -3,13 +3,17 @@
doctest_add_library(lib_1 STATIC lib_1_src1.cpp lib_1_src2.cpp)
target_link_libraries(lib_1 doctest)
+set_target_properties(lib_1 PROPERTIES FOLDER ${PROJECT_NAME})
+
doctest_add_library(lib_2 STATIC lib_2_src.cpp)
target_link_libraries(lib_2 doctest)
+set_target_properties(lib_2 PROPERTIES FOLDER ${PROJECT_NAME})
doctest_add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} doctest)
target_link_libraries(${PROJECT_NAME} lib_1)
target_link_libraries(${PROJECT_NAME} lib_2)
+set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER ${PROJECT_NAME})
doctest_add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
diff --git a/examples/executable_dll_and_plugin/CMakeLists.txt b/examples/executable_dll_and_plugin/CMakeLists.txt
index d2651e9..1bf80ae 100644
--- a/examples/executable_dll_and_plugin/CMakeLists.txt
+++ b/examples/executable_dll_and_plugin/CMakeLists.txt
@@ -11,19 +11,23 @@
doctest_add_library(implementation SHARED implementation.cpp implementation_2.cpp)
target_link_libraries(implementation doctest)
+set_target_properties(implementation PROPERTIES FOLDER ${PROJECT_NAME})
doctest_add_library(dll SHARED dll.cpp)
target_link_libraries(dll doctest)
target_link_libraries(dll implementation)
+set_target_properties(dll PROPERTIES FOLDER ${PROJECT_NAME})
doctest_add_library(plugin SHARED plugin.cpp)
target_link_libraries(plugin doctest)
target_link_libraries(plugin implementation)
+set_target_properties(plugin PROPERTIES FOLDER ${PROJECT_NAME})
doctest_add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} doctest)
target_link_libraries(${PROJECT_NAME} dll)
target_link_libraries(${PROJECT_NAME} implementation)
+set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER ${PROJECT_NAME})
if(NOT WIN32)
target_link_libraries(${PROJECT_NAME} dl)
diff --git a/scripts/cmake/common.cmake b/scripts/cmake/common.cmake
index 7dd4015..00a95c9 100644
--- a/scripts/cmake/common.cmake
+++ b/scripts/cmake/common.cmake
@@ -8,6 +8,8 @@
# cache this for use inside of the function
set(CURRENT_LIST_DIR_CACHED ${CMAKE_CURRENT_LIST_DIR})
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
enable_testing()
set(DOCTEST_TEST_MODE "COMPARE" CACHE STRING "Test mode - normal/run through valgrind/collect output/compare with output")