From c97ada1910d149dc811b29073685ffc26e750cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 30 Jan 2017 19:42:27 +0100 Subject: [PATCH] Improved assertion documentation Mentioned that decomposing `&&` and `||` is not supported, gave examples + possible workarounds. Closes #621, #787, #341 and maybe others I haven't found. --- docs/assertions.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/assertions.md b/docs/assertions.md index 82bb96a3..f64fdcfe 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -34,6 +34,15 @@ Example: REQUIRE_FALSE( thisReturnsFalse() ); ``` +Do note that "overly complex" expressions cannot be decomposed and thus will not compile. This is done partly for practical reasons (to keep the underlying expression template machinery to minimum) and partly for philosophical reasons (assertions should be simple and deterministic). + +Examples: +* `CHECK(a == 1 && b == 2);` +This expression is too complex because of the `&&` operator. If you want to check that 2 or more properties hold, you can either put the expression into parenthesis, which stops decomposition from working, or you need to decompose the expression into two assertions: `CHECK( a == 1 ); CHECK( b == 2);` +* `CHECK( a == 2 || b == 1 );` +This expression is too complex because of the `||` operator. If you want to check that one of several properties hold, you can put the expression into parenthesis (unlike with `&&`, expression decomposition into several `CHECK`s is not possible). + + ### Floating point comparisons When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations.