fixed #10
also added an example using the parts of the doctest header (and fixed it to work)
diff --git a/doctest/doctest.h b/doctest/doctest.h
index d406bbe..792bc4c 100644
--- a/doctest/doctest.h
+++ b/doctest/doctest.h
@@ -695,18 +695,18 @@
// registers the test by initializing a dummy var with a function
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_REGISTER_FUNCTION(f, name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name);
#elif defined(__clang__)
#define DOCTEST_REGISTER_FUNCTION(f, name) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name); \
_Pragma("clang diagnostic pop")
#else // MSVC
#define DOCTEST_REGISTER_FUNCTION(f, name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name);
#endif // MSVC
@@ -730,61 +730,60 @@
// for registering tests
#define DOCTEST_TEST_CASE(name) \
- DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for registering tests with a fixture
#define DOCTEST_TEST_CASE_FIXTURE(c, name) \
- DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_CLASS_), c, \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), c, \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for subcases
#if defined(__GNUC__)
#define DOCTEST_SUBCASE(name) \
- if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_SUBCASE_) \
+ if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_ANON_SUBCASE_) \
__attribute__((unused)) = \
doctest::detail::Subcase(name, __FILE__, __LINE__))
#else // __GNUC__
#define DOCTEST_SUBCASE(name) \
- if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_SUBCASE_) = \
+ if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_ANON_SUBCASE_) = \
doctest::detail::Subcase(name, __FILE__, __LINE__))
#endif // __GNUC__
// for starting a testsuite block
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_TEST_SUITE(name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::setTestSuiteName(name); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#elif defined(__clang__)
#define DOCTEST_TEST_SUITE(name) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::setTestSuiteName(name); \
- _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#else // MSVC
#define DOCTEST_TEST_SUITE(name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = doctest::detail::setTestSuiteName(name); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(name); \
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#endif // MSVC
// for ending a testsuite block
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_TEST_SUITE_END \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::setTestSuiteName(""); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#elif defined(__clang__)
-#define DOCTEST_TEST_SUITE_END \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
- doctest::detail::setTestSuiteName(""); \
- _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+#define DOCTEST_TEST_SUITE_END \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(""); \
+ _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#else // MSVC
#define DOCTEST_TEST_SUITE_END \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = doctest::detail::setTestSuiteName(""); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(""); \
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#endif // MSVC
#define DOCTEST_LOG_START() \
@@ -798,19 +797,19 @@
} while(doctest::detail::always_false())
#define DOCTEST_ASSERT_IMPLEMENT(expr, assert_name, false_invert_op) \
- doctest::detail::Result res; \
- bool threw = false; \
+ doctest::detail::Result _DOCTEST_R; \
+ bool _DOCTEST_THREW = false; \
try { \
- res = doctest::detail::ExpressionDecomposer() << expr; \
- } catch(...) { threw = true; } \
+ _DOCTEST_R = doctest::detail::ExpressionDecomposer() << expr; \
+ } catch(...) { _DOCTEST_THREW = true; } \
false_invert_op; \
- if(res || DOCTEST_GCS()->success) { \
+ if(_DOCTEST_R || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssert(res.m_passed, res.m_decomposition.c_str(), threw, #expr, \
- assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssert(_DOCTEST_R.m_passed, _DOCTEST_R.m_decomposition.c_str(), \
+ _DOCTEST_THREW, #expr, assert_name, __FILE__, __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(res) { \
+ if(_DOCTEST_R) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -835,23 +834,24 @@
#define DOCTEST_CHECK(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK", ((void)0))
#define DOCTEST_REQUIRE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE", ((void)0))
-#define DOCTEST_WARN_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "WARN_FALSE", res.invert())
-#define DOCTEST_CHECK_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK_FALSE", res.invert())
-#define DOCTEST_REQUIRE_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE_FALSE", res.invert())
+#define DOCTEST_WARN_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "WARN_FALSE", _DOCTEST_R.invert())
+#define DOCTEST_CHECK_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK_FALSE", _DOCTEST_R.invert())
+#define DOCTEST_REQUIRE_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE_FALSE", _DOCTEST_R.invert()
#define DOCTEST_ASSERT_THROWS(expr, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
+ bool _DOCTEST_THREW = false; \
try { \
expr; \
- } catch(...) { threw = true; } \
- if(!threw || DOCTEST_GCS()->success) { \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(!_DOCTEST_THREW || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertThrows(threw, #expr, assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssertThrows(_DOCTEST_THREW, #expr, assert_name, __FILE__, \
+ __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(!threw) { \
+ if(!_DOCTEST_THREW) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -862,21 +862,21 @@
#define DOCTEST_ASSERT_THROWS_AS(expr, as, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
- bool threw_as = false; \
+ bool _DOCTEST_THREW = false; \
+ bool _DOCTEST_THREW_AS = false; \
try { \
expr; \
} catch(as) { \
- threw = true; \
- threw_as = true; \
- } catch(...) { threw = true; } \
- if(!threw_as || DOCTEST_GCS()->success) { \
+ _DOCTEST_THREW = true; \
+ _DOCTEST_THREW_AS = true; \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(!_DOCTEST_THREW_AS || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertThrowsAs(threw, threw_as, #as, #expr, assert_name, \
- __FILE__, __LINE__); \
+ doctest::detail::logAssertThrowsAs(_DOCTEST_THREW, _DOCTEST_THREW_AS, #as, #expr, \
+ assert_name, __FILE__, __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(!threw_as) { \
+ if(!_DOCTEST_THREW_AS) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -887,16 +887,17 @@
#define DOCTEST_ASSERT_NOTHROW(expr, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
+ bool _DOCTEST_THREW = false; \
try { \
expr; \
- } catch(...) { threw = true; } \
- if(threw || DOCTEST_GCS()->success) { \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(_DOCTEST_THREW || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertNothrow(threw, #expr, assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssertNothrow(_DOCTEST_THREW, #expr, assert_name, __FILE__, \
+ __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(threw) { \
+ if(_DOCTEST_THREW) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -938,21 +939,21 @@
// for registering tests
#define DOCTEST_TEST_CASE(name) \
- DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for registering tests with a fixture
#define DOCTEST_TEST_CASE_FIXTURE(x, name) \
- DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_CLASS_), x, \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), x, \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for subcases
#define DOCTEST_SUBCASE(name)
// for starting a testsuite block
-#define DOCTEST_TEST_SUITE(name) void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+#define DOCTEST_TEST_SUITE(name) void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
// for ending a testsuite block
-#define DOCTEST_TEST_SUITE_END void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+#define DOCTEST_TEST_SUITE_END void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#define DOCTEST_WARN(expr) ((void)0)
#define DOCTEST_WARN_FALSE(expr) ((void)0)
@@ -1079,6 +1080,10 @@
#ifndef DOCTEST_LIBRARY_IMPLEMENTATION
#define DOCTEST_LIBRARY_IMPLEMENTATION
+#ifndef DOCTEST_SINGLE_HEADER
+#include "doctest_fwd.h"
+#endif // DOCTEST_SINGLE_HEADER
+
// required includes - will go only in one translation unit!
#include <ctime>
#include <cmath>
diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h
index f80f232..b404acf 100644
--- a/doctest/parts/doctest_fwd.h
+++ b/doctest/parts/doctest_fwd.h
@@ -692,18 +692,18 @@
// registers the test by initializing a dummy var with a function
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_REGISTER_FUNCTION(f, name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name);
#elif defined(__clang__)
#define DOCTEST_REGISTER_FUNCTION(f, name) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name); \
_Pragma("clang diagnostic pop")
#else // MSVC
#define DOCTEST_REGISTER_FUNCTION(f, name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::regTest(f, __LINE__, __FILE__, name);
#endif // MSVC
@@ -727,61 +727,60 @@
// for registering tests
#define DOCTEST_TEST_CASE(name) \
- DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for registering tests with a fixture
#define DOCTEST_TEST_CASE_FIXTURE(c, name) \
- DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_CLASS_), c, \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), c, \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for subcases
#if defined(__GNUC__)
#define DOCTEST_SUBCASE(name) \
- if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_SUBCASE_) \
+ if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_ANON_SUBCASE_) \
__attribute__((unused)) = \
doctest::detail::Subcase(name, __FILE__, __LINE__))
#else // __GNUC__
#define DOCTEST_SUBCASE(name) \
- if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_SUBCASE_) = \
+ if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(DOCTEST_ANON_SUBCASE_) = \
doctest::detail::Subcase(name, __FILE__, __LINE__))
#endif // __GNUC__
// for starting a testsuite block
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_TEST_SUITE(name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::setTestSuiteName(name); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#elif defined(__clang__)
#define DOCTEST_TEST_SUITE(name) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = \
doctest::detail::setTestSuiteName(name); \
- _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#else // MSVC
#define DOCTEST_TEST_SUITE(name) \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = doctest::detail::setTestSuiteName(name); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(name); \
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
#endif // MSVC
// for ending a testsuite block
#if defined(__GNUC__) && !defined(__clang__)
#define DOCTEST_TEST_SUITE_END \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) __attribute__((unused)) = \
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) __attribute__((unused)) = \
doctest::detail::setTestSuiteName(""); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#elif defined(__clang__)
-#define DOCTEST_TEST_SUITE_END \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = \
- doctest::detail::setTestSuiteName(""); \
- _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+#define DOCTEST_TEST_SUITE_END \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") static int \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(""); \
+ _Pragma("clang diagnostic pop") void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#else // MSVC
#define DOCTEST_TEST_SUITE_END \
- static int DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_VAR_) = doctest::detail::setTestSuiteName(""); \
- void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+ static int DOCTEST_ANONYMOUS(DOCTEST_ANON_VAR_) = doctest::detail::setTestSuiteName(""); \
+ void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#endif // MSVC
#define DOCTEST_LOG_START() \
@@ -795,19 +794,19 @@
} while(doctest::detail::always_false())
#define DOCTEST_ASSERT_IMPLEMENT(expr, assert_name, false_invert_op) \
- doctest::detail::Result res; \
- bool threw = false; \
+ doctest::detail::Result _DOCTEST_R; \
+ bool _DOCTEST_THREW = false; \
try { \
- res = doctest::detail::ExpressionDecomposer() << expr; \
- } catch(...) { threw = true; } \
+ _DOCTEST_R = doctest::detail::ExpressionDecomposer() << expr; \
+ } catch(...) { _DOCTEST_THREW = true; } \
false_invert_op; \
- if(res || DOCTEST_GCS()->success) { \
+ if(_DOCTEST_R || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssert(res.m_passed, res.m_decomposition.c_str(), threw, #expr, \
- assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssert(_DOCTEST_R.m_passed, _DOCTEST_R.m_decomposition.c_str(), \
+ _DOCTEST_THREW, #expr, assert_name, __FILE__, __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(res) { \
+ if(_DOCTEST_R) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -832,23 +831,24 @@
#define DOCTEST_CHECK(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK", ((void)0))
#define DOCTEST_REQUIRE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE", ((void)0))
-#define DOCTEST_WARN_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "WARN_FALSE", res.invert())
-#define DOCTEST_CHECK_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK_FALSE", res.invert())
-#define DOCTEST_REQUIRE_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE_FALSE", res.invert())
+#define DOCTEST_WARN_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "WARN_FALSE", _DOCTEST_R.invert())
+#define DOCTEST_CHECK_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "CHECK_FALSE", _DOCTEST_R.invert())
+#define DOCTEST_REQUIRE_FALSE(expr) DOCTEST_ASSERT_PROXY(expr, "REQUIRE_FALSE", _DOCTEST_R.invert()
#define DOCTEST_ASSERT_THROWS(expr, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
+ bool _DOCTEST_THREW = false; \
try { \
expr; \
- } catch(...) { threw = true; } \
- if(!threw || DOCTEST_GCS()->success) { \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(!_DOCTEST_THREW || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertThrows(threw, #expr, assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssertThrows(_DOCTEST_THREW, #expr, assert_name, __FILE__, \
+ __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(!threw) { \
+ if(!_DOCTEST_THREW) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -859,21 +859,21 @@
#define DOCTEST_ASSERT_THROWS_AS(expr, as, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
- bool threw_as = false; \
+ bool _DOCTEST_THREW = false; \
+ bool _DOCTEST_THREW_AS = false; \
try { \
expr; \
} catch(as) { \
- threw = true; \
- threw_as = true; \
- } catch(...) { threw = true; } \
- if(!threw_as || DOCTEST_GCS()->success) { \
+ _DOCTEST_THREW = true; \
+ _DOCTEST_THREW_AS = true; \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(!_DOCTEST_THREW_AS || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertThrowsAs(threw, threw_as, #as, #expr, assert_name, \
- __FILE__, __LINE__); \
+ doctest::detail::logAssertThrowsAs(_DOCTEST_THREW, _DOCTEST_THREW_AS, #as, #expr, \
+ assert_name, __FILE__, __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(!threw_as) { \
+ if(!_DOCTEST_THREW_AS) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -884,16 +884,17 @@
#define DOCTEST_ASSERT_NOTHROW(expr, assert_name) \
do { \
if(!DOCTEST_GCS()->no_throw) { \
- bool threw = false; \
+ bool _DOCTEST_THREW = false; \
try { \
expr; \
- } catch(...) { threw = true; } \
- if(threw || DOCTEST_GCS()->success) { \
+ } catch(...) { _DOCTEST_THREW = true; } \
+ if(_DOCTEST_THREW || DOCTEST_GCS()->success) { \
DOCTEST_LOG_START(); \
- doctest::detail::logAssertNothrow(threw, #expr, assert_name, __FILE__, __LINE__); \
+ doctest::detail::logAssertNothrow(_DOCTEST_THREW, #expr, assert_name, __FILE__, \
+ __LINE__); \
} \
DOCTEST_GCS()->numAssertionsForCurrentTestcase++; \
- if(threw) { \
+ if(_DOCTEST_THREW) { \
doctest::detail::addFailedAssert(assert_name); \
DOCTEST_BREAK_INTO_DEBUGGER(); \
doctest::detail::checkIfShouldThrow(assert_name); \
@@ -935,21 +936,21 @@
// for registering tests
#define DOCTEST_TEST_CASE(name) \
- DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for registering tests with a fixture
#define DOCTEST_TEST_CASE_FIXTURE(x, name) \
- DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_CLASS_), x, \
- DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FUNC_), name)
+ DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(DOCTEST_ANON_CLASS_), x, \
+ DOCTEST_ANONYMOUS(DOCTEST_ANON_FUNC_), name)
// for subcases
#define DOCTEST_SUBCASE(name)
// for starting a testsuite block
-#define DOCTEST_TEST_SUITE(name) void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_FOR_SEMICOLON_)()
+#define DOCTEST_TEST_SUITE(name) void DOCTEST_ANONYMOUS(DOCTEST_ANON_FOR_SEMICOLON_)()
// for ending a testsuite block
-#define DOCTEST_TEST_SUITE_END void DOCTEST_ANONYMOUS(DOCTEST_AUTOGEN_TESTSUITE_END_)
+#define DOCTEST_TEST_SUITE_END void DOCTEST_ANONYMOUS(DOCTEST_ANON_TESTSUITE_END_)
#define DOCTEST_WARN(expr) ((void)0)
#define DOCTEST_WARN_FALSE(expr) ((void)0)
diff --git a/doctest/parts/doctest_impl.h b/doctest/parts/doctest_impl.h
index d24e066..27992eb 100644
--- a/doctest/parts/doctest_impl.h
+++ b/doctest/parts/doctest_impl.h
@@ -41,6 +41,10 @@
#ifndef DOCTEST_LIBRARY_IMPLEMENTATION
#define DOCTEST_LIBRARY_IMPLEMENTATION
+#ifndef DOCTEST_SINGLE_HEADER
+#include "doctest_fwd.h"
+#endif // DOCTEST_SINGLE_HEADER
+
// required includes - will go only in one translation unit!
#include <ctime>
#include <cmath>
diff --git a/examples/alternative_macros/test_output/alternative_macros.txt b/examples/alternative_macros/test_output/alternative_macros.txt
index 6237a67..0661180 100644
--- a/examples/alternative_macros/test_output/alternative_macros.txt
+++ b/examples/alternative_macros/test_output/alternative_macros.txt
@@ -1,7 +1,7 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
Hello world!
Hello world!
===============================================================================
-[doctest] test cases: 1 | 1 passed | 0 failed
-[doctest] assertions: 4 | 4 passed | 0 failed
+[doctest] test cases: 1 | 1 passed | 0 failed | 0 skipped
+[doctest] assertions: 4 | 4 passed | 0 failed |
diff --git a/examples/assertion_macros/test_output/assertion_macros.txt b/examples/assertion_macros/test_output/assertion_macros.txt
index a0d5cda..2fa7c12 100644
--- a/examples/assertion_macros/test_output/assertion_macros.txt
+++ b/examples/assertion_macros/test_output/assertion_macros.txt
@@ -1,5 +1,5 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
===============================================================================
main.cpp(16)
an empty test that will fail because of an exception
@@ -37,5 +37,5 @@
REQUIRE_NOTHROW( throws(true) )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed
-[doctest] assertions: 11 | 5 passed | 6 failed
+[doctest] test cases: 4 | 1 passed | 3 failed | 0 skipped
+[doctest] assertions: 11 | 5 passed | 6 failed |
diff --git a/examples/hello_world/test_output/hello_world.txt b/examples/hello_world/test_output/hello_world.txt
index ca7a9ad..0592078 100644
--- a/examples/hello_world/test_output/hello_world.txt
+++ b/examples/hello_world/test_output/hello_world.txt
@@ -1,5 +1,5 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
===============================================================================
main.cpp(6)
testing the factorial function
@@ -10,5 +10,5 @@
CHECK( 0 == 1 )
===============================================================================
-[doctest] test cases: 1 | 0 passed | 1 failed
-[doctest] assertions: 5 | 4 passed | 1 failed
+[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
+[doctest] assertions: 5 | 4 passed | 1 failed |
diff --git a/examples/multi_file_example/test_output/multi_file_example.txt b/examples/multi_file_example/test_output/multi_file_example.txt
index fc8d7e2..01ce372 100644
--- a/examples/multi_file_example/test_output/multi_file_example.txt
+++ b/examples/multi_file_example/test_output/multi_file_example.txt
@@ -1,5 +1,14 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 0 | 0 passed | 0 failed
-[doctest] assertions: 0 | 0 passed | 0 failed
+f1.cpp(3)
+
+
+f1.cpp(4) FAILED!
+ CHECK( 1 == 0 )
+with expansion:
+ CHECK( 1 == 0 )
+
+===============================================================================
+[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
+[doctest] assertions: 1 | 0 passed | 1 failed |
diff --git a/examples/separate_headers/CMakeLists.txt b/examples/separate_headers/CMakeLists.txt
new file mode 100644
index 0000000..77efa4c
--- /dev/null
+++ b/examples/separate_headers/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+
+get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+project(${PROJECT_NAME})
+
+include(../../scripts/common.cmake)
+
+include_directories("../../doctest/")
+
+add_executable(${PROJECT_NAME} main.cpp test.cpp)
+
+add_test(NAME ${PROJECT_NAME} COMMAND $<TARGET_FILE:${PROJECT_NAME}>)
diff --git a/examples/separate_headers/main.cpp b/examples/separate_headers/main.cpp
new file mode 100644
index 0000000..6345532
--- /dev/null
+++ b/examples/separate_headers/main.cpp
@@ -0,0 +1,21 @@
+#include "parts/doctest_impl.h"
+
+int main(int argc, char** argv) {
+ doctest::Context context(argc, argv); // initialize
+
+ // overrides
+ context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name
+ context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
+ context.setOption("abort-after", 5); // stop test execution after 5 failed assertions
+ context.setOption("sort", "name"); // sort the test cases by their name
+
+ int res = context.run(); // run
+
+ if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
+ return res; // propagate the result of the tests
+
+ int client_stuff_return_code = 0;
+ // your program - if the testing framework is integrated in your production code
+
+ return res + client_stuff_return_code;
+}
diff --git a/examples/separate_headers/test.cpp b/examples/separate_headers/test.cpp
new file mode 100644
index 0000000..7b351de
--- /dev/null
+++ b/examples/separate_headers/test.cpp
@@ -0,0 +1,5 @@
+#include "parts/doctest_fwd.h"
+
+TEST_CASE("captain obvious") {
+ CHECK(true == true);
+}
diff --git a/examples/separate_headers/test_output/separate_headers.txt b/examples/separate_headers/test_output/separate_headers.txt
new file mode 100644
index 0000000..0765785
--- /dev/null
+++ b/examples/separate_headers/test_output/separate_headers.txt
@@ -0,0 +1,5 @@
+[doctest] doctest version is "1.0.0"
+[doctest] run with "--help" for options
+===============================================================================
+[doctest] test cases: 1 | 1 passed | 0 failed | 0 skipped
+[doctest] assertions: 1 | 1 passed | 0 failed |
diff --git a/examples/stringification/test_output/stringification.txt b/examples/stringification/test_output/stringification.txt
index bc380ba..62b65b7 100644
--- a/examples/stringification/test_output/stringification.txt
+++ b/examples/stringification/test_output/stringification.txt
@@ -1,5 +1,5 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
===============================================================================
main.cpp(86)
the only test
@@ -25,5 +25,5 @@
CHECK( [1, 42, 3, ] == [1, 2, 666, ] )
===============================================================================
-[doctest] test cases: 1 | 0 passed | 1 failed
-[doctest] assertions: 4 | 0 passed | 4 failed
+[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
+[doctest] assertions: 4 | 0 passed | 4 failed |
diff --git a/examples/subcases_and_bdd/test_output/subcases_and_bdd.txt b/examples/subcases_and_bdd/test_output/subcases_and_bdd.txt
index e1fd3e9..a3661fe 100644
--- a/examples/subcases_and_bdd/test_output/subcases_and_bdd.txt
+++ b/examples/subcases_and_bdd/test_output/subcases_and_bdd.txt
@@ -1,5 +1,5 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
root
1
@@ -51,5 +51,5 @@
CHECK( 84 == 85 )
===============================================================================
-[doctest] test cases: 4 | 1 passed | 3 failed
-[doctest] assertions: 18 | 15 passed | 3 failed
+[doctest] test cases: 4 | 1 passed | 3 failed | 0 skipped
+[doctest] assertions: 18 | 15 passed | 3 failed |
diff --git a/examples/user_supplied_main/test_output/user_supplied_main.txt b/examples/user_supplied_main/test_output/user_supplied_main.txt
index 8b7f96a..98dc2be 100644
--- a/examples/user_supplied_main/test_output/user_supplied_main.txt
+++ b/examples/user_supplied_main/test_output/user_supplied_main.txt
@@ -1,6 +1,6 @@
[doctest] doctest version is "1.0.0"
-[doctest] run with "-dt-help" for options
+[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 1 | 1 passed | 0 failed
-[doctest] assertions: 1 | 1 passed | 0 failed
+[doctest] test cases: 1 | 1 passed | 0 failed | 1 skipped
+[doctest] assertions: 1 | 1 passed | 0 failed |
Program code.