examples almost done! only assertion_macros.cpp is left
diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt
index 1fd8d6d..47a7035 100644
--- a/examples/all_features/CMakeLists.txt
+++ b/examples/all_features/CMakeLists.txt
@@ -1,10 +1,14 @@
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})
+################################################################################
+## BUILD ALL EXAMPLE SOURCES INTO A SINGLE BINARY AND EXECUTE TESTS ON EACH FILE
+################################################################################
+
set(files
main.cpp
doctest_proxy.h
- header_with_tests.h
+ header.h
coverage_maxout.cpp
alternative_macros.cpp
assertion_macros.cpp
@@ -15,7 +19,6 @@
test_suites.cpp
)
-# add the normal build
doctest_add_executable(${PROJECT_NAME} ${files})
target_compile_definitions(${PROJECT_NAME} PRIVATE DOCTEST_CONFIG_COLORS_NONE) # easy way to fix test coverage
@@ -45,10 +48,15 @@
#doctest_add_test(NAME order_2 COMMAND $<TARGET_FILE:${PROJECT_NAME}> -ob=name)
#doctest_add_test(NAME order_3 COMMAND $<TARGET_FILE:${PROJECT_NAME}> -ob=rand -rs=324 -sfe=*) # sfe=* to exclude all tests for no output
-# add variation of the build with disabled tests - should still compile
+################################################################################
+## VARIATION OF THE BUILD WITH DOCTEST DISABLED - SHOULD STILL COMPILE
+################################################################################
+
doctest_add_executable(disabled ${files})
target_compile_definitions(disabled PRIVATE DOCTEST_CONFIG_DISABLE)
+
doctest_add_test(NAME disabled COMMAND $<TARGET_FILE:disabled>)
+
# TODO: think about fixing these in a different way! - see issue #61 or commit 6b61e8aa3818c5ea100cedc1bb48a60ea10df6e8
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(disabled PRIVATE /wd4505) # unreferenced local function has been removed
diff --git a/examples/all_features/assertion_macros.cpp b/examples/all_features/assertion_macros.cpp
index 9d339af..0be79ad 100644
--- a/examples/all_features/assertion_macros.cpp
+++ b/examples/all_features/assertion_macros.cpp
@@ -1,41 +1,24 @@
#include "doctest.h"
+#include "header.h"
+
#include <stdexcept>
-template <typename T>
-static int conditional_throw(bool in, const T& ex) {
- if(in)
-#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
- throw ex;
-#else // DOCTEST_CONFIG_NO_EXCEPTIONS
- ((void)ex);
-#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
- return 42;
+TEST_CASE("an empty test that will succeed") {}
+
+TEST_CASE("an empty test that will fail because of an exception") {
+ throw_if(true, 0);
}
-using doctest::Approx;
-
-TEST_SUITE("meaningless macros") {
- TEST_CASE("an empty test that will succeed") {}
-
- TEST_CASE("an empty test that will fail because of an exception") {
- conditional_throw(true, 0);
- }
-}
-
-TEST_SUITE_BEGIN("meaningless macros");
-
TEST_CASE("an empty test that will fail because of a std::exception") {
- conditional_throw(true, std::runtime_error("whops!"));
+ throw_if(true, std::runtime_error("whops!"));
}
-TEST_SUITE_END();
-
TEST_CASE("normal macros") {
int a = 5;
int b = 5;
- CHECK(conditional_throw(true, std::runtime_error("whops!")) == 42);
+ CHECK(throw_if(true, std::runtime_error("whops!")) == 42);
CHECK_FALSE(!(a == b));
@@ -45,52 +28,26 @@
FAST_CHECK_EQ(a, b);
- // commented out because 32 vs 64 bit builds will fail when the output is compared
- //WARN(reinterpret_cast<void*>(1000) == reinterpret_cast<void*>(1004));
+ CHECK(doctest::Approx(0.1000001) == 0.1000002);
+ CHECK(doctest::Approx(0.502) == 0.501);
- CHECK(Approx(0.1000001) == 0.1000002);
- CHECK(Approx(0.502) == 0.501);
-
- conditional_throw(true, 0);
-}
-
-TEST_CASE("normal macros with std::exception") {
- int a = 5;
- int b = 5;
-
- CHECK(conditional_throw(true, 0) == 42);
-
- CHECK_FALSE(!(a == b));
-
- REQUIRE(a == b);
-
- CHECK_EQ(a, b);
-
- FAST_CHECK_EQ(a, b);
-
- // commented out because 32 vs 64 bit builds will fail when the output is compared
- //WARN(reinterpret_cast<void*>(1000) == reinterpret_cast<void*>(1004));
-
- CHECK(Approx(0.1000001) == 0.1000002);
- CHECK(Approx(0.502) == 0.501);
-
- conditional_throw(true, 0);
+ throw_if(true, 0);
}
TEST_CASE("exceptions-related macros") {
- CHECK_THROWS(conditional_throw(false, 0));
- CHECK_THROWS_AS(conditional_throw(false, 0), int);
- CHECK_THROWS_AS(conditional_throw(true, 0), int);
- CHECK_THROWS_AS(conditional_throw(true, 0), char);
+ CHECK_THROWS(throw_if(false, 0));
+ CHECK_THROWS_AS(throw_if(false, 0), int);
+ CHECK_THROWS_AS(throw_if(true, 0), int);
+ CHECK_THROWS_AS(throw_if(true, 0), char);
- CHECK_NOTHROW(conditional_throw(true, 0));
+ CHECK_NOTHROW(throw_if(true, 0));
}
TEST_CASE("exceptions-related macros for std::exception") {
- CHECK_THROWS(conditional_throw(false, 0));
- CHECK_THROWS_AS(conditional_throw(false, std::runtime_error("whops!")), std::exception);
- CHECK_THROWS_AS(conditional_throw(true, std::runtime_error("whops!")), std::exception);
- CHECK_THROWS_AS(conditional_throw(true, std::runtime_error("whops!")), int);
+ CHECK_THROWS(throw_if(false, 0));
+ CHECK_THROWS_AS(throw_if(false, std::runtime_error("whops!")), std::exception&);
+ CHECK_THROWS_AS(throw_if(true, std::runtime_error("whops!")), std::exception&);
+ CHECK_THROWS_AS(throw_if(true, std::runtime_error("whops!")), int);
- REQUIRE_NOTHROW(conditional_throw(true, std::runtime_error("whops!")));
+ REQUIRE_NOTHROW(throw_if(true, std::runtime_error("whops!")));
}
diff --git a/examples/all_features/coverage_maxout.cpp b/examples/all_features/coverage_maxout.cpp
index b88e970..4e91f06 100644
--- a/examples/all_features/coverage_maxout.cpp
+++ b/examples/all_features/coverage_maxout.cpp
@@ -1,10 +1,14 @@
#include "doctest.h"
+#include "header.h"
+
#include <ostream>
#include <sstream>
+/*
+
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
-#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+//#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif // > gcc 4.6
#ifndef DOCTEST_CONFIG_DISABLE
@@ -45,16 +49,6 @@
using doctest::Approx;
-static int throws(bool in) {
- if(in)
-#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
- throw false;
-#else // DOCTEST_CONFIG_NO_EXCEPTIONS
- return 0;
-#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
- return 42;
-}
-
struct myType
{
myType() {}
@@ -165,3 +159,5 @@
TEST_SUITE_END();
#endif // DOCTEST_CONFIG_DISABLE
+
+*/
diff --git a/examples/all_features/header.h b/examples/all_features/header.h
new file mode 100644
index 0000000..83ff6c4
--- /dev/null
+++ b/examples/all_features/header.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "doctest.h"
+
+// helper for throwing exceptions
+
+template <typename T>
+int throw_if(bool in, const T& ex) {
+ if(in)
+#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
+ throw ex;
+#else // DOCTEST_CONFIG_NO_EXCEPTIONS
+ ((void)ex);
+#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
+ return 42;
+}
+
+// stuff that should be fine when used in a header - test cases for example should be registered only once
+
+TEST_SUITE("some TS") {
+ TEST_CASE("in TS") {
+ FAIL("");
+ }
+}
+
+REGISTER_EXCEPTION_TRANSLATOR(int& in) {
+ return doctest::toString(in);
+}
+
+TYPE_TO_STRING(doctest::String);
+
+TEST_CASE_TEMPLATE("template 1", T, doctest::Types<char>) {
+ FAIL("");
+}
+
+TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) {
+ FAIL("");
+}
+
+TEST_CASE_TEMPLATE_INSTANTIATE(header_test, doctest::Types<doctest::String>);
+
+// to silence GCC warnings when inheriting from the class SomeFixture which has no virtual destructor
+//#if defined(__GNUC__) && !defined(__clang__)
+//#pragma GCC diagnostic ignored "-Weffc++"
+//#endif // __GNUC__
+
+struct SomeFixture
+{
+ int data;
+ SomeFixture()
+ : data(42) {
+ // setup here
+ }
+
+ ~SomeFixture() {
+ // teardown here
+ }
+};
+
+TEST_CASE_FIXTURE(SomeFixture, "fixtured test") {
+ data /= 2;
+ CHECK(data == 21);
+}
diff --git a/examples/all_features/header_with_tests.h b/examples/all_features/header_with_tests.h
deleted file mode 100644
index b10dc34..0000000
--- a/examples/all_features/header_with_tests.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "doctest.h"
-
-#include <iostream>
-#include <vector>
-using namespace std;
-
-typedef doctest::Types<char, short, int> the_types;
-
-TEST_CASE_TEMPLATE("signed integers stuff", T, the_types) {
- T var = T();
- --var;
- CHECK(var == -1);
-}
-
-
-
-
-TYPE_TO_STRING(std::vector<int>);
-
-
-
-
-
-
-
-
-TEST_CASE_TEMPLATE_DEFINE("default construction", T, test_id) {
- T var = T();
- CHECK(var == T());
-}
-
-TEST_CASE_TEMPLATE_INSTANTIATE(test_id, the_types);
-TEST_CASE_TEMPLATE_INSTANTIATE(test_id, doctest::Types<float, double>);
diff --git a/examples/all_features/logging.cpp b/examples/all_features/logging.cpp
index 9a66397..889b118 100644
--- a/examples/all_features/logging.cpp
+++ b/examples/all_features/logging.cpp
@@ -3,108 +3,3 @@
#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 63bf98e..e5d227a 100644
--- a/examples/all_features/main.cpp
+++ b/examples/all_features/main.cpp
@@ -1,6 +1,8 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
+#include "header.h"
+
int program();
int main(int argc, char** argv) {
diff --git a/examples/all_features/stringification.cpp b/examples/all_features/stringification.cpp
index 8dda581..a70cd47 100644
--- a/examples/all_features/stringification.cpp
+++ b/examples/all_features/stringification.cpp
@@ -1,5 +1,7 @@
#include "doctest.h"
+#include "header.h"
+
#include <string>
#include <vector>
#include <list>
@@ -42,20 +44,9 @@
}
// to silence GCC warnings when inheriting from the class MyType which has no virtual destructor
-#if defined(__GNUC__) && !defined(__clang__)
-#pragma GCC diagnostic ignored "-Weffc++"
-#endif // __GNUC__
-
-template <typename T>
-static int conditional_throw(bool in, const T& ex) {
- if(in)
-#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
- throw ex;
-#else // DOCTEST_CONFIG_NO_EXCEPTIONS
- ((void)ex);
-#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
- return 42;
-}
+//#if defined(__GNUC__) && !defined(__clang__)
+//#pragma GCC diagnostic ignored "-Weffc++"
+//#endif // __GNUC__
template <typename T, typename K>
struct MyType
@@ -86,9 +77,8 @@
friend bool operator==(const Foo&, const Foo&) { return false; }
};
-doctest::String toString(const Foo&); // to silence -Wmissing-declarations
// as a third option you may provide an overload of toString()
-doctest::String toString(const Foo&) { return "Foo{}"; }
+inline doctest::String toString(const Foo&) { return "Foo{}"; }
} // namespace Bar
// set an exception translator for MyTypeInherited<int>
@@ -97,7 +87,7 @@
doctest::toString(ex.two) + ")";
}
-TEST_CASE("the only test") {
+TEST_CASE("all asserts should fail and show how the objects get stringified") {
MyTypeInherited<int> bla1;
bla1.one = 5;
bla1.two = 4.0f;
@@ -140,7 +130,7 @@
CHECK(lst_1 == lst_2);
// lets see if this exception gets translated
- conditional_throw(true, bla1);
+ throw_if(true, bla1);
}
static doctest::String intTranslator(int ex) {
@@ -149,8 +139,8 @@
TEST_CASE("a test case that registers an exception translator for int and then throws one") {
// set an exception translator for int - note that this shouldn't be done in a test case but
- // in main() or somewhere before executing the tests - but here I'm lazy to write my own main...
+ // in main() or somewhere before executing the tests - but here I'm just lazy...
doctest::registerExceptionTranslator(intTranslator);
- conditional_throw(true, 5);
+ throw_if(true, 5);
}
diff --git a/examples/all_features/subcases.cpp b/examples/all_features/subcases.cpp
index 9a66397..c760d8b 100644
--- a/examples/all_features/subcases.cpp
+++ b/examples/all_features/subcases.cpp
@@ -1,19 +1,11 @@
#include "doctest.h"
+#include "header.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("") {
@@ -25,7 +17,7 @@
SUBCASE("") { cout << "2.1" << endl; }
SUBCASE("") {
// whops! all the subcases below shouldn't be discovered and executed!
- throws(true);
+ FAIL("");
cout << "2.2" << endl;
SUBCASE("") {
@@ -80,31 +72,3 @@
}
}
}
-
-// 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/assertion_macros.cpp.txt b/examples/all_features/test_output/assertion_macros.cpp.txt
index f114ac8..74d2469 100644
--- a/examples/all_features/test_output/assertion_macros.cpp.txt
+++ b/examples/all_features/test_output/assertion_macros.cpp.txt
@@ -5,7 +5,7 @@
TEST CASE FAILED!
threw exception:
- unknown exception
+ 0
== TEST CASE ==================================================================
assertion_macros.cpp(0)
@@ -20,82 +20,64 @@
normal macros
assertion_macros.cpp(0) ERROR!
- CHECK( conditional_throw(true, std::runtime_error("whops!")) == 42 )
+ CHECK( throw_if(true, std::runtime_error("whops!")) == 42 )
threw exception:
whops!
assertion_macros.cpp(0) ERROR!
- CHECK( Approx(0.502) == 0.501 )
+ CHECK( doctest::Approx(0.502) == 0.501 )
with expansion:
CHECK( Approx( 0.502 ) == 0.501 )
TEST CASE FAILED!
threw exception:
- unknown exception
-
-== TEST CASE ==================================================================
-assertion_macros.cpp(0)
-normal macros with std::exception
-
-assertion_macros.cpp(0) ERROR!
- CHECK( conditional_throw(true, 0) == 42 )
-threw exception:
- unknown exception
-
-assertion_macros.cpp(0) ERROR!
- CHECK( Approx(0.502) == 0.501 )
-with expansion:
- CHECK( Approx( 0.502 ) == 0.501 )
-
-TEST CASE FAILED!
-threw exception:
- unknown exception
+ 0
== TEST CASE ==================================================================
assertion_macros.cpp(0)
exceptions-related macros
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS( conditional_throw(false, 0) )
+ CHECK_THROWS( throw_if(false, 0) )
didn't throw at all
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS_AS( conditional_throw(false, 0), int )
+ CHECK_THROWS_AS( throw_if(false, 0), int )
didn't throw at all
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS_AS( conditional_throw(true, 0), char )
+ CHECK_THROWS_AS( throw_if(true, 0), char )
threw a different exception:
- unknown exception
+ 0
assertion_macros.cpp(0) ERROR!
- CHECK_NOTHROW( conditional_throw(true, 0) )
+ CHECK_NOTHROW( throw_if(true, 0) )
threw exception:
- unknown exception
+ 0
== TEST CASE ==================================================================
assertion_macros.cpp(0)
exceptions-related macros for std::exception
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS( conditional_throw(false, 0) )
+ CHECK_THROWS( throw_if(false, 0) )
didn't throw at all
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS_AS( conditional_throw(false, std::runtime_error("whops!")), std::exception )
+ CHECK_THROWS_AS( throw_if(false, std::runtime_error("whops!")), std::exception& )
didn't throw at all
assertion_macros.cpp(0) ERROR!
- CHECK_THROWS_AS( conditional_throw(true, std::runtime_error("whops!")), int )
+ CHECK_THROWS_AS( throw_if(true, std::runtime_error("whops!")), int )
threw a different exception:
whops!
assertion_macros.cpp(0) FATAL ERROR!
- REQUIRE_NOTHROW( conditional_throw(true, std::runtime_error("whops!")) )
+ REQUIRE_NOTHROW( throw_if(true, std::runtime_error("whops!")) )
threw exception:
whops!
===============================================================================
-[doctest] test cases: 7 | 1 passed | 6 failed |
-[doctest] assertions: 24 | 12 passed | 12 failed |
+[doctest] test cases: 6 | 1 passed | 5 failed |
+[doctest] assertions: 17 | 7 passed | 10 failed |
Program code.
diff --git a/examples/all_features/test_output/coverage_maxout.cpp.txt b/examples/all_features/test_output/coverage_maxout.cpp.txt
index 614f6c6..eca69f0 100644
--- a/examples/all_features/test_output/coverage_maxout.cpp.txt
+++ b/examples/all_features/test_output/coverage_maxout.cpp.txt
@@ -1,59 +1,5 @@
[doctest] run with "--help" for options
-== TEST CASE ==================================================================
-coverage_maxout.cpp(0)
-assertions
-
-coverage_maxout.cpp(0) ERROR!
- CHECK( 1 == 0 )
-with expansion:
- CHECK( 1 == 0 )
-
-coverage_maxout.cpp(0) ERROR!
- CHECK_FALSE( 1 )
-with expansion:
- CHECK_FALSE( 1 )
-
-coverage_maxout.cpp(0) ERROR!
- CHECK( a == b )
-with expansion:
- CHECK( myType! == myType! )
-
-coverage_maxout.cpp(0) ERROR!
- CHECK( Approx(0.1) == 0.2 )
-with expansion:
- CHECK( Approx( 0.1 ) == 0.2 )
-
-coverage_maxout.cpp(0) ERROR!
- CHECK_THROWS( throws(false) )
-didn't throw at all
-
-coverage_maxout.cpp(0) ERROR!
- CHECK_NOTHROW( throws(true) )
-threw exception:
- unknown exception
-
-coverage_maxout.cpp(0) FATAL ERROR!
- REQUIRE_THROWS_AS( throws(false), bool )
-didn't throw at all
-
-== TEST CASE ==================================================================
-coverage_maxout.cpp(0)
-assertions - all of them
-
-coverage_maxout.cpp(0) FATAL ERROR!
- FAST_REQUIRE_UNARY_FALSE( 1 )
-with expansion:
- FAST_REQUIRE_UNARY_FALSE( 1 )
-
-== TEST CASE ==================================================================
-coverage_maxout.cpp(0)
-throws
-
-TEST CASE FAILED!
-threw exception:
- unknown exception
-
===============================================================================
-[doctest] test cases: 5 | 2 passed | 3 failed |
-[doctest] assertions: 60 | 52 passed | 8 failed |
+[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/header.h.txt b/examples/all_features/test_output/header.h.txt
new file mode 100644
index 0000000..d096dca
--- /dev/null
+++ b/examples/all_features/test_output/header.h.txt
@@ -0,0 +1,23 @@
+[doctest] run with "--help" for options
+== TEST CASE ==================================================================
+header.h(0)
+in TS
+
+header.h(0) FATAL ERROR!
+
+== TEST CASE ==================================================================
+header.h(0)
+template 1<char>
+
+header.h(0) FATAL ERROR!
+
+== TEST CASE ==================================================================
+header.h(0)
+template 2<doctest::String>
+
+header.h(0) FATAL ERROR!
+
+===============================================================================
+[doctest] test cases: 4 | 1 passed | 3 failed |
+[doctest] assertions: 1 | 1 passed | 0 failed |
+Program code.
diff --git a/examples/all_features/test_output/header_with_tests.h.txt b/examples/all_features/test_output/header_with_tests.h.txt
deleted file mode 100644
index eca69f0..0000000
--- a/examples/all_features/test_output/header_with_tests.h.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-[doctest] run with "--help" for options
-===============================================================================
-[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
index bf8d161..eca69f0 100644
--- a/examples/all_features/test_output/logging.cpp.txt
+++ b/examples/all_features/test_output/logging.cpp.txt
@@ -1,57 +1,5 @@
[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 |
+[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/stringification.cpp.txt b/examples/all_features/test_output/stringification.cpp.txt
index 3250acb..058fc0f 100644
--- a/examples/all_features/test_output/stringification.cpp.txt
+++ b/examples/all_features/test_output/stringification.cpp.txt
@@ -1,7 +1,7 @@
[doctest] run with "--help" for options
== TEST CASE ==================================================================
stringification.cpp(0)
-the only test
+all asserts should fail and show how the objects get stringified
stringification.cpp(0) ERROR!
CHECK( f1 == f2 )
@@ -33,7 +33,7 @@
TEST CASE FAILED!
threw exception:
- int: 5
+ 5
===============================================================================
[doctest] test cases: 2 | 0 passed | 2 failed |
diff --git a/examples/all_features/test_output/subcases.cpp.txt b/examples/all_features/test_output/subcases.cpp.txt
index cb1e8e7..adfffb1 100644
--- a/examples/all_features/test_output/subcases.cpp.txt
+++ b/examples/all_features/test_output/subcases.cpp.txt
@@ -14,9 +14,7 @@
subcases.cpp(0)
lots of nested subcases
-TEST CASE FAILED!
-threw exception:
- unknown exception
+subcases.cpp(0) FATAL ERROR!
== TEST CASE ==================================================================
subcases.cpp(0)
@@ -42,16 +40,7 @@
with expansion:
CHECK( 5 == 10 )
-== TEST CASE ==================================================================
-subcases.cpp(0)
-test with a fixture - 2
-
-subcases.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 |
+[doctest] test cases: 2 | 0 passed | 2 failed |
+[doctest] assertions: 16 | 14 passed | 2 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
index c2f42ab..72a0678 100644
--- a/examples/all_features/test_output/test_suites.cpp.txt
+++ b/examples/all_features/test_output/test_suites.cpp.txt
@@ -1,57 +1,35 @@
[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
+not part of a test suite
-TEST CASE FAILED!
-threw exception:
- unknown exception
+test_suites.cpp(0) FATAL ERROR!
== 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
+part of scoped
-test_suites.cpp(0) ERROR!
- CHECK( v.size() == 20 )
-with expansion:
- CHECK( 10 == 20 )
+test_suites.cpp(0) FATAL ERROR!
== 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
+part of scoped 2
-test_suites.cpp(0) ERROR!
- CHECK( v.size() == 10 )
-with expansion:
- CHECK( 5 == 10 )
+test_suites.cpp(0) FATAL ERROR!
== TEST CASE ==================================================================
test_suites.cpp(0)
-test with a fixture - 2
+part of some TS
-test_suites.cpp(0) ERROR!
- CHECK( data == 85 )
-with expansion:
- CHECK( 84 == 85 )
+test_suites.cpp(0) FATAL ERROR!
+
+== TEST CASE ==================================================================
+test_suites.cpp(0)
+not part of a test suite 2
+
+test_suites.cpp(0) FATAL ERROR!
===============================================================================
-[doctest] test cases: 6 | 3 passed | 3 failed |
-[doctest] assertions: 18 | 15 passed | 3 failed |
+[doctest] test cases: 5 | 0 passed | 5 failed |
+[doctest] assertions: 0 | 0 passed | 0 failed |
Program code.
diff --git a/examples/all_features/test_suites.cpp b/examples/all_features/test_suites.cpp
index 6efebfd..f08319c 100644
--- a/examples/all_features/test_suites.cpp
+++ b/examples/all_features/test_suites.cpp
@@ -1,121 +1,27 @@
#include "doctest.h"
-TEST_SUITE("meaningless macros") {
- TEST_CASE("an empty test that will succeed") {}
+TEST_CASE("not part of a test suite") {
+ FAIL("");
+}
- TEST_CASE("an empty test that will fail because of an exception") {
+TEST_SUITE("scoped test suite") {
+ TEST_CASE("part of scoped") {
+ FAIL("");
+ }
+
+ TEST_CASE("part of scoped 2") {
+ FAIL("");
}
}
+TEST_SUITE_BEGIN("some TS"); // begin "some TS"
-
-
-
-#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("part of some TS") {
+ FAIL("");
}
-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);
+TEST_SUITE_END(); // ends "some TS"
- 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);
+TEST_CASE("not part of a test suite 2") {
+ FAIL("");
}