2017-08-24 15:21:36 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								< a  id = "top" > < / a > 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Assertion Macros
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-13 11:14:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								**Contents**< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[Natural Expressions ](#natural-expressions )< br > 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[Floating point comparisons ](#floating-point-comparisons )< br > 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-13 11:14:37 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[Exceptions ](#exceptions )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[Matcher expressions ](#matcher-expressions )< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[Thread Safety ](#thread-safety )< br > 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-09 21:41:44 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[Expressions with commas ](#expressions-with-commas )< br > 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-28 22:42:26 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS` ``, ` ``_NOTEQUALS` ``, ` ``_GREATER_THAN` `` etc).
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 09:15:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there is a rich set of auxiliary macros as well. We'll describe all of these here.
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Most of these macros come in two forms:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Natural Expressions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The ```REQUIRE` `` family of macros tests an expression and aborts the test case if it fails.
							 
						 
					
						
							
								
									
										
										
										
											2014-06-11 15:17:17 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The ```CHECK` `` family are equivalent but execution continues in the same test case even if the assertion fails. This is useful if you have a series of essentially orthogonal assertions and it is useful to see all the results rather than stopping at the first failure.
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE(** _expression_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK(** _expression_  ** )**
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-12-09 15:29:39 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Evaluates the expression and records the result. If an exception is thrown, it is caught, reported, and counted as a failure. These are the macros you will use most of the time.
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Examples:
							 
						 
					
						
							
								
									
										
										
										
											2014-12-17 18:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								CHECK( str == "string value" );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								CHECK( thisReturnsTrue() );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE( i == 42 );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2014-12-17 18:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Expressions prefixed with `!`  cannot be decomposed. If you have a type
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								that is convertible to bool and you want to assert that it evaluates to
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								false, use the two forms below:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 12:35:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_FALSE(** _expression_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK_FALSE(** _expression_  ** )**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Note that there is no reason to use these forms for plain bool variables,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								because there is no added value in decomposing them.
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Example:
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```cpp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Status ret = someFunction();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE_FALSE(ret); // ret must evaluate to false, and Catch2 will print
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    // out the value of ret if possibly
							 
						 
					
						
							
								
									
										
										
										
											2014-12-17 18:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								### Other limitations
 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 12:35:54 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Note that expressions containing either of the binary logical operators,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								`&&`  or `||` , cannot be decomposed and will not compile. The reason behind
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								this is that it is impossible to overload `&&`  and `||`  in a way that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								keeps their short-circuiting semantics, and expression decomposition
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								relies on overloaded operators to work.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Simple example of an issue with overloading binary logical operators
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								is a common pointer idiom, `p && p->foo == 2` . Using the built-in `&&` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								operator, `p`  is only dereferenced if it is not null. With overloaded
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								`&&` , `p`  is always dereferenced, thus causing a segfault if
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								`p == nullptr` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								If you want to test expression that contains `&&`  or `||` , you have two
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								options.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								1) Enclose it in parentheses. Parentheses force evaluation of the expression
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   before the expression decomposition can touch it, and thus it cannot
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   be used.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								2) Rewrite the expression. `REQUIRE(a == 1 && b == 2)`  can always be split
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   into `REQUIRE(a == 1); REQUIRE(b == 2);` . Alternatively, if this is a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   common pattern in your tests, think about using [Matchers ](#matcher-expressions ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   instead. There is no simple rewrite rule for `||` , but I generally
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   believe that if you have `||`  in your test expression, you should rethink
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   your tests.
							 
						 
					
						
							
								
									
										
										
										
											2017-01-30 19:42:27 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:13:00 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Floating point comparisons
 
							 
						 
					
						
							
								
									
										
										
										
											2014-12-17 18:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-14 22:14:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Comparing floating point numbers is complex, and [so it has its own
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								documentation page](comparing-floating-point-numbers.md#top ).
							 
						 
					
						
							
								
									
										
										
										
											2017-02-27 14:22:17 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-12-17 18:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Exceptions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_NOTHROW(** _expression_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 16:18:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK_NOTHROW(** _expression_  ** )**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Expects that no exception is thrown during evaluation of the expression.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_THROWS(** _expression_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK_THROWS(** _expression_  ** )**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Expects that an exception (of any type) is be thrown during evaluation of the expression.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_THROWS_AS(** _expression_ , _exception type_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK_THROWS_AS(** _expression_ , _exception type_  ** )**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-19 21:34:06 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Expects that an exception of the _specified type_  is thrown during evaluation of the expression. Note that the _exception type_  is extended with `const&`  and you should not include it yourself.
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_THROWS_WITH(** _expression_ , _string or string matcher_  ** )** and
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 16:18:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **CHECK_THROWS_WITH(** _expression_ , _string or string matcher_  ** )**
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 08:17:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 16:18:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Expects that an exception is thrown that, when converted to a string, matches the _string_  or _string matcher_  provided (see next section for Matchers).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								e.g.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```cpp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE_THROWS_WITH( openThePodBayDoors(), Contains( "afraid" ) & &  Contains( "can't do that" ) );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-05 18:40:50 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_THROWS_MATCHES(** _expression_ , _exception type_ , _matcher for given exception type_  ** )** and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  **CHECK_THROWS_MATCHES(** _expression_ , _exception type_ , _matcher for given exception type_  ** )**
							 
						 
					
						
							
								
									
										
										
										
											2017-02-06 16:08:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-29 20:38:32 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Expects that exception of _exception type_  is thrown and it matches provided matcher (see the [documentation for Matchers ](matchers.md#top )).
							 
						 
					
						
							
								
									
										
										
										
											2017-06-05 18:40:50 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								_Please note that the `THROW`  family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function._
							 
						 
					
						
							
								
									
										
										
										
											2017-02-06 16:08:13 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```cpp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE_NOTHROW([& ](){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    int i = 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    int j = 2;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    auto k = i + j;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if (k == 3) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        throw 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}());
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-05 18:42:04 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Matcher expressions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-24 15:33:38 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								To support Matchers a slightly different form is used. Matchers have [their own documentation ](matchers.md#top ).
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:02:45 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  **REQUIRE_THAT(** _lhs_ , _matcher expression_  ** )** and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  **CHECK_THAT(** _lhs_ , _matcher expression_  ** )**
							 
						 
					
						
							
								
									
										
										
										
											2017-02-08 16:18:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Matchers can be composed using `&&` , `||`  and `!`  operators.
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:08:20 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-11 14:25:19 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Thread Safety
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Currently assertions in Catch are not thread safe.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								For more details, along with workarounds, see the section on [the limitations page ](limitations.md#thread-safe-assertions ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-09 21:41:44 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Expressions with commas
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Because the preprocessor parses code using different rules than the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								compiler, multiple-argument assertions (e.g. `REQUIRE_THROWS_AS` ) have
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								problems with commas inside the provided expressions. As an example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								`REQUIRE_THROWS_AS(std::pair<int, int>(1, 2), std::invalid_argument);` 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-31 23:21:14 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								will fail to compile, because the preprocessor sees 3 arguments provided,
							 
						 
					
						
							
								
									
										
										
										
											2018-04-09 21:41:44 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								but the macro accepts only 2. There are two possible workarounds.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								1) Use typedef:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```cpp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using int_pair = std::pair< int ,  int > ;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REQUIRE_THROWS_AS(int_pair(1, 2), std::invalid_argument);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This solution is always applicable, but makes the meaning of the code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								less clear.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								2) Parenthesize the expression:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```cpp
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								TEST_CASE_METHOD((Fixture< int ,  int > ), "foo", "[bar]") {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    SUCCEED();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This solution is not always applicable, because it might require extra
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								changes on the Catch's side to work.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-06-10 08:08:20 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-24 15:33:38 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[Home ](Readme.md#top )