Fix move-only types failing to decompose correctly (#634)
* Fix application of move semantics to allow for decomposition of move-only types
* Add regression test
* Remove shadowing to appease compiler gods
* Oops
diff --git a/examples/all_features/CMakeLists.txt b/examples/all_features/CMakeLists.txt
index 3d6b342..80105c9 100644
--- a/examples/all_features/CMakeLists.txt
+++ b/examples/all_features/CMakeLists.txt
@@ -16,6 +16,7 @@
test_cases_and_suites.cpp
asserts_used_outside_of_tests.cpp
enums.cpp
+ decomposition.cpp
)
set(files_all
diff --git a/examples/all_features/decomposition.cpp b/examples/all_features/decomposition.cpp
new file mode 100644
index 0000000..d610cc7
--- /dev/null
+++ b/examples/all_features/decomposition.cpp
@@ -0,0 +1,25 @@
+#include <doctest/doctest.h>
+
+class MoveOnly {
+ public:
+ MoveOnly(int iIn) : i(iIn) { }
+ MoveOnly(MoveOnly&&) = default;
+ MoveOnly(const MoveOnly&) = delete;
+ MoveOnly& operator=(MoveOnly&&) = default;
+ MoveOnly& operator=(const MoveOnly&) = default;
+ operator bool() { // NOT const!
+ return i == 42;
+ }
+
+ private:
+ int i;
+};
+
+static MoveOnly genType(bool b) {
+ return MoveOnly(b ? 42 : 0);
+}
+
+TEST_CASE("Move Only Type") {
+ CHECK(genType(true));
+ CHECK(genType(false));
+}
diff --git a/examples/all_features/test_output/decomposition.cpp.txt b/examples/all_features/test_output/decomposition.cpp.txt
new file mode 100644
index 0000000..7eba247
--- /dev/null
+++ b/examples/all_features/test_output/decomposition.cpp.txt
@@ -0,0 +1,13 @@
+[doctest] run with "--help" for options
+===============================================================================
+decomposition.cpp(0):
+TEST CASE: Move Only Type
+
+decomposition.cpp(0): ERROR: CHECK( genType(false) ) is NOT correct!
+ values: CHECK( {?} )
+
+===============================================================================
+[doctest] test cases: 1 | 0 passed | 1 failed |
+[doctest] assertions: 2 | 1 passed | 1 failed |
+[doctest] Status: FAILURE!
+Program code.
diff --git a/examples/all_features/test_output/decomposition.cpp_junit.txt b/examples/all_features/test_output/decomposition.cpp_junit.txt
new file mode 100644
index 0000000..8ab87d4
--- /dev/null
+++ b/examples/all_features/test_output/decomposition.cpp_junit.txt
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuites>
+ <testsuite name="all_features" errors="0" failures="1" tests="2">
+ <testcase classname="decomposition.cpp" name="Move Only Type" status="run">
+ <failure message="{?}" type="CHECK">
+decomposition.cpp(0):
+CHECK( genType(false) ) is NOT correct!
+ values: CHECK( {?} )
+
+ </failure>
+ </testcase>
+ </testsuite>
+</testsuites>
+Program code.
diff --git a/examples/all_features/test_output/decomposition.cpp_xml.txt b/examples/all_features/test_output/decomposition.cpp_xml.txt
new file mode 100644
index 0000000..584f85b
--- /dev/null
+++ b/examples/all_features/test_output/decomposition.cpp_xml.txt
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<doctest binary="all_features">
+ <Options order_by="file" rand_seed="324" first="0" last="4294967295" abort_after="0" subcase_filter_levels="2147483647" case_sensitive="false" no_throw="false" no_skip="false"/>
+ <TestSuite>
+ <TestCase name="Move Only Type" filename="decomposition.cpp" line="0">
+ <Expression success="false" type="CHECK" filename="decomposition.cpp" line="0">
+ <Original>
+ genType(false)
+ </Original>
+ <Expanded>
+ {?}
+ </Expanded>
+ </Expression>
+ <OverallResultsAsserts successes="1" failures="1" test_case_success="false"/>
+ </TestCase>
+ </TestSuite>
+ <OverallResultsAsserts successes="1" failures="1"/>
+ <OverallResultsTestCases successes="0" failures="1"/>
+</doctest>
+Program code.
diff --git a/examples/all_features/test_output/filter_2.txt b/examples/all_features/test_output/filter_2.txt
index a076fd2..c734cf8 100644
--- a/examples/all_features/test_output/filter_2.txt
+++ b/examples/all_features/test_output/filter_2.txt
@@ -1,6 +1,6 @@
[doctest] run with "--help" for options
===============================================================================
-[doctest] test cases: 0 | 0 passed | 0 failed | 98 skipped
+[doctest] test cases: 0 | 0 passed | 0 failed | 99 skipped
[doctest] assertions: 0 | 0 passed | 0 failed |
[doctest] Status: SUCCESS!
Program code.
diff --git a/examples/all_features/test_output/filter_2_xml.txt b/examples/all_features/test_output/filter_2_xml.txt
index 804fa4f..e36071c 100644
--- a/examples/all_features/test_output/filter_2_xml.txt
+++ b/examples/all_features/test_output/filter_2_xml.txt
@@ -4,6 +4,7 @@
<TestSuite>
<TestCase name=" Scenario: vectors can be sized and resized" filename="subcases.cpp" line="0" skipped="true"/>
<TestCase name="CHECK level of asserts fail the test case but don't abort it" filename="assertion_macros.cpp" line="0" skipped="true"/>
+ <TestCase name="Move Only Type" filename="decomposition.cpp" line="0" skipped="true"/>
<TestCase name="Nested - related to https://github.com/doctest/doctest/issues/282" filename="subcases.cpp" line="0" skipped="true"/>
<TestCase name="REQUIRE level of asserts fail and abort the test case - 1" filename="assertion_macros.cpp" line="0" skipped="true"/>
<TestCase name="REQUIRE level of asserts fail and abort the test case - 10" filename="assertion_macros.cpp" line="0" skipped="true"/>
@@ -140,6 +141,6 @@
<TestCase name="without a funny name:" filename="subcases.cpp" line="0" skipped="true"/>
</TestSuite>
<OverallResultsAsserts successes="0" failures="0"/>
- <OverallResultsTestCases successes="0" failures="0" skipped="98"/>
+ <OverallResultsTestCases successes="0" failures="0" skipped="99"/>
</doctest>
Program code.
diff --git a/examples/all_features/test_output/no_multi_lane_atomics.txt b/examples/all_features/test_output/no_multi_lane_atomics.txt
index 1d3a309..490dd74 100644
--- a/examples/all_features/test_output/no_multi_lane_atomics.txt
+++ b/examples/all_features/test_output/no_multi_lane_atomics.txt
@@ -53,6 +53,13 @@
assertion_macros.cpp(0): MESSAGE: reached!
===============================================================================
+decomposition.cpp(0):
+TEST CASE: Move Only Type
+
+decomposition.cpp(0): ERROR: CHECK( genType(false) ) is NOT correct!
+ values: CHECK( {?} )
+
+===============================================================================
assertion_macros.cpp(0):
TEST CASE: REQUIRE level of asserts fail and abort the test case - 1
@@ -807,7 +814,7 @@
subcases.cpp(0): MESSAGE: Nooo
===============================================================================
-[doctest] test cases: 78 | 30 passed | 48 failed |
-[doctest] assertions: 213 | 99 passed | 114 failed |
+[doctest] test cases: 79 | 30 passed | 49 failed |
+[doctest] assertions: 215 | 100 passed | 115 failed |
[doctest] Status: FAILURE!
Program code.
diff --git a/examples/all_features/test_output/no_multithreading.txt b/examples/all_features/test_output/no_multithreading.txt
index 1d3a309..490dd74 100644
--- a/examples/all_features/test_output/no_multithreading.txt
+++ b/examples/all_features/test_output/no_multithreading.txt
@@ -53,6 +53,13 @@
assertion_macros.cpp(0): MESSAGE: reached!
===============================================================================
+decomposition.cpp(0):
+TEST CASE: Move Only Type
+
+decomposition.cpp(0): ERROR: CHECK( genType(false) ) is NOT correct!
+ values: CHECK( {?} )
+
+===============================================================================
assertion_macros.cpp(0):
TEST CASE: REQUIRE level of asserts fail and abort the test case - 1
@@ -807,7 +814,7 @@
subcases.cpp(0): MESSAGE: Nooo
===============================================================================
-[doctest] test cases: 78 | 30 passed | 48 failed |
-[doctest] assertions: 213 | 99 passed | 114 failed |
+[doctest] test cases: 79 | 30 passed | 49 failed |
+[doctest] assertions: 215 | 100 passed | 115 failed |
[doctest] Status: FAILURE!
Program code.