From 08b93ce386c434be146f35e6826b6d5c81b5c480 Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 2 Dec 2014 11:59:01 +0300 Subject: [PATCH] Added -exact-match flag to unit test command line --- tests/cppunit/cppunit_mini.h | 24 +++----------- tests/cppunit/test_main.cpp | 61 ++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/tests/cppunit/cppunit_mini.h b/tests/cppunit/cppunit_mini.h index 198f8f00..46545a74 100644 --- a/tests/cppunit/cppunit_mini.h +++ b/tests/cppunit/cppunit_mini.h @@ -176,25 +176,8 @@ namespace CppUnitMini } } - bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName, - bool invert, bool explicit_test, bool &do_progress) { - if ((in_desiredTest) && (in_desiredTest[0] != '\0')) { - do_progress = false; - const char *ptr = strstr(in_desiredTest, "::"); - if (ptr) { - bool match = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0 && in_desiredTest[strlen(in_className)] == ':' ) - && (strncmp(ptr + 2, in_functionName, strlen(ptr + 2)) == 0); - // Invert shall not make explicit test run: - return invert ? (match ? !match : !explicit_test) - : match; - } - bool match = (strcmp(in_desiredTest, in_className) == 0); - do_progress = match; - return !explicit_test && (match == !invert); - } - do_progress = true; - return !explicit_test; - } + bool shouldRunThis( const char *in_desiredTest, const char *in_className, const char *in_functionName, + bool invert, bool explicit_test, bool &do_progress ); void tearDown() { print_gc_state(); @@ -213,7 +196,8 @@ namespace CppUnitMini public: static bool m_bPrintGCState ; // print GC state after each test static Config m_Cfg; - static std::string m_strTestDataDir; + static std::string m_strTestDataDir; + static bool m_bExactMatch; protected: static int m_numErrors; diff --git a/tests/cppunit/test_main.cpp b/tests/cppunit/test_main.cpp index f886f51f..57727c23 100644 --- a/tests/cppunit/test_main.cpp +++ b/tests/cppunit/test_main.cpp @@ -81,6 +81,7 @@ namespace CppUnitMini bool TestCase::m_bPrintGCState = false; std::string TestCase::m_strTestDataDir("."); Config TestCase::m_Cfg; + bool TestCase::m_bExactMatch = false; TestCase * TestCase::m_pCurTestCase = nullptr; @@ -114,6 +115,35 @@ namespace CppUnitMini return m_numErrors; } + bool TestCase::shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName, + bool invert, bool explicit_test, bool &do_progress) + { + if ((in_desiredTest) && (in_desiredTest[0] != '\0')) { + do_progress = false; + const char *ptr = strstr(in_desiredTest, "::"); + if (ptr) { + bool match; + if ( m_bExactMatch ) { + match = (strncmp( in_desiredTest, in_className, strlen( in_className )) == 0 && in_desiredTest[strlen( in_className )] == ':') + && (strcmp( ptr + 2, in_functionName ) == 0); + } + else { + match = (strncmp( in_desiredTest, in_className, strlen( in_className )) == 0 && in_desiredTest[strlen( in_className )] == ':') + && (strncmp( ptr + 2, in_functionName, strlen( ptr + 2 ) ) == 0); + } + // Invert shall not make explicit test run: + return invert ? (match ? !match : !explicit_test) + : match; + } + bool match = (strcmp(in_desiredTest, in_className) == 0); + do_progress = match; + return !explicit_test && (match == !invert); + } + do_progress = true; + return !explicit_test; + } + + void TestCase::print_gc_state() { if ( m_bPrintGCState ) { @@ -222,11 +252,12 @@ namespace CppUnitMini static void usage(const char* name) { printf("Usage : %s [-t=[::]] [-x=[::]] [-f=] [-m]\n", name); - printf("\t[-t=[::]] : test class or class::test to execute;\n"); - printf("\t[-x=[::]] : test class or class::test to exclude from execution;\n"); - printf("\t[-d=dir] : test data directory (default is .);\n"); - printf("\t[-f=] : output file"); + printf("\t[-t=[::]] : test class or class::test to execute\n"); + printf("\t[-x=[::]] : test class or class::test to exclude from execution\n"); + printf("\t[-d=dir] : test data directory (default is .)\n"); + printf( "\t[-f=] : output file\n" ); //printf(";\n\t[-m] : monitor test execution, display time duration for each test\n"); + printf( "\t[-exact-match] : class::test should be exactly matched to existing test\n" ); printf("\t[-gc_state] : print gc state after each test\n"); printf("\t[-cfg=] : config file name for tests\n"); } @@ -263,31 +294,35 @@ int main(int argc, char** argv) for (int i = 1; i < argc; ++i) { if (argv[i][0] == '-') { - if (!strncmp(argv[i], "-t=", 3)) { + if ( strncmp(argv[i], "-t=", 3) == 0 ) { testName = argv[i]+3; continue; } - else if (!strncmp(argv[i], "-f=", 3)) { + else if ( strncmp(argv[i], "-f=", 3) == 0 ) { fileName = argv[i]+3; continue; } - else if (!strncmp(argv[i], "-x=", 3)) { + else if ( strncmp(argv[i], "-x=", 3) == 0 ) { xtestName = argv[i]+3; continue; } - else if (!strncmp(argv[i], "-d=", 3)) { + else if ( strncmp(argv[i], "-d=", 3) == 0 ) { testDataDir = argv[i] + 3; continue; } - else if ( !strncmp(argv[i], "-m", 2)) { - doMonitoring = true; - continue; + else if ( strncmp( argv[i], "-m", 2 ) == 0 ) { + doMonitoring = true; + continue; + } + else if ( strncmp( argv[i], "-exact-match", 12 ) == 0 ) { + CppUnitMini::TestCase::m_bExactMatch = true; + continue; } - else if (!strncmp(argv[i], "-gc_state", 9)) { + else if ( strncmp(argv[i], "-gc_state", 9) == 0 ) { CppUnitMini::TestCase::m_bPrintGCState = true; continue; } - else if( !strncmp(argv[i], "-cfg=", 5)) { + else if( strncmp(argv[i], "-cfg=", 5) == 0 ) { cfgFileName = argv[i] + 5; continue; } -- 2.34.1