From 7d6439ac4d0b959d9efae1c1497453249169e10e Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Tue, 4 Mar 2025 22:12:01 -0800 Subject: [PATCH 1/6] Fix list for #95 --- cppcheck-fix | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 cppcheck-fix diff --git a/cppcheck-fix b/cppcheck-fix new file mode 100644 index 0000000..d40b897 --- /dev/null +++ b/cppcheck-fix @@ -0,0 +1,6 @@ +include/internal/TestCPPAssertions.h:304:42: style: The scope of the variable 'nullAssertionMessage' can be reduced. [variableScope] + static constexpr const char* nullAssertionMessage = "Null assertion failed!"; + ^ +include/internal/TestCPPAssertions.h:324:42: style: The scope of the variable 'notNullAssertionMessage' can be reduced. [variableScope] + static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; + ^ From 23050a80141469336dd033143a908b804360c15a Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Tue, 4 Mar 2025 22:33:37 -0800 Subject: [PATCH 2/6] Reduce scope of constexpr locals to the minimum required, fixes #99 --- include/internal/TestCPPAssertions.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/internal/TestCPPAssertions.h b/include/internal/TestCPPAssertions.h index 8cdccce..5b3bc34 100644 --- a/include/internal/TestCPPAssertions.h +++ b/include/internal/TestCPPAssertions.h @@ -301,10 +301,9 @@ namespace TestCPP { const string& failureMessage ) { - static constexpr const char* nullAssertionMessage = "Null assertion failed!"; - bool null = ptr == nullptr; if (!null) { + static constexpr const char* nullAssertionMessage = "Null assertion failed!"; return logTestFailure( "", "", nullAssertionMessage, @@ -321,10 +320,9 @@ namespace TestCPP { const string& failureMessage ) { - static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; - bool notNull = ptr != nullptr; if (!notNull) { + static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; return logTestFailure( "", "", notNullAssertionMessage, From a3bec2fedb46c763871a588bef57bb053062f535 Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Tue, 4 Mar 2025 22:39:53 -0800 Subject: [PATCH 3/6] Remove the issues list --- cppcheck-fix | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 cppcheck-fix diff --git a/cppcheck-fix b/cppcheck-fix deleted file mode 100644 index d40b897..0000000 --- a/cppcheck-fix +++ /dev/null @@ -1,6 +0,0 @@ -include/internal/TestCPPAssertions.h:304:42: style: The scope of the variable 'nullAssertionMessage' can be reduced. [variableScope] - static constexpr const char* nullAssertionMessage = "Null assertion failed!"; - ^ -include/internal/TestCPPAssertions.h:324:42: style: The scope of the variable 'notNullAssertionMessage' can be reduced. [variableScope] - static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; - ^ From 231d74b506254bb687a024154d1afe636192e6e9 Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Tue, 4 Mar 2025 23:27:58 -0800 Subject: [PATCH 4/6] Fixes #9 by making parameters const. --- include/internal/TestCPPTestCase.h | 6 +++--- src/TestCPPTestCase.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/internal/TestCPPTestCase.h b/include/internal/TestCPPTestCase.h index f092f33..2edfe26 100644 --- a/include/internal/TestCPPTestCase.h +++ b/include/internal/TestCPPTestCase.h @@ -143,7 +143,7 @@ namespace TestCPP { * TestCase. * @param o The test case from which to make a copy. */ - TestCase (TestCase& o); + TestCase (const TestCase& o); /** * @brief Construct a TestCase by moving all data from another @@ -157,7 +157,7 @@ namespace TestCPP { * @param rhs The test case to copy from. * @return A reference to the new TestCase copy. */ - TestCase& operator= (TestCase& rhs); + TestCase& operator= (const TestCase& rhs); /** * @brief Move a TestCase into another TestCase. @@ -289,7 +289,7 @@ namespace TestCPP { * @param out The stream to write the test failure reason to. * @param reason The test failure reason to write. */ - void logFailure (ostream& out, string& reason); + void logFailure (ostream& out, const string& reason); /** * @brief If a test encounters an error while running, this * function will be called to log the test error. diff --git a/src/TestCPPTestCase.cpp b/src/TestCPPTestCase.cpp index c4c3d43..c032288 100644 --- a/src/TestCPPTestCase.cpp +++ b/src/TestCPPTestCase.cpp @@ -142,7 +142,7 @@ namespace TestCPP { this->option = opt; } - TestCase::TestCase (TestCase& o) { + TestCase::TestCase (const TestCase& o) { this->outCompareOption(o.option); this->setNotifyPassed(o.notifyTestPassed); @@ -231,7 +231,7 @@ namespace TestCPP { } } - TestCase& TestCase::operator= (TestCase& rhs) { + TestCase& TestCase::operator= (const TestCase& rhs) { this->outCompareOption(rhs.option); this->setNotifyPassed(rhs.notifyTestPassed); @@ -289,7 +289,7 @@ namespace TestCPP { return this->lastRunTime; } - void TestCase::logFailure(ostream& out, string& reason) { + void TestCase::logFailure(ostream& out, const string& reason) { out << fixed; out << setprecision(TCPPNum::TIME_PRECISION); out << TCPPStr::TEST << this->testName << TCPPStr::FAIL From 2ad3b54ac26f25caa59a9457220c8807fee6aeec Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Tue, 4 Mar 2025 23:56:28 -0800 Subject: [PATCH 5/6] Increase coverage for codecov patch qg. --- test/include/TestCase/TestCaseSuite.h | 8 +++++ test/include/TestCase/TestCaseTests.h | 2 ++ test/src/TestCase/TestCaseTests.cpp | 44 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/test/include/TestCase/TestCaseSuite.h b/test/include/TestCase/TestCaseSuite.h index 18b1e5a..ba306ad 100644 --- a/test/include/TestCase/TestCaseSuite.h +++ b/test/include/TestCase/TestCaseSuite.h @@ -13,6 +13,14 @@ namespace TestCPP { "Case construction Test", function(TestCaseTests::TestConstructCase) ), + make_tuple( + "Case assignment Test", + function(TestCaseTests::TestAssignTestCase) + ), + make_tuple( + "Case move assignment Test", + function(TestCaseTests::TestMoveAssignTestCase) + ), make_tuple( "Case runner Test", function(TestCaseTests::TestTestCaseGo) diff --git a/test/include/TestCase/TestCaseTests.h b/test/include/TestCase/TestCaseTests.h index 35ca62a..9832a98 100644 --- a/test/include/TestCase/TestCaseTests.h +++ b/test/include/TestCase/TestCaseTests.h @@ -5,6 +5,8 @@ namespace TestCPP { namespace Testing { namespace TestCaseTests { void TestConstructCase (); + void TestAssignTestCase (); + void TestMoveAssignTestCase (); void TestTestCaseGo (); void TestTestCaseGoThrowStr (); void TestTestCaseGoThrowChr (); diff --git a/test/src/TestCase/TestCaseTests.cpp b/test/src/TestCase/TestCaseTests.cpp index e6fe31d..6eac2d5 100644 --- a/test/src/TestCase/TestCaseTests.cpp +++ b/test/src/TestCase/TestCaseTests.cpp @@ -39,6 +39,50 @@ namespace TestCPP { parameterVariationTestChunks(); } + void TestAssignTestCase() { + const auto test = unique_ptr(new TestCase( + "Assignment case Test - const TestCase", + function([]() {}) + )); + + TestCase testCopy = *test; + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + Assertions::assertTrue( + testCopy.go(), + "Should have succeeded basic no-op test!" + ); + } + + void TestMoveAssignTestCase() { + auto test = unique_ptr(new TestCase( + "Move Assignment case Test - const TestCase", + function([]() {}) + )); + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + + TestCase movedTest = std::move(*test); + + Assertions::assertTrue( + movedTest.go(), + "Should have succeeded basic no-op test!" + ); + + *test = std::move(movedTest); + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + } + void TestTestCaseGo () { auto test = unique_ptr(new TestCase( "SUB-TEST TestCaseGo case Test", From 3cca780361181d086bce0011d530a9a57878cafb Mon Sep 17 00:00:00 2001 From: Jonathan Hyry Date: Wed, 5 Mar 2025 00:13:11 -0800 Subject: [PATCH 6/6] Increase coverage for codecov patch qg. --- test/src/TestCase/TestCaseTests.cpp | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/src/TestCase/TestCaseTests.cpp b/test/src/TestCase/TestCaseTests.cpp index 6eac2d5..b880166 100644 --- a/test/src/TestCase/TestCaseTests.cpp +++ b/test/src/TestCase/TestCaseTests.cpp @@ -39,20 +39,30 @@ namespace TestCPP { parameterVariationTestChunks(); } + /** + * Targets various types of non-move assignments. + */ void TestAssignTestCase() { const auto test = unique_ptr(new TestCase( "Assignment case Test - const TestCase", function([]() {}) )); - - TestCase testCopy = *test; + const auto test2 = unique_ptr(new TestCase( + "Assignment case Test 2 - const TestCase", + function([]() {}) + )); Assertions::assertTrue( test->go(), "Should have succeeded basic no-op test!" ); + + const TestCase& testCopy = *test; + TestCase testCopy2 = *test2; + testCopy2 = testCopy; + Assertions::assertTrue( - testCopy.go(), + testCopy2.go(), "Should have succeeded basic no-op test!" ); } @@ -62,20 +72,19 @@ namespace TestCPP { "Move Assignment case Test - const TestCase", function([]() {}) )); + auto test2 = unique_ptr(new TestCase( + "Move Assignment case Test 2 - const TestCase", + function([]() {}) + )); Assertions::assertTrue( test->go(), "Should have succeeded basic no-op test!" ); - TestCase movedTest = std::move(*test); - - Assertions::assertTrue( - movedTest.go(), - "Should have succeeded basic no-op test!" - ); - - *test = std::move(movedTest); + TestCase tempCpy = *test; + *test = std::move(*test2); + *test2 = std::move(tempCpy); Assertions::assertTrue( test->go(),