diff options
author | onqtam <vik.kirilov@gmail.com> | 2017-04-17 10:46:55 +0300 |
---|---|---|
committer | onqtam <vik.kirilov@gmail.com> | 2017-05-16 00:22:21 +0300 |
commit | 119cfb6fe19225427a4561a105ac13b031ab691e (patch) | |
tree | f718651bc80788bd55e72109189233f982830b18 /examples | |
parent | e0f18802cb6c036faf7a3690a92f05c5f90a9b87 (diff) |
- 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
Diffstat (limited to 'examples')
17 files changed, 531 insertions, 10 deletions
diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt index d47b7abe..68e089d0 100644 --- a/examples/all_features/CMakeLists.txt +++ b/examples/all_features/CMakeLists.txt @@ -9,6 +9,9 @@ set(files assertion_macros.cpp stringification.cpp subcases.cpp + logging.cpp + templated_test_cases.cpp + test_suites.cpp ) # add the normal build @@ -18,7 +21,7 @@ target_link_libraries(${PROJECT_NAME} doctest) # 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 00000000..9a66397d --- /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 8dd9e365..63bf98eb 100644 --- a/examples/all_features/main.cpp +++ b/examples/all_features/main.cpp @@ -29,8 +29,6 @@ int main(int argc, char** argv) { 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 00000000..9a66397d --- /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 index c76c4b0c..e20c8f43 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 index 094bcea1..f114ac80 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 @@ threw exception: 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 index 45375eec..614f6c6f 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 @@ threw exception: 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 index c8a806b6..eca69f05 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/logging.cpp.txt b/examples/all_features/test_output/logging.cpp.txt new file mode 100644 index 00000000..bf8d1613 --- /dev/null +++ b/examples/all_features/test_output/logging.cpp.txt @@ -0,0 +1,57 @@ +[doctest] run with "--help" for options + +root +1 +1.1 + +root +2 +2.1 + +root +2 +== TEST CASE ================================================================== +logging.cpp(0) +lots of nested subcases + +TEST CASE FAILED! +threw exception: + unknown exception + +== TEST CASE ================================================================== +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 + +logging.cpp(0) ERROR! + CHECK( v.size() == 20 ) +with expansion: + CHECK( 10 == 20 ) + +== TEST CASE ================================================================== +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 + +logging.cpp(0) ERROR! + CHECK( v.size() == 10 ) +with expansion: + CHECK( 5 == 10 ) + +== TEST CASE ================================================================== +logging.cpp(0) +test with a fixture - 2 + +logging.cpp(0) ERROR! + CHECK( data == 85 ) +with expansion: + CHECK( 84 == 85 ) + +=============================================================================== +[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 index 589d3798..ef42e866 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 index 7a7bdf5f..3250acb0 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 @@ threw exception: 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 index 3fe18864..cb1e8e79 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 @@ 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/templated_test_cases.cpp.txt b/examples/all_features/test_output/templated_test_cases.cpp.txt new file mode 100644 index 00000000..5d97a251 --- /dev/null +++ b/examples/all_features/test_output/templated_test_cases.cpp.txt @@ -0,0 +1,57 @@ +[doctest] run with "--help" for options + +root +1 +1.1 + +root +2 +2.1 + +root +2 +== TEST CASE ================================================================== +templated_test_cases.cpp(0) +lots of nested subcases + +TEST CASE FAILED! +threw exception: + unknown exception + +== TEST CASE ================================================================== +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 + +templated_test_cases.cpp(0) ERROR! + CHECK( v.size() == 20 ) +with expansion: + CHECK( 10 == 20 ) + +== TEST CASE ================================================================== +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 + +templated_test_cases.cpp(0) ERROR! + CHECK( v.size() == 10 ) +with expansion: + CHECK( 5 == 10 ) + +== TEST CASE ================================================================== +templated_test_cases.cpp(0) +test with a fixture - 2 + +templated_test_cases.cpp(0) ERROR! + CHECK( data == 85 ) +with expansion: + CHECK( 84 == 85 ) + +=============================================================================== +[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/test_suites.cpp.txt b/examples/all_features/test_output/test_suites.cpp.txt new file mode 100644 index 00000000..c2f42ab1 --- /dev/null +++ b/examples/all_features/test_output/test_suites.cpp.txt @@ -0,0 +1,57 @@ +[doctest] run with "--help" for options + +root +1 +1.1 + +root +2 +2.1 + +root +2 +== TEST CASE ================================================================== +test_suites.cpp(0) +lots of nested subcases + +TEST CASE FAILED! +threw exception: + unknown exception + +== TEST CASE ================================================================== +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 + +test_suites.cpp(0) ERROR! + CHECK( v.size() == 20 ) +with expansion: + CHECK( 10 == 20 ) + +== TEST CASE ================================================================== +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 + +test_suites.cpp(0) ERROR! + CHECK( v.size() == 10 ) +with expansion: + CHECK( 5 == 10 ) + +== TEST CASE ================================================================== +test_suites.cpp(0) +test with a fixture - 2 + +test_suites.cpp(0) ERROR! + CHECK( data == 85 ) +with expansion: + CHECK( 84 == 85 ) + +=============================================================================== +[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 00000000..6efebfd2 --- /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 cd0eae85..5b30d511 100644 --- a/examples/exe_with_static_libs/CMakeLists.txt +++ b/examples/exe_with_static_libs/CMakeLists.txt @@ -3,13 +3,17 @@ project(${PROJECT_NAME}) 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 d2651e9e..1bf80ae4 100644 --- a/examples/executable_dll_and_plugin/CMakeLists.txt +++ b/examples/executable_dll_and_plugin/CMakeLists.txt @@ -11,19 +11,23 @@ endif() 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) |