mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Added tests (single char pretty printing + op overload)
Tests for issue #809 -- Potentional operator overload ambiguity -- and PR #646 -- Pretty print characters.
This commit is contained in:
		| @@ -829,6 +829,6 @@ with expansion: | ||||
|   "first" == "second" | ||||
|  | ||||
| =============================================================================== | ||||
| test cases: 157 | 113 passed | 42 failed |  2 failed as expected | ||||
| assertions: 913 | 817 passed | 78 failed | 18 failed as expected | ||||
| test cases: 159 | 115 passed | 42 failed |  2 failed as expected | ||||
| assertions: 928 | 832 passed | 78 failed | 18 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -14,6 +14,18 @@ PASSED: | ||||
| with message: | ||||
|   yay | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| #809 | ||||
| ------------------------------------------------------------------------------- | ||||
| CompilationTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| CompilationTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( 42 == f ) | ||||
| with expansion: | ||||
|   42 == {?} | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| 'Not' checks that should fail | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -533,6 +545,111 @@ PASSED: | ||||
| with expansion: | ||||
|   true | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Character pretty printing | ||||
|   Specifically escaped | ||||
| ------------------------------------------------------------------------------- | ||||
| ToStringGeneralTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( tab == '\t' ) | ||||
| with expansion: | ||||
|   '\t' == '\t' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( newline == '\n' ) | ||||
| with expansion: | ||||
|   '\n' == '\n' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( carr_return == '\r' ) | ||||
| with expansion: | ||||
|   '\r' == '\r' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( form_feed == '\f' ) | ||||
| with expansion: | ||||
|   '\f' == '\f' | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Character pretty printing | ||||
|   General chars | ||||
| ------------------------------------------------------------------------------- | ||||
| ToStringGeneralTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( space == ' ' ) | ||||
| with expansion: | ||||
|   ' ' == ' ' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == chars[i] ) | ||||
| with expansion: | ||||
|   'a' == 'a' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == chars[i] ) | ||||
| with expansion: | ||||
|   'z' == 'z' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == chars[i] ) | ||||
| with expansion: | ||||
|   'A' == 'A' | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == chars[i] ) | ||||
| with expansion: | ||||
|   'Z' == 'Z' | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Character pretty printing | ||||
|   Low ASCII | ||||
| ------------------------------------------------------------------------------- | ||||
| ToStringGeneralTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   CHECK( null_terminator == '\0' ) | ||||
| with expansion: | ||||
|   0 == 0 | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == i ) | ||||
| with expansion: | ||||
|   2 == 2 | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == i ) | ||||
| with expansion: | ||||
|   3 == 3 | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == i ) | ||||
| with expansion: | ||||
|   4 == 4 | ||||
|  | ||||
| ToStringGeneralTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( c == i ) | ||||
| with expansion: | ||||
|   5 == 5 | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Comparing function pointers | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -9025,6 +9142,6 @@ MiscTests.cpp:<line number>: | ||||
| PASSED: | ||||
|  | ||||
| =============================================================================== | ||||
| test cases: 157 | 112 passed | 43 failed |  2 failed as expected | ||||
| assertions: 915 | 817 passed | 80 failed | 18 failed as expected | ||||
| test cases: 159 | 114 passed | 43 failed |  2 failed as expected | ||||
| assertions: 930 | 832 passed | 80 failed | 18 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -14,6 +14,18 @@ PASSED: | ||||
| with message: | ||||
|   yay | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| #809 | ||||
| ------------------------------------------------------------------------------- | ||||
| CompilationTests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| CompilationTests.cpp:<line number>: | ||||
| PASSED: | ||||
|   REQUIRE( 42 == f ) | ||||
| with expansion: | ||||
|   42 == {?} | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| 'Not' checks that should fail | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -35,6 +47,6 @@ ConditionTests.cpp:<line number>: FAILED: | ||||
|   CHECK_FALSE( true ) | ||||
|  | ||||
| =============================================================================== | ||||
| test cases: 2 | 1 passed | 1 failed | ||||
| assertions: 5 | 1 passed | 4 failed | ||||
| test cases: 3 | 2 passed | 1 failed | ||||
| assertions: 6 | 2 passed | 4 failed | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| <?xml version="1.1" encoding="UTF-8"?> | ||||
| <testsuites> | ||||
|   <testsuite name="<exe-name>" errors="13" failures="68" tests="916" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|   <testsuite name="<exe-name>" errors="13" failures="68" tests="931" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|     <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/> | ||||
|     <testcase classname="global" name="#809" time="{duration}"/> | ||||
|     <testcase classname="global" name="'Not' checks that should fail" time="{duration}"> | ||||
|       <failure message="false != false" type="CHECK"> | ||||
| ConditionTests.cpp:<line number> | ||||
| @@ -80,6 +81,9 @@ ExceptionTests.cpp:<line number> | ||||
|     <testcase classname="Assertions then sections" name="A section" time="{duration}"/> | ||||
|     <testcase classname="Assertions then sections" name="A section/Another section" time="{duration}"/> | ||||
|     <testcase classname="Assertions then sections" name="A section/Another other section" time="{duration}"/> | ||||
|     <testcase classname="Character pretty printing" name="Specifically escaped" time="{duration}"/> | ||||
|     <testcase classname="Character pretty printing" name="General chars" time="{duration}"/> | ||||
|     <testcase classname="Character pretty printing" name="Low ASCII" time="{duration}"/> | ||||
|     <testcase classname="global" name="Comparing function pointers" time="{duration}"/> | ||||
|     <testcase classname="global" name="Comparing member function pointers" time="{duration}"/> | ||||
|     <testcase classname="global" name="Comparisons between ints where one side is computed" time="{duration}"/> | ||||
|   | ||||
| @@ -4,6 +4,17 @@ | ||||
|     <TestCase name="# A test name that starts with a #"> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="#809"> | ||||
|       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/CompilationTests.cpp" > | ||||
|         <Original> | ||||
|           42 == f | ||||
|         </Original> | ||||
|         <Expanded> | ||||
|           42 == {?} | ||||
|         </Expanded> | ||||
|       </Expression> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="'Not' checks that should fail"> | ||||
|       <Expression success="false" type="CHECK" filename="projects/<exe-name>/ConditionTests.cpp" > | ||||
|         <Original> | ||||
| @@ -554,6 +565,130 @@ | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Character pretty printing"> | ||||
|       <Section name="Specifically escaped"> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             tab == '\t' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             '\t' == '\t' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             newline == '\n' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             '\n' == '\n' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             carr_return == '\r' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             '\r' == '\r' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             form_feed == '\f' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             '\f' == '\f' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <OverallResults successes="4" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <Section name="General chars"> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             space == ' ' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             ' ' == ' ' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == chars[i] | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             'a' == 'a' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == chars[i] | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             'z' == 'z' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == chars[i] | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             'A' == 'A' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == chars[i] | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             'Z' == 'Z' | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <OverallResults successes="5" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <Section name="Low ASCII"> | ||||
|         <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             null_terminator == '\0' | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             0 == 0 | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == i | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             2 == 2 | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == i | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             3 == 3 | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == i | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             4 == 4 | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > | ||||
|           <Original> | ||||
|             c == i | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             5 == 5 | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <OverallResults successes="5" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Comparing function pointers"> | ||||
|       <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" > | ||||
|         <Original> | ||||
| @@ -9520,7 +9655,7 @@ there" | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <OverallResults successes="817" failures="81" expectedFailures="18"/> | ||||
|     <OverallResults successes="832" failures="81" expectedFailures="18"/> | ||||
|   </Group> | ||||
|   <OverallResults successes="817" failures="80" expectedFailures="18"/> | ||||
|   <OverallResults successes="832" failures="80" expectedFailures="18"/> | ||||
| </Catch> | ||||
|   | ||||
							
								
								
									
										24
									
								
								projects/SelfTest/CompilationTests.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								projects/SelfTest/CompilationTests.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| /* | ||||
|  *  Created by Martin on 17/02/2017. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  */ | ||||
|  | ||||
| #include "catch.hpp" | ||||
|  | ||||
|  | ||||
| // This is a minimal example for an issue we have found in 1.7.0 | ||||
| struct foo { | ||||
|     int i; | ||||
| }; | ||||
|  | ||||
| template <typename T> | ||||
| bool operator==(const T& val, foo f){ | ||||
|     return val == f.i; | ||||
| } | ||||
|  | ||||
| TEST_CASE("#809") { | ||||
|     foo f; f.i = 42; | ||||
|     REQUIRE(42 == f); | ||||
| } | ||||
							
								
								
									
										40
									
								
								projects/SelfTest/ToStringGeneralTests.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								projects/SelfTest/ToStringGeneralTests.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| /* | ||||
|  *  Created by Martin on 17/02/2017. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  */ | ||||
|  | ||||
| #include "catch.hpp" | ||||
|  | ||||
|  | ||||
| TEST_CASE( "Character pretty printing" ){ | ||||
|     //  | ||||
|     SECTION("Specifically escaped"){ | ||||
|         char tab = '\t'; | ||||
|         char newline = '\n'; | ||||
|         char carr_return = '\r'; | ||||
|         char form_feed = '\f'; | ||||
|         CHECK(tab == '\t'); | ||||
|         CHECK(newline == '\n'); | ||||
|         CHECK(carr_return == '\r'); | ||||
|         CHECK(form_feed == '\f'); | ||||
|     } | ||||
|     SECTION("General chars"){ | ||||
|         char space = ' '; | ||||
|         CHECK(space == ' '); | ||||
|         char chars[] = {'a', 'z', 'A', 'Z'}; | ||||
|         for (int i = 0; i < 4; ++i){ | ||||
|             char c = chars[i]; | ||||
|             REQUIRE(c == chars[i]); | ||||
|         } | ||||
|     } | ||||
|     SECTION("Low ASCII"){ | ||||
|         char null_terminator = '\0'; | ||||
|         CHECK(null_terminator == '\0'); | ||||
|         for (int i = 2; i < 6; ++i){ | ||||
|             char c = static_cast<char>(i); | ||||
|             REQUIRE(c == i); | ||||
|         } | ||||
|     }     | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský