From f52050c3363b48327345b105a114a19d2808b1fb Mon Sep 17 00:00:00 2001 From: Malcolm Noyes Date: Tue, 10 Dec 2013 15:28:49 +0000 Subject: [PATCH] Fix output for different versions of VS --- include/internal/catch_config.hpp | 4 ++-- include/internal/catch_vs_test_registry.hpp | 20 ++++++++--------- include/reporters/catch_vs_reporter.hpp | 4 ++++ projects/SelfTest/RunAllTests.cpp | 7 ++++++ scripts/validateVSTests.py | 24 ++++++++++++++++++--- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 712296e5..e68a8b1a 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -192,11 +192,11 @@ namespace CatchOverrides { template struct ConfigReset { - ConfigReset( const std::string& file, int c ) + ConfigReset( const std::string& file, int c, int defaultAbortAfter ) { Config::instance().insertSuccessfulResults(file, c, false); Config::instance().insertMissingAssertions(file, c, false); - Config::instance().insertAbortAfter(file, c, -1); + Config::instance().insertAbortAfter(file, c, defaultAbortAfter); Config::instance().insertTest(file, c, ""); } }; diff --git a/include/internal/catch_vs_test_registry.hpp b/include/internal/catch_vs_test_registry.hpp index 58d748e1..e3b2de67 100644 --- a/include/internal/catch_vs_test_registry.hpp +++ b/include/internal/catch_vs_test_registry.hpp @@ -193,7 +193,7 @@ private: INTERNAL_CATCH_MAP_CATEGORY_TO_TAG2( #Category, Tag, __COUNTER__ ) #define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST( Category ) \ - INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( #Category, __COUNTER__ ) + INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( #Category, #Category, __COUNTER__ ) #define FAIL_STRING( str ) _T( str ) @@ -241,8 +241,8 @@ private: #define INTERNAL_CATCH_MAP_CATEGORY_TO_TAG( Category, Tag ) \ INTERNAL_CATCH_MAP_CATEGORY_TO_TAG2( Category, Tag, __COUNTER__ ) -#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST( Category, List ) \ - INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, List, __COUNTER__ ) +#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST( Category ) \ + INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, #Category, __COUNTER__ ) #define FAIL_STRING( str ) WIDEN( str ) @@ -301,7 +301,7 @@ private: static void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(); \ namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( & INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc(CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name), Desc) ); \ - CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \ + CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, 1); \ INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \ { \ INTERNAL_CATCH_CLASS_CONTEXT \ @@ -314,7 +314,7 @@ private: CHECK_FOR_TEST_CASE_CLASH \ namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( & QualifiedMethod, "&" # QualifiedMethod, Catch::NameAndDesc(CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name), Desc), CATCH_INTERNAL_LINEINFO ); \ - CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \ + CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, 1); \ INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \ { \ INTERNAL_CATCH_CLASS_CONTEXT \ @@ -330,7 +330,7 @@ private: }; \ namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( & INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )::invoke, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc(CATCH_INTERNAL_HANDLE_EMPTY_PARAM(TestName), Desc) ); \ - CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \ + CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, 1); \ INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \ { \ INTERNAL_CATCH_CLASS_CONTEXT \ @@ -363,7 +363,7 @@ private: #define INTERNAL_CATCH_MAP_CATEGORY_TO_TAG2( Category, Tag, Count ) \ CHECK_FOR_TEST_CASE_CLASH \ namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \ - CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \ + CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, -1); \ INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \ { \ INTERNAL_CATCH_CLASS_CONTEXT \ @@ -387,10 +387,10 @@ private: }; \ } -#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, Count ) \ +#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, CategoryName, Count ) \ CHECK_FOR_TEST_CASE_CLASH \ namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \ - CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \ + CatchOverrides::ConfigReset INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, -1); \ INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \ { \ INTERNAL_CATCH_CLASS_CONTEXT \ @@ -401,7 +401,7 @@ private: cd.warnings = (CatchOverrides::Config::instance().warnAboutMissingAssertions(__FILE__, Count ) ? Catch::WarnAbout::NoAssertions : Catch::WarnAbout::Nothing); \ cd.abortAfter = CatchOverrides::Config::instance().abortAfter(__FILE__, Count ); \ cd.reporterName = "vs_reporterlf"; \ - cd.name = "Batch run using category : " Category; \ + cd.name = "Batch run using category : " CategoryName; \ std::vector stringNames = CatchOverrides::Config::instance().listOfTests(__FILE__, Count ); \ Catch::Ptr config(new Catch::Config(cd)); \ Catch::ReporterRegistrar reporterReg("vs_reporterlf"); \ diff --git a/include/reporters/catch_vs_reporter.hpp b/include/reporters/catch_vs_reporter.hpp index 8a158133..4ccc6197 100644 --- a/include/reporters/catch_vs_reporter.hpp +++ b/include/reporters/catch_vs_reporter.hpp @@ -119,7 +119,11 @@ namespace Catch { : VSStreamingReporterBase( _config ), m_prevCout( std::cout.rdbuf() ), m_prevCerr( std::cerr.rdbuf() ), +#if defined(INTERNAL_CATCH_VS_NATIVE) || _MSC_VER >= 1700 + m_addLineFeeds(false), +#else m_addLineFeeds(true), +#endif m_headerPrinted( false ), m_atLeastOneTestCasePrinted( false ) { diff --git a/projects/SelfTest/RunAllTests.cpp b/projects/SelfTest/RunAllTests.cpp index 3da197f4..2a709206 100644 --- a/projects/SelfTest/RunAllTests.cpp +++ b/projects/SelfTest/RunAllTests.cpp @@ -12,7 +12,14 @@ namespace AllTestsRunner { + // VS2010 // mstest /TestContainer:Debug\ManagedTestCatch.dll /category:"all" + // + // VS2012 managed + // vstest.console.exe /Logger:Trx Debug\ManagedTestCatch.dll /TestCaseFilter:"TestCategory=all" + // + // VS2012 native + // vstest.console.exe /Logger:Trx Debug\NativeTestCatch.dll /TestCaseFilter:"Owner=all" #if defined(INTERNAL_CATCH_VS_MANAGED) || defined(INTERNAL_CATCH_VS_NATIVE) CATCH_MAP_CATEGORY_TO_TAG(all, "~[vs]"); diff --git a/scripts/validateVSTests.py b/scripts/validateVSTests.py index 53ca4920..fa17c6c4 100644 --- a/scripts/validateVSTests.py +++ b/scripts/validateVSTests.py @@ -22,8 +22,13 @@ if len(sys.argv) == 2: else: if sys.platform == 'win32': cmdPath = os.path.join( catchPath, 'projects\\VS2010\\TestCatch\\Release\\TestCatch.exe' ) + # VS2010 #dllPath = os.path.join( catchPath, 'projects\\VS2010\\ManagedTestCatch\\Release\\ManagedTestCatch.dll' ) dllPath = os.path.join( catchPath, 'projects\\VS2010\\ManagedTestCatch\\Debug\\ManagedTestCatch.dll' ) + # VS2012 managed + #dllPath = os.path.join( catchPath, 'projects\\VS2012\\ManagedTestCatch\\Debug\\ManagedTestCatch.dll' ) + # VS2012 native + #dllPath = os.path.join( catchPath, 'projects\\VS2012\\NativeTestCatch\\Debug\\NativeTestCatch.dll' ) else: cmdPath = os.path.join( catchPath, 'projects/XCode4/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' ) @@ -705,9 +710,24 @@ def approveMsTest( baseName, filter ): raise Exception("Managed DLL does not exist: '" + dllPath + "'") args = [] + # Options for VS2010 args.append("MSTest.exe") args.append("/testcontainer:" + dllPath) args.append("/category:\"" + filter + "\"") + + # Options for VS2012 managed + #args.append("vstest.console.exe") + #args.append("/Logger:Trx") + #args.append(dllPath) + #args.append("/TestCaseFilter:TestCategory=" + filter) + + # Options for VS2012 native + #args.append("vstest.console.exe") + #args.append("/Logger:Trx") + #args.append(dllPath) + #args.append("/TestCaseFilter:Owner=" + filter) + + #print args f = open( rawResultsPath, 'w' ) subprocess.call( args, stdout=f, stderr=f ) f.close() @@ -715,9 +735,7 @@ def approveMsTest( baseName, filter ): if os.path.exists( rawResultsPath ): f = open( rawResultsPath, 'r' ) for line in f: - #line = "Results file: c:\Projects\Catch\TestResults\NoyesMa_SACHDEW7 2013-12-09 11_43_57.trx" - - if line.startswith("Results file:"): + if line.startswith("Results file:") or line.startswith("Results File:"): trxFile = line[13:].strip() parseTrxFile(baseName, trxFile)