Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Added tests (single char pretty printing + op overload)

Tests for issue #809 -- Potentional operator overload ambiguity -- and
PR #646 -- Pretty print characters.
Commit
7db4d8d90c84fd62f2b3dcefab66fe5f355f3918
Author
Martin Hořeňovský ·
Parents
a5ce57b34627

Files · Download .tar.gz

Changes

 CMakeLists.txt                                     |   2 +
 .../SelfTest/Baselines/console.std.approved.txt    |   4 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 121 +++++++++++++++++-
 .../SelfTest/Baselines/console.swa4.approved.txt   |  16 ++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |   6 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 139 ++++++++++++++++++++-
 projects/SelfTest/CompilationTests.cpp             |  24 ++++
 projects/SelfTest/ToStringGeneralTests.cpp         |  40 ++++++
 8 files changed, 343 insertions(+), 9 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4a74a8d..6fe4e4e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,7 @@ set(TEST_SOURCES
         ${SELF_TEST_DIR}/BDDTests.cpp
         ${SELF_TEST_DIR}/ClassTests.cpp
         ${SELF_TEST_DIR}/CmdLineTests.cpp
+        ${SELF_TEST_DIR}/CompilationTests.cpp
         ${SELF_TEST_DIR}/ConditionTests.cpp
         ${SELF_TEST_DIR}/EnumToString.cpp
         ${SELF_TEST_DIR}/ExceptionTests.cpp
@@ -62,6 +63,7 @@ set(TEST_SOURCES
         ${SELF_TEST_DIR}/PartTrackerTests.cpp
         ${SELF_TEST_DIR}/TagAliasTests.cpp
         ${SELF_TEST_DIR}/TestMain.cpp
+        ${SELF_TEST_DIR}/ToStringGeneralTests.cpp
         ${SELF_TEST_DIR}/ToStringPair.cpp
         ${SELF_TEST_DIR}/ToStringTuple.cpp
         ${SELF_TEST_DIR}/ToStringVector.cpp
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index ea2e1008..2b9f5696 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -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
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 2ea4dd0b..8b172f52 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -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
 
diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt
index ee0f5d31..c6905bb5 100644
--- a/projects/SelfTest/Baselines/console.swa4.approved.txt
+++ b/projects/SelfTest/Baselines/console.swa4.approved.txt
@@ -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
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index 55ee56c9..c27d9419 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -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}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 354ed640..a9076d29 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -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>
diff --git a/projects/SelfTest/CompilationTests.cpp b/projects/SelfTest/CompilationTests.cpp
new file mode 100644
index 00000000..f12372bf
--- /dev/null
+++ b/projects/SelfTest/CompilationTests.cpp
@@ -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);
+}
diff --git a/projects/SelfTest/ToStringGeneralTests.cpp b/projects/SelfTest/ToStringGeneralTests.cpp
new file mode 100644
index 00000000..a9fa4b83
--- /dev/null
+++ b/projects/SelfTest/ToStringGeneralTests.cpp
@@ -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);
+        }
+    }    
+}