Skip to content

Commit

Permalink
- added the ability to compile code with assertions that need excepti…
Browse files Browse the repository at this point in the history
…ons even without exceptions - see the use of DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

- added clang 3.9 to build matrix

relates #44
  • Loading branch information
onqtam committed Nov 14, 2016
1 parent 1f5d22a commit 4402545
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -48,6 +48,7 @@ addons:
- llvm-toolchain-precise-3.6
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise-3.8
- llvm-toolchain-precise-3.9
- llvm-toolchain-precise

compiler: clang
Expand Down Expand Up @@ -164,6 +165,13 @@ matrix:
packages: ["clang-3.8", "valgrind", "g++-multilib", "libc6-dbg", "libc6-dbg:i386", "g++-6"]
sources: *apt_sources

# Clang 3.9
- env: COMPILER=clang++-3.9 HAS_ASAN_64=true HAS_UBSAN_64=true
addons: &clang39
apt:
packages: ["clang-3.9", "valgrind", "g++-multilib", "libc6-dbg", "libc6-dbg:i386", "g++-6"]
sources: *apt_sources

# Xcode 6.1 Clang
- env: COMPILER=clang++
os: osx
Expand Down
21 changes: 18 additions & 3 deletions doc/markdown/configuration.md
Expand Up @@ -15,6 +15,7 @@ The identifiers should be defined before the inclusion of the framework header.
- [**```DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS```**](#doctest_config_no_unprefixed_options)
- [**```DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS```**](#doctest_config_no_try_catch_in_asserts)
- [**```DOCTEST_CONFIG_NO_EXCEPTIONS```**](#doctest_config_no_exceptions)
- [**```DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS```**](#doctest_config_no_exceptions_but_with_all_asserts)
- [**```DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE```**](#doctest_config_assertion_parameters_by_value)
- [**```DOCTEST_CONFIG_COLORS_NONE```**](#doctest_config_colors_none)
- [**```DOCTEST_CONFIG_COLORS_WINDOWS```**](#doctest_config_colors_windows)
Expand Down Expand Up @@ -102,7 +103,7 @@ This should be defined only in the source file where the library is implemented
This will remove all ```try``` / ```catch``` sections from:

- the [normal asserts](assertions.md#expression-decomposing-asserts)
- the [binary and unary asserts](assertions.md#expression-decomposing-asserts)
- the [binary and unary asserts](assertions.md#binary-and-unary-asserts)

so exceptions thrown while evaluating the expression in an assert will terminate the current test case.

Expand All @@ -115,16 +116,30 @@ This will remove everything that uses exceptions from the framework - it is also
What gets changed:

- asserts that evaluate the expression in a ```try``` / ```catch``` section no longer evaluate in such a context
- ```REQUIRE``` macros are gone
- [exception macros](assertions.md#exceptions) are gone
- ```REQUIRE``` macros are gone (undefined)
- [exception macros](assertions.md#exceptions) are gone (undefined)
- the ```abort-after``` option won't be fully working because an exception is used to terminate test cases

The ```REQUIRE``` family of asserts uses exceptions to terminate the current test case when they fail. An exception is used instead of a simple ```return;``` because asserts can be used not only in a test case but also in functions called by a test case.

[**```DOCTEST_CONFIG_NO_EXCEPTIONS```**](#doctest_config_no_exceptions) implies [**```DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS```**](#doctest_config_no_try_catch_in_asserts)

If you wish to use asserts that deal with exceptions and only sometimes build without exceptions - check the [**```DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS```**](#doctest_config_no_exceptions_but_with_all_asserts) config option.

This should be defined globally.


### **```DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS```**

When building with no exceptions (see [**```DOCTEST_CONFIG_NO_EXCEPTIONS```**](#doctest_config_no_exceptions)) ```REQUIRE``` asserts and the ones about dealing with exceptions are gone.

If however you want your code to use these assertions and only sometimes build without exceptions - then using this config will be of help. The effects of using it are the following:

- ```REQUIRE``` asserts are not gone - but they act like ```CHECK``` asserts - when one of them fails the whole test case will be marked as failed but will not be exited immediately
- the [asserts for dealing with exceptions](assertions.md#exceptions) are turned into a no-op (instead of being totally undefined)

This can be defined both globally and in specific source files only.

### **```DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE```**

This option forces all doctest asserts to copy by value the expressions they are given instead of binding them to const references. This might be useful to avoid ODR-usage of static constants (which might lead to linker errors with g++/clang):
Expand Down
27 changes: 25 additions & 2 deletions doctest/doctest.h
Expand Up @@ -1444,9 +1444,13 @@ class Context
#define DOCTEST_FAST_REQUIRE_UNARY_FALSE(v) \
DOCTEST_FAST_UNARY_ASSERT(DT_FAST_REQUIRE_UNARY_FALSE, v)



// OMGOMGOMG trqbva da napravq teq da sa no-op - a ne prosto da ne gi undef-vam



#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS
#undef DOCTEST_REQUIRE
#undef DOCTEST_REQUIRE_FALSE

#undef DOCTEST_WARN_THROWS
#undef DOCTEST_CHECK_THROWS
Expand All @@ -1458,6 +1462,22 @@ class Context
#undef DOCTEST_CHECK_NOTHROW
#undef DOCTEST_REQUIRE_NOTHROW

#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#define DOCTEST_WARN_THROWS(expr) ((void)0)
#define DOCTEST_WARN_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_WARN_NOTHROW(expr) ((void)0)
#define DOCTEST_CHECK_THROWS(expr) ((void)0)
#define DOCTEST_CHECK_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_CHECK_NOTHROW(expr) ((void)0)
#define DOCTEST_REQUIRE_THROWS(expr) ((void)0)
#define DOCTEST_REQUIRE_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0)

#else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#undef DOCTEST_REQUIRE
#undef DOCTEST_REQUIRE_FALSE
#undef DOCTEST_REQUIRE_EQ
#undef DOCTEST_REQUIRE_NE
#undef DOCTEST_REQUIRE_GT
Expand All @@ -1474,6 +1494,9 @@ class Context
#undef DOCTEST_FAST_REQUIRE_LE
#undef DOCTEST_FAST_REQUIRE_UNARY
#undef DOCTEST_FAST_REQUIRE_UNARY_FALSE

#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#endif // DOCTEST_CONFIG_NO_EXCEPTIONS

// =================================================================================================
Expand Down
27 changes: 25 additions & 2 deletions doctest/parts/doctest_fwd.h
Expand Up @@ -1441,9 +1441,13 @@ class Context
#define DOCTEST_FAST_REQUIRE_UNARY_FALSE(v) \
DOCTEST_FAST_UNARY_ASSERT(DT_FAST_REQUIRE_UNARY_FALSE, v)



// OMGOMGOMG trqbva da napravq teq da sa no-op - a ne prosto da ne gi undef-vam



#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS
#undef DOCTEST_REQUIRE
#undef DOCTEST_REQUIRE_FALSE

#undef DOCTEST_WARN_THROWS
#undef DOCTEST_CHECK_THROWS
Expand All @@ -1455,6 +1459,22 @@ class Context
#undef DOCTEST_CHECK_NOTHROW
#undef DOCTEST_REQUIRE_NOTHROW

#ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#define DOCTEST_WARN_THROWS(expr) ((void)0)
#define DOCTEST_WARN_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_WARN_NOTHROW(expr) ((void)0)
#define DOCTEST_CHECK_THROWS(expr) ((void)0)
#define DOCTEST_CHECK_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_CHECK_NOTHROW(expr) ((void)0)
#define DOCTEST_REQUIRE_THROWS(expr) ((void)0)
#define DOCTEST_REQUIRE_THROWS_AS(expr, ex) ((void)0)
#define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0)

#else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#undef DOCTEST_REQUIRE
#undef DOCTEST_REQUIRE_FALSE
#undef DOCTEST_REQUIRE_EQ
#undef DOCTEST_REQUIRE_NE
#undef DOCTEST_REQUIRE_GT
Expand All @@ -1471,6 +1491,9 @@ class Context
#undef DOCTEST_FAST_REQUIRE_LE
#undef DOCTEST_FAST_REQUIRE_UNARY
#undef DOCTEST_FAST_REQUIRE_UNARY_FALSE

#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS

#endif // DOCTEST_CONFIG_NO_EXCEPTIONS

// =================================================================================================
Expand Down

0 comments on commit 4402545

Please sign in to comment.