diff --git a/cmake/Includes.cmake b/cmake/Includes.cmake index 90f2587..6c50bed 100644 --- a/cmake/Includes.cmake +++ b/cmake/Includes.cmake @@ -28,13 +28,23 @@ if (BUILD_TESTING) ) target_include_directories ( - ${PROJECT_NAME}_TestSuite_test PRIVATE + ${PROJECT_NAME}_TestSuite_ctor_test PRIVATE + test/include + include + ) + target_include_directories ( + ${PROJECT_NAME}_TestSuite_running_test PRIVATE + test/include + include + ) + target_include_directories ( + ${PROJECT_NAME}_TestSuite_tpm_test PRIVATE test/include include ) target_include_directories ( - ${PROJECT_NAME}_Assertions_test PRIVATE + ${PROJECT_NAME}_Assertions_basic_test PRIVATE test/include include ) diff --git a/cmake/Targets.cmake b/cmake/Targets.cmake index 1606e70..580f48b 100644 --- a/cmake/Targets.cmake +++ b/cmake/Targets.cmake @@ -30,15 +30,27 @@ if (BUILD_TESTING) ) add_executable ( - ${PROJECT_NAME}_TestSuite_test - test/src/TestSuite/TestSuiteTests.cpp - test/src/TestCPPTestSuiteMain.cpp + ${PROJECT_NAME}_TestSuite_ctor_test + test/src/TestSuite/TestSuiteConstructionTests.cpp + test/src/TestCPPTestSuiteConstructionMain.cpp ) add_executable ( - ${PROJECT_NAME}_Assertions_test - test/src/Assertions/BasicAssertionsTests.cpp - test/src/TestCPPAssertionsMain.cpp + ${PROJECT_NAME}_TestSuite_running_test + test/src/TestSuite/TestSuiteRunningTests.cpp + test/src/TestCPPTestSuiteRunningMain.cpp + ) + + add_executable ( + ${PROJECT_NAME}_TestSuite_tpm_test + test/src/TestSuite/TestSuiteTestPassedMessageTests.cpp + test/src/TestCPPTestSuiteTestPassedMessageMain.cpp + ) + + add_executable ( + ${PROJECT_NAME}_Assertions_basic_test + test/src/Assertions/AssertionsBasicTests.cpp + test/src/TestCPPAssertionsBasicMain.cpp ) add_executable ( diff --git a/cmake/Testing.cmake b/cmake/Testing.cmake index 146527f..550a0a5 100644 --- a/cmake/Testing.cmake +++ b/cmake/Testing.cmake @@ -5,13 +5,21 @@ if (BUILD_TESTING) ) add_test ( - NAME ${PROJECT_NAME}TestSuiteTests - COMMAND ${PROJECT_NAME}_TestSuite_test + NAME ${PROJECT_NAME}TestSuiteConstructionTests + COMMAND ${PROJECT_NAME}_TestSuite_ctor_test + ) + add_test ( + NAME ${PROJECT_NAME}TestSuiteRunningTests + COMMAND ${PROJECT_NAME}_TestSuite_running_test + ) + add_test ( + NAME ${PROJECT_NAME}TestSuiteTestPassedMessageTests + COMMAND ${PROJECT_NAME}_TestSuite_tpm_test ) add_test ( - NAME ${PROJECT_NAME}AssertionsTests - COMMAND ${PROJECT_NAME}_Assertions_test + NAME ${PROJECT_NAME}AssertionsBasicTests + COMMAND ${PROJECT_NAME}_Assertions_basic_test ) add_test ( diff --git a/cmake/build/DebugCompileDefs.cmake b/cmake/build/DebugCompileDefs.cmake index 8f424d3..55e55d1 100644 --- a/cmake/build/DebugCompileDefs.cmake +++ b/cmake/build/DebugCompileDefs.cmake @@ -19,12 +19,22 @@ if (BUILD_TESTING) DEBUG_LOG ) target_compile_definitions ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test PUBLIC DEBUG_LOG ) target_compile_definitions ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + DEBUG_LOG + ) + target_compile_definitions ( + ${PROJECT_NAME}_TestSuite_tpm_test + PUBLIC + DEBUG_LOG + ) + target_compile_definitions ( + ${PROJECT_NAME}_Assertions_basic_test PUBLIC DEBUG_LOG ) diff --git a/cmake/build/GCCClangDebug.cmake b/cmake/build/GCCClangDebug.cmake index 7ae11bd..d6df79e 100644 --- a/cmake/build/GCCClangDebug.cmake +++ b/cmake/build/GCCClangDebug.cmake @@ -17,6 +17,10 @@ list ( # it's not necessary to maintain # compatibility with C++98. -Wno-covered-switch-default # -Wswitch-default is more important. + -Wno-unknown-pragmas # Ignore unknown pragmas, since we are + # building for Clang, GCC, and MSVC, + # and MSVC has different pragmas than + # GCC/Clang. -Wno-unused-lambda-capture # Avoid MSVC error C3493 - There is # implementation divergence here and # since we're not using >=C++14 there @@ -93,13 +97,23 @@ else () ) target_compile_options ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + PUBLIC + ${GCC_CLANG_DEBUG_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + ${GCC_CLANG_DEBUG_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_tpm_test PUBLIC ${GCC_CLANG_DEBUG_BUILD_OPTS} ) target_compile_options ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test PUBLIC ${GCC_CLANG_DEBUG_BUILD_OPTS} ) diff --git a/cmake/build/GCCClangRelease.cmake b/cmake/build/GCCClangRelease.cmake index 723a235..819709a 100644 --- a/cmake/build/GCCClangRelease.cmake +++ b/cmake/build/GCCClangRelease.cmake @@ -14,6 +14,10 @@ list ( # it's not necessary to maintain # compatibility with C++98. -Wno-covered-switch-default # -Wswitch-default is more important. + -Wno-unknown-pragmas # Ignore unknown pragmas, since we are + # building for Clang, GCC, and MSVC, + # and MSVC has different pragmas than + # GCC/Clang. -Wno-unused-parameter # Unused parameters occur in the Release # build in debugLog. -Wno-unused-lambda-capture # Avoid MSVC error C3493 - There is @@ -86,13 +90,23 @@ if (BUILD_TESTING) ) target_compile_options ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + PUBLIC + ${GCC_CLANG_RELEASE_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + ${GCC_CLANG_RELEASE_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_tpm_test PUBLIC ${GCC_CLANG_RELEASE_BUILD_OPTS} ) target_compile_options ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test PUBLIC ${GCC_CLANG_RELEASE_BUILD_OPTS} ) diff --git a/cmake/build/GCCCoverage.cmake b/cmake/build/GCCCoverage.cmake index d6ef9ee..7874bd1 100644 --- a/cmake/build/GCCCoverage.cmake +++ b/cmake/build/GCCCoverage.cmake @@ -17,6 +17,10 @@ list ( # it's not necessary to maintain # compatibility with C++98. -Wno-covered-switch-default # -Wswitch-default is more important. + -Wno-unknown-pragmas # Ignore unknown pragmas, since we are + # building for Clang, GCC, and MSVC, + # and MSVC has different pragmas than + # GCC/Clang. -fprofile-arcs # Enable profile points that help with # code coverage. -ftest-coverage # Enable core code coverage compilation. @@ -39,13 +43,23 @@ target_compile_options ( ) target_compile_options ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + PUBLIC + ${COVERAGE_BUILD_OPTS} +) +target_compile_options ( + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + ${COVERAGE_BUILD_OPTS} +) +target_compile_options ( + ${PROJECT_NAME}_TestSuite_tpm_test PUBLIC ${COVERAGE_BUILD_OPTS} ) target_compile_options ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test PUBLIC ${COVERAGE_BUILD_OPTS} ) diff --git a/cmake/build/MSVCDebug.cmake b/cmake/build/MSVCDebug.cmake index b86c7ad..1b2cb92 100644 --- a/cmake/build/MSVCDebug.cmake +++ b/cmake/build/MSVCDebug.cmake @@ -73,13 +73,23 @@ if (BUILD_TESTING) ) target_compile_options ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + PUBLIC + ${MSVC_DEBUG_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + ${MSVC_DEBUG_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_tpm_test PUBLIC ${MSVC_DEBUG_BUILD_OPTS} ) target_compile_options ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test PUBLIC ${MSVC_DEBUG_BUILD_OPTS} ) diff --git a/cmake/build/MSVCRelease.cmake b/cmake/build/MSVCRelease.cmake index 2874a78..0bc537b 100644 --- a/cmake/build/MSVCRelease.cmake +++ b/cmake/build/MSVCRelease.cmake @@ -63,13 +63,23 @@ if (BUILD_TESTING) ) target_compile_options ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + PUBLIC + ${MSVC_RELEASE_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_running_test + PUBLIC + ${MSVC_RELEASE_BUILD_OPTS} + ) + target_compile_options ( + ${PROJECT_NAME}_TestSuite_tpm_test PUBLIC ${MSVC_RELEASE_BUILD_OPTS} ) target_compile_options ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test PUBLIC ${MSVC_RELEASE_BUILD_OPTS} ) diff --git a/cmake/link/Tests.cmake b/cmake/link/Tests.cmake index ada2836..01958d7 100644 --- a/cmake/link/Tests.cmake +++ b/cmake/link/Tests.cmake @@ -6,13 +6,25 @@ if (${TESTCPP_STACKTRACE_ENABLED} AND MSVC) dbgeng ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test ${PROJECT_NAME} ole32 dbgeng ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + ole32 + dbgeng + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test + ${PROJECT_NAME} + ole32 + dbgeng + ) + target_link_libraries ( + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} ole32 dbgeng @@ -31,12 +43,22 @@ elseif (${TESTCPP_STACKTRACE_ENABLED}) dl ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + ${PROJECT_NAME} + dl + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + dl + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test ${PROJECT_NAME} dl ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} dl ) @@ -52,11 +74,19 @@ else () ${PROJECT_NAME} ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + ${PROJECT_NAME} + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test ${PROJECT_NAME} ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} ) target_link_libraries ( diff --git a/cmake/link/TestsWithCoverage.cmake b/cmake/link/TestsWithCoverage.cmake index 244e366..dff4a34 100644 --- a/cmake/link/TestsWithCoverage.cmake +++ b/cmake/link/TestsWithCoverage.cmake @@ -7,14 +7,28 @@ if (${TESTCPP_STACKTRACE_ENABLED} AND MSVC) dbgeng ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test ${PROJECT_NAME} gcov ole32 dbgeng ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + gcov + ole32 + dbgeng + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test + ${PROJECT_NAME} + gcov + ole32 + dbgeng + ) + target_link_libraries ( + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} gcov ole32 @@ -36,13 +50,25 @@ elseif (${TESTCPP_STACKTRACE_ENABLED}) dl ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + ${PROJECT_NAME} + gcov + dl + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + gcov + dl + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test ${PROJECT_NAME} gcov dl ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} gcov dl @@ -61,12 +87,22 @@ else () gcov ) target_link_libraries ( - ${PROJECT_NAME}_TestSuite_test + ${PROJECT_NAME}_TestSuite_ctor_test + ${PROJECT_NAME} + gcov + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_running_test + ${PROJECT_NAME} + gcov + ) + target_link_libraries ( + ${PROJECT_NAME}_TestSuite_tpm_test ${PROJECT_NAME} gcov ) target_link_libraries ( - ${PROJECT_NAME}_Assertions_test + ${PROJECT_NAME}_Assertions_basic_test ${PROJECT_NAME} gcov ) diff --git a/include/internal/TestCPPTestSuite.h b/include/internal/TestCPPTestSuite.h index 545a193..9d9e83e 100644 --- a/include/internal/TestCPPTestSuite.h +++ b/include/internal/TestCPPTestSuite.h @@ -46,7 +46,6 @@ using std::chrono::system_clock; using std::chrono::duration_cast; using std::enable_if; using std::endl; -using std::forward; using std::function; using std::runtime_error; using std::string; @@ -77,12 +76,10 @@ namespace TestCPP { * tests. */ template - TestSuite (TestObjName&& suiteName, + TestSuite (TestObjName&& newSuiteName, typename enable_if::type) { - this->testSuitePassedMessage = true; - this->setSuiteName(std::move(suiteName)); - this->tests = vector(); + commonInit(std::forward(newSuiteName)); } /** @@ -90,11 +87,9 @@ namespace TestCPP { * tests. */ template - TestSuite (TestObjName&& suiteName, TestType ...tests) { - this->testSuitePassedMessage = true; - this->setSuiteName(std::move(suiteName)); - this->tests = vector(); - + TestSuite (TestObjName&& newSuiteName, TestType ...tests) + { + commonInit(std::forward(newSuiteName)); this->addTests(tests...); } @@ -145,19 +140,30 @@ namespace TestCPP { void disableTestPassedMessage (); /** - * @brief Calculate the total number of tests in the suite that - * failed after the last suite run. + * @brief Retrieve the total number of tests in the suite that + * failed during the last suite run. * @return The total number of tests that failed in the last * suite run. */ unsigned getLastRunFailCount (); + /** + * @brief Retrieve the total number of tests in the suite that + * succeeded (passed) during the last suite run. + * @return The total number of tests that passed in the last + * suite run. + */ + unsigned getLastRunSuccessCount(); + /** * @brief Run all tests in the test suite. */ void run (); private: + unsigned zeroInit = 0; + + bool firstRun; bool testSuitePassedMessage; bool lastRunSucceeded; unsigned lastRunSuccessCount; @@ -166,6 +172,24 @@ namespace TestCPP { TestObjName suiteName; vector tests; + + // It's ok that this function is removed, because it's private + // and inlined and is not externally visible or used + // externally. + // It's appropriate to suppress this instance of C4514. +#pragma warning(suppress: 4514) + void commonInit(TestObjName&& newSuiteName) { + + this->firstRun = true; + this->testSuitePassedMessage = true; + this->lastRunSucceeded = true; + this->lastRunFailCount = zeroInit; + this->lastRunSuccessCount = zeroInit; + this->totalRuntime = 0; + + this->setSuiteName(std::forward(newSuiteName)); + this->tests = vector(); + } }; } diff --git a/src/TestCPPTestSuite.cpp b/src/TestCPPTestSuite.cpp index ecaf3d6..cfd7f21 100644 --- a/src/TestCPPTestSuite.cpp +++ b/src/TestCPPTestSuite.cpp @@ -74,16 +74,25 @@ namespace TestCPP { return this->lastRunFailCount; } + unsigned TestSuite::getLastRunSuccessCount() { + return this->lastRunSuccessCount; + } + void TestSuite::run () { if (this->tests.size() == 0) { clog << TCPPStr::NTR << endl; return; } - this->lastRunSucceeded = true; - this->lastRunFailCount = 0; - this->lastRunSuccessCount = 0; - this->totalRuntime = 0; + if (!this->firstRun) { + this->lastRunSucceeded = true; + this->lastRunFailCount = zeroInit; + this->lastRunSuccessCount = zeroInit; + this->totalRuntime = 0; + } + else { + this->firstRun = false; + } clog << endl << TCPPStr::START_RUN << TCPPStr::SUITE @@ -160,8 +169,9 @@ namespace TestCPP { * element is the test function that defines the test. */ template<> - void TestSuite::addTest (tuple>&& test) { + void TestSuite::addTest (tuple>&& + test) + { this->tests.emplace_back( std::get<0>(test), std::get<1>(test), diff --git a/test/include/Assertions/AssertionsSuites.h b/test/include/Assertions/AssertionsBasicSuite.h similarity index 99% rename from test/include/Assertions/AssertionsSuites.h rename to test/include/Assertions/AssertionsBasicSuite.h index 87f2e64..c165656 100644 --- a/test/include/Assertions/AssertionsSuites.h +++ b/test/include/Assertions/AssertionsBasicSuite.h @@ -1,7 +1,7 @@ #ifndef TESTCPP_ASSERTIONS_SUITE_ #define TESTCPP_ASSERTIONS_SUITE_ -#include "BasicAssertionsTests.h" +#include "AssertionsBasicTests.h" namespace TestCPP { namespace Testing { diff --git a/test/include/Assertions/BasicAssertionsTests.h b/test/include/Assertions/AssertionsBasicTests.h similarity index 100% rename from test/include/Assertions/BasicAssertionsTests.h rename to test/include/Assertions/AssertionsBasicTests.h diff --git a/test/include/TestSuite/TestSuiteConstructionSuite.h b/test/include/TestSuite/TestSuiteConstructionSuite.h new file mode 100644 index 0000000..fd9e86b --- /dev/null +++ b/test/include/TestSuite/TestSuiteConstructionSuite.h @@ -0,0 +1,42 @@ +#ifndef TESTCPP_TESTSUITE_CONSTRUCTION_SUITE_ +#define TESTCPP_TESTSUITE_CONSTRUCTION_SUITE_ + +#include "TestCPP.h" +#include "TestSuiteTests.h" + +namespace TestCPP { + namespace Testing { + namespace TestSuiteSuites { + TestSuite ctorSuite( + "TestCPP TestSuite Tests - Construction", + + make_tuple( + "Suite construction Test - no tests", + function( + TestSuiteTests::TestConstructSuiteBare + ) + ), + make_tuple( + "Suite construction Test - TestCases", + function( + TestSuiteTests::TestConstructSuiteTestCases + ) + ), + make_tuple( + "Suite construction Test - tuples", + function( + TestSuiteTests::TestConstructSuiteTuples + ) + ), + make_tuple( + "Suite construction Test - mixed", + function( + TestSuiteTests::TestConstructSuiteMixed + ) + ) + ); + } + } +} + +#endif diff --git a/test/include/TestSuite/TestSuiteRunningSuite.h b/test/include/TestSuite/TestSuiteRunningSuite.h new file mode 100644 index 0000000..e7d4511 --- /dev/null +++ b/test/include/TestSuite/TestSuiteRunningSuite.h @@ -0,0 +1,54 @@ +#ifndef TESTCPP_TESTSUITE_SUITERUN_SUITE_ +#define TESTCPP_TESTSUITE_SUITERUN_SUITE_ + +#include "TestCPP.h" +#include "TestSuiteTests.h" + +namespace TestCPP { + namespace Testing { + namespace TestSuiteSuites { + TestSuite runSuite( + "TestCPP TestSuite Tests - Suite Running", + + make_tuple( + "Suite run test - no tests", + function( + TestSuiteTests::TestSuiteRunNoTests + ) + ), + make_tuple( + "Suite run test - one test", + function( + TestSuiteTests::TestSuiteRunOneTest + ) + ), + make_tuple( + "Suite run test - many tests", + function( + TestSuiteTests::TestSuiteRunManyTests + ) + ), + make_tuple( + "Suite run test - no tests twice", + function( + TestSuiteTests::TestSuiteRunNoTestsTwice + ) + ), + make_tuple( + "Suite run test - one test twice", + function( + TestSuiteTests::TestSuiteRunOneTestTwice + ) + ), + make_tuple( + "Suite run test - many tests twice", + function( + TestSuiteTests::TestSuiteRunManyTestsTwice + ) + ) + ); + } + } +} + +#endif diff --git a/test/include/TestSuite/TestSuiteSuite.h b/test/include/TestSuite/TestSuiteTestPassedMessageSuite.h similarity index 59% rename from test/include/TestSuite/TestSuiteSuite.h rename to test/include/TestSuite/TestSuiteTestPassedMessageSuite.h index 68cef2c..6eab880 100644 --- a/test/include/TestSuite/TestSuiteSuite.h +++ b/test/include/TestSuite/TestSuiteTestPassedMessageSuite.h @@ -1,38 +1,15 @@ -#ifndef TESTCPP_TESTSUITE_SUITE_ -#define TESTCPP_TESTSUITE_SUITE_ +#ifndef TESTCPP_TESTSUITE_TESTPASSEDMESSAGE_SUITE_ +#define TESTCPP_TESTSUITE_TESTPASSEDMESSAGE_SUITE_ +#include "TestCPP.h" #include "TestSuiteTests.h" namespace TestCPP { namespace Testing { - namespace TestSuiteSuite { - TestSuite suite( - "TestCPP TestSuite Tests", + namespace TestSuiteSuites { + TestSuite testPassedMessageSuite( + "TestCPP TestSuite Tests - Test Passed Message enable/disable", - make_tuple( - "Suite construction Test - no tests", - function( - TestSuiteTests::TestConstructSuiteBare - ) - ), - make_tuple( - "Suite construction Test - TestCases", - function( - TestSuiteTests::TestConstructSuiteTestCases - ) - ), - make_tuple( - "Suite construction Test - tuples", - function( - TestSuiteTests::TestConstructSuiteTuples - ) - ), - make_tuple( - "Suite construction Test - mixed", - function( - TestSuiteTests::TestConstructSuiteMixed - ) - ), make_tuple( "Suite enable test passed message - no tests", function( diff --git a/test/include/TestSuite/TestSuiteTests.h b/test/include/TestSuite/TestSuiteTests.h index 878c6a6..655b750 100644 --- a/test/include/TestSuite/TestSuiteTests.h +++ b/test/include/TestSuite/TestSuiteTests.h @@ -8,6 +8,12 @@ namespace TestCPP { void TestConstructSuiteTestCases (); void TestConstructSuiteTuples (); void TestConstructSuiteMixed (); + void TestSuiteRunNoTests (); + void TestSuiteRunOneTest (); + void TestSuiteRunManyTests (); + void TestSuiteRunNoTestsTwice (); + void TestSuiteRunOneTestTwice (); + void TestSuiteRunManyTestsTwice (); void TestEnableTestPassedMessageNoTests (); void TestEnableTestPassedMessageOneTest (); void TestEnableTestPassedMessageManyTests (); diff --git a/test/src/Assertions/BasicAssertionsTests.cpp b/test/src/Assertions/AssertionsBasicTests.cpp similarity index 99% rename from test/src/Assertions/BasicAssertionsTests.cpp rename to test/src/Assertions/AssertionsBasicTests.cpp index 99e3764..82d3f83 100644 --- a/test/src/Assertions/BasicAssertionsTests.cpp +++ b/test/src/Assertions/AssertionsBasicTests.cpp @@ -1,5 +1,5 @@ #include "TestCPP.h" -#include "Assertions/BasicAssertionsTests.h" +#include "Assertions/AssertionsBasicTests.h" namespace TestCPP { namespace Testing { diff --git a/test/src/TestCPPAssertionsMain.cpp b/test/src/TestCPPAssertionsBasicMain.cpp similarity index 77% rename from test/src/TestCPPAssertionsMain.cpp rename to test/src/TestCPPAssertionsBasicMain.cpp index 8016bca..04e7c3b 100644 --- a/test/src/TestCPPAssertionsMain.cpp +++ b/test/src/TestCPPAssertionsBasicMain.cpp @@ -6,7 +6,7 @@ using std::string; using std::make_tuple; using std::function; -#include "Assertions/AssertionsSuites.h" +#include "Assertions/AssertionsBasicSuite.h" int main(void) { @@ -17,10 +17,7 @@ int main(void) getLastRunFailCount() ); - int allSuitesFailCount = 0; - allSuitesFailCount += basicSuiteFailCount; - - return allSuitesFailCount; + return basicSuiteFailCount; } catch (std::exception& e) { std::cerr << "Test suite run failed with an exception: " diff --git a/test/src/TestCPPTestSuiteConstructionMain.cpp b/test/src/TestCPPTestSuiteConstructionMain.cpp new file mode 100644 index 0000000..2d39584 --- /dev/null +++ b/test/src/TestCPPTestSuiteConstructionMain.cpp @@ -0,0 +1,25 @@ +#include "TestCPP.h" + +using TestCPP::TestCase; +using TestCPP::TestSuite; +using std::string; +using std::make_tuple; +using std::function; + +#include "TestSuite/TestSuiteConstructionSuite.h" + +int main(void) +{ + try { + TestCPP::Testing::TestSuiteSuites::ctorSuite.run(); + return TestCPP::Util::unsignedToSigned( + TestCPP::Testing::TestSuiteSuites::ctorSuite. + getLastRunFailCount() + ); + } + catch (std::exception& e) { + std::cerr << "Test suite run failed with an exception: " + << e.what() << std::endl; + return -1; + } +} diff --git a/test/src/TestCPPTestSuiteMain.cpp b/test/src/TestCPPTestSuiteRunningMain.cpp similarity index 73% rename from test/src/TestCPPTestSuiteMain.cpp rename to test/src/TestCPPTestSuiteRunningMain.cpp index 8cb0f8a..73b3e70 100644 --- a/test/src/TestCPPTestSuiteMain.cpp +++ b/test/src/TestCPPTestSuiteRunningMain.cpp @@ -6,14 +6,14 @@ using std::string; using std::make_tuple; using std::function; -#include "TestSuite/TestSuiteSuite.h" +#include "TestSuite/TestSuiteRunningSuite.h" int main(void) { try { - TestCPP::Testing::TestSuiteSuite::suite.run(); + TestCPP::Testing::TestSuiteSuites::runSuite.run(); return TestCPP::Util::unsignedToSigned( - TestCPP::Testing::TestSuiteSuite::suite. + TestCPP::Testing::TestSuiteSuites::runSuite. getLastRunFailCount() ); } diff --git a/test/src/TestCPPTestSuiteTestPassedMessageMain.cpp b/test/src/TestCPPTestSuiteTestPassedMessageMain.cpp new file mode 100644 index 0000000..c5390ab --- /dev/null +++ b/test/src/TestCPPTestSuiteTestPassedMessageMain.cpp @@ -0,0 +1,25 @@ +#include "TestCPP.h" + +using TestCPP::TestCase; +using TestCPP::TestSuite; +using std::string; +using std::make_tuple; +using std::function; + +#include "TestSuite/TestSuiteTestPassedMessageSuite.h" + +int main(void) +{ + try { + TestCPP::Testing::TestSuiteSuites::testPassedMessageSuite.run(); + return TestCPP::Util::unsignedToSigned( + TestCPP::Testing::TestSuiteSuites::testPassedMessageSuite. + getLastRunFailCount() + ); + } + catch (std::exception& e) { + std::cerr << "Test suite run failed with an exception: " + << e.what() << std::endl; + return -1; + } +} diff --git a/test/src/TestSuite/TestSuiteConstructionTests.cpp b/test/src/TestSuite/TestSuiteConstructionTests.cpp new file mode 100644 index 0000000..0b4051e --- /dev/null +++ b/test/src/TestSuite/TestSuiteConstructionTests.cpp @@ -0,0 +1,94 @@ +#include "TestCPP.h" +#include "TestSuite/TestSuiteTests.h" + +namespace TestCPP { + namespace Testing { + namespace TestSuiteTests { + void TestConstructSuiteBare () { + auto testSuite = unique_ptr(new TestSuite( + "Suite construction - bare" + )); + } + + void TestConstructSuiteTestCases () { + TestCase test1("dummy 1", [](){}), + test2("dummy 2", [](){}); + + auto testSuite = unique_ptr(new TestSuite( + "Suite construction - TestCases", + test1 + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - TestCases", + test1, test2 + )); + } + + void TestConstructSuiteTuples () { + auto testSuite = unique_ptr(new TestSuite( + "Suite construction - tuples", + make_tuple("dummy 1", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - tuples", + make_tuple("dummy 1", function([](){})), + make_tuple("dummy 2", function([](){})) + )); + } + + void TestConstructSuiteMixed () { + TestCase test1("dummy 1", [](){}), + test2("dummy 2", [](){}); + auto testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, + make_tuple("dummy 1", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, test2, + make_tuple("dummy 1", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, + make_tuple("dummy 1", function([](){})), + make_tuple("dummy 2", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, test2, + make_tuple("dummy 1", function([](){})), + make_tuple("dummy 2", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, + make_tuple("dummy 1", function([](){})), + make_tuple("dummy 2", function([](){})), + test2 + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + make_tuple("dummy 1", function([](){})), + test1, test2, + make_tuple("dummy 2", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + test1, + make_tuple("dummy 1", function([](){})), + test2, + make_tuple("dummy 2", function([](){})) + )); + testSuite = unique_ptr(new TestSuite( + "Suite construction - mixed", + make_tuple("dummy 1", function([](){})), + test2, + make_tuple("dummy 2", function([](){})), + test1 + )); + } + } + } +} diff --git a/test/src/TestSuite/TestSuiteRunningTests.cpp b/test/src/TestSuite/TestSuiteRunningTests.cpp new file mode 100644 index 0000000..986961a --- /dev/null +++ b/test/src/TestSuite/TestSuiteRunningTests.cpp @@ -0,0 +1,114 @@ +#include "TestCPP.h" +#include "TestSuite/TestSuiteTests.h" + +namespace TestCPP { + namespace Testing { + namespace TestSuiteTests { + unsigned zero = 0; + unsigned one = 1; + unsigned three = 3; + + void TestSuiteRunNoTests() { + auto testSuite = unique_ptr(new TestSuite( + "Suite run - no tests" + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(zero, + testSuite->getLastRunSuccessCount()); + } + void TestSuiteRunOneTest() { + TestCase test1("dummy 1", []() {}); + + auto testSuite = unique_ptr(new TestSuite( + "Suite run - one test", + test1 + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(one, + testSuite->getLastRunSuccessCount()); + } + void TestSuiteRunManyTests() { + TestCase test1("dummy 1", []() {}), + test2("dummy 2", []() {}), + test3("dummy 3", []() {}); + + auto testSuite = unique_ptr(new TestSuite( + "Suite run - many tests", + test1, test2, test3 + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(three, + testSuite->getLastRunSuccessCount()); + } + + void TestSuiteRunNoTestsTwice() { + auto testSuite = unique_ptr(new TestSuite( + "Suite double run - no tests" + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(zero, + testSuite->getLastRunSuccessCount()); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(zero, + testSuite->getLastRunSuccessCount()); + } + void TestSuiteRunOneTestTwice() { + TestCase test1("dummy 1", []() {}); + + auto testSuite = unique_ptr(new TestSuite( + "Suite double run - one test", + test1 + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(one, + testSuite->getLastRunSuccessCount()); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(one, + testSuite->getLastRunSuccessCount()); + } + void TestSuiteRunManyTestsTwice() { + TestCase test1("dummy 1", []() {}), + test2("dummy 2", []() {}), + test3("dummy 3", []() {}); + + auto testSuite = unique_ptr(new TestSuite( + "Suite double run - many tests", + test1, test2, test3 + )); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(three, + testSuite->getLastRunSuccessCount()); + + testSuite->run(); + Assertions::assertEquals(zero, + testSuite->getLastRunFailCount()); + Assertions::assertEquals(three, + testSuite->getLastRunSuccessCount()); + } + } + } +} diff --git a/test/src/TestSuite/TestSuiteTests.cpp b/test/src/TestSuite/TestSuiteTestPassedMessageTests.cpp similarity index 80% rename from test/src/TestSuite/TestSuiteTests.cpp rename to test/src/TestSuite/TestSuiteTestPassedMessageTests.cpp index 52189a1..57615a3 100644 --- a/test/src/TestSuite/TestSuiteTests.cpp +++ b/test/src/TestSuite/TestSuiteTestPassedMessageTests.cpp @@ -4,89 +4,6 @@ namespace TestCPP { namespace Testing { namespace TestSuiteTests { - void TestConstructSuiteBare () { - auto testSuite = unique_ptr(new TestSuite( - "Suite construction - bare" - )); - } - void TestConstructSuiteTestCases () { - TestCase test1("dummy 1", [](){}), - test2("dummy 2", [](){}); - - auto testSuite = unique_ptr(new TestSuite( - "Suite construction - TestCases", - test1 - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - TestCases", - test1, test2 - )); - } - void TestConstructSuiteTuples () { - auto testSuite = unique_ptr(new TestSuite( - "Suite construction - tuples", - make_tuple("dummy 1", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - tuples", - make_tuple("dummy 1", function([](){})), - make_tuple("dummy 2", function([](){})) - )); - } - void TestConstructSuiteMixed () { - TestCase test1("dummy 1", [](){}), - test2("dummy 2", [](){}); - auto testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, - make_tuple("dummy 1", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, test2, - make_tuple("dummy 1", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, - make_tuple("dummy 1", function([](){})), - make_tuple("dummy 2", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, test2, - make_tuple("dummy 1", function([](){})), - make_tuple("dummy 2", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, - make_tuple("dummy 1", function([](){})), - make_tuple("dummy 2", function([](){})), - test2 - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - make_tuple("dummy 1", function([](){})), - test1, test2, - make_tuple("dummy 2", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - test1, - make_tuple("dummy 1", function([](){})), - test2, - make_tuple("dummy 2", function([](){})) - )); - testSuite = unique_ptr(new TestSuite( - "Suite construction - mixed", - make_tuple("dummy 1", function([](){})), - test2, - make_tuple("dummy 2", function([](){})), - test1 - )); - } - void TestEnableTestPassedMessageNoTests() { auto testSuite = unique_ptr(new TestSuite( "SUBSUITE - Test Passed Message Enabled - no tests"