From 907f514de798d0422b8351b7821f5a674b00df1d Mon Sep 17 00:00:00 2001 From: Malcolm Noyes Date: Sun, 17 Nov 2013 14:18:02 +0000 Subject: [PATCH] Add support for Managed tests in VS2010 & VS2012. Add support for Native tests in VS2012 --- .gitignore | 4 +- include/internal/catch_capture.hpp | 63 +- include/internal/catch_runner_impl.hpp | 8 +- include/internal/catch_vs_managed_impl.hpp | 80 ++- include/internal/catch_vs_native_impl.hpp | 76 ++- include/internal/catch_vs_test_registry.hpp | 405 ++++++++++++ include/reporters/catch_vs_reporter.hpp | 458 +++++++++++++ projects/SelfTest/ClassTests.cpp | 12 +- projects/SelfTest/ConditionTests.cpp | 480 +++++++------- projects/SelfTest/ExceptionTests.cpp | 206 +++--- projects/SelfTest/MessageTests.cpp | 142 ++-- projects/SelfTest/MiscTests.cpp | 608 +++++++++--------- projects/SelfTest/TrickyTests.cpp | 156 ++--- projects/SelfTest/VariadicMacrosTests.cpp | 25 +- .../VS2010/ManagedTestCatch/AssemblyInfo.cpp | 34 + .../ManagedTestCatch/Local.testsettings | 10 + .../ManagedTestCatch/ManagedTestCatch.sln | 30 + .../ManagedTestCatch/ManagedTestCatch.vcxproj | 115 ++++ .../ManagedTestCatch.vcxproj.filters | 85 +++ .../ManagedTestCatch/ManagedTestCatch.vsmdi | 6 + .../TraceAndTestImpact.testsettings | 9 + projects/VS2010/ManagedTestCatch/app.ico | Bin 0 -> 1078 bytes projects/VS2010/ManagedTestCatch/app.rc | 52 ++ projects/VS2010/ManagedTestCatch/resource.h | 3 + projects/VS2010/ManagedTestCatch/stdafx.cpp | 5 + projects/VS2010/ManagedTestCatch/stdafx.h | 7 + .../TestCatch/TestCatch.vcxproj.filters | 300 +++++++++ .../VS2012/ManagedTestCatch/AssemblyInfo.cpp | 34 + .../ManagedTestCatch/ManagedTestCatch.sln | 20 + .../ManagedTestCatch/ManagedTestCatch.vcxproj | 125 ++++ .../ManagedTestCatch.vcxproj.filters | 85 +++ projects/VS2012/ManagedTestCatch/app.ico | Bin 0 -> 10134 bytes projects/VS2012/ManagedTestCatch/app.rc | 52 ++ projects/VS2012/ManagedTestCatch/resource.h | 3 + projects/VS2012/ManagedTestCatch/stdafx.cpp | 5 + projects/VS2012/ManagedTestCatch/stdafx.h | 7 + .../NativeTestCatch/NativeTestCatch.sln | 20 + .../NativeTestCatch/NativeTestCatch.vcxproj | 111 ++++ .../NativeTestCatch.vcxproj.filters | 72 +++ projects/VS2012/NativeTestCatch/stdafx.cpp | 9 + projects/VS2012/NativeTestCatch/stdafx.h | 13 + projects/VS2012/NativeTestCatch/targetver.h | 8 + 42 files changed, 3129 insertions(+), 814 deletions(-) create mode 100644 include/internal/catch_vs_test_registry.hpp create mode 100644 include/reporters/catch_vs_reporter.hpp create mode 100644 projects/VS2010/ManagedTestCatch/AssemblyInfo.cpp create mode 100644 projects/VS2010/ManagedTestCatch/Local.testsettings create mode 100644 projects/VS2010/ManagedTestCatch/ManagedTestCatch.sln create mode 100644 projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj create mode 100644 projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj.filters create mode 100644 projects/VS2010/ManagedTestCatch/ManagedTestCatch.vsmdi create mode 100644 projects/VS2010/ManagedTestCatch/TraceAndTestImpact.testsettings create mode 100644 projects/VS2010/ManagedTestCatch/app.ico create mode 100644 projects/VS2010/ManagedTestCatch/app.rc create mode 100644 projects/VS2010/ManagedTestCatch/resource.h create mode 100644 projects/VS2010/ManagedTestCatch/stdafx.cpp create mode 100644 projects/VS2010/ManagedTestCatch/stdafx.h create mode 100644 projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters create mode 100644 projects/VS2012/ManagedTestCatch/AssemblyInfo.cpp create mode 100644 projects/VS2012/ManagedTestCatch/ManagedTestCatch.sln create mode 100644 projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj create mode 100644 projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj.filters create mode 100644 projects/VS2012/ManagedTestCatch/app.ico create mode 100644 projects/VS2012/ManagedTestCatch/app.rc create mode 100644 projects/VS2012/ManagedTestCatch/resource.h create mode 100644 projects/VS2012/ManagedTestCatch/stdafx.cpp create mode 100644 projects/VS2012/ManagedTestCatch/stdafx.h create mode 100644 projects/VS2012/NativeTestCatch/NativeTestCatch.sln create mode 100644 projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj create mode 100644 projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj.filters create mode 100644 projects/VS2012/NativeTestCatch/stdafx.cpp create mode 100644 projects/VS2012/NativeTestCatch/stdafx.h create mode 100644 projects/VS2012/NativeTestCatch/targetver.h diff --git a/.gitignore b/.gitignore index 215fb7f9..d9cfe6d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,12 @@ *.mode1v3 *.ncb *.sdf +*.opensdf *.suo Debug Release +ipch +TestResults *.user *.xcuserstate *.o @@ -14,7 +17,6 @@ xcuserdata CatchSelfTest.xcscheme Breakpoints.xcbkptlist projects/VS2010/TestCatch/_UpgradeReport_Files/ -projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters projects/VisualStudio/TestCatch/UpgradeLog.XML UpgradeLog.XML projects/XCode4/iOSTest/Build/Intermediates/PrecompiledHeaders diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 849dee97..eaef9237 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -16,7 +16,7 @@ #include "catch_context.h" #include "catch_common.h" #include "catch_tostring.hpp" -#include "catch_interfaces_registry_hub.h" +#include "catch_interfaces_reporter.h" #include "internal/catch_compiler_capabilities.h" #include @@ -56,19 +56,70 @@ namespace Catch { .setResultType( matcher.match( arg ) ); } +#if defined(INTERNAL_CATCH_VS_MANAGED) + // TestFailureException not defined for CLR +#else // detect CLR struct TestFailureException{}; +#endif } // end namespace Catch /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_ASSERTIONINFO_NAME INTERNAL_CATCH_UNIQUE_NAME( __assertionInfo ) +#if !defined(INTERNAL_CATCH_VS_MANAGED) && !defined(INTERNAL_CATCH_VS_NATIVE) + + // normal Catch + #define INTERNAL_CATCH_TEST_FAILURE_EXCEPTION const Catch::TestFailureException& + #define INTERNAL_CATCH_TEST_THROW_FAILURE throw Catch::TestFailureException(); + +#else // VS integration + +#if defined(INTERNAL_CATCH_VS_MANAGED) + + #define INTERNAL_CATCH_TEST_THROW_FAILURE \ + { \ + Catch::IResultCapture& cap = Catch::getResultCapture(); \ + const Catch::AssertionResult* r = cap.getLastResult(); \ + std::stringstream _sf; \ + _sf << r->getExpressionInMacro().c_str() << ", " << r->getMessage().c_str(); \ + std::string fail = _sf.str(); \ + Assert::Fail(Catch::convert_string_to_managed(fail)); \ + } + + #define INTERNAL_CATCH_TEST_FAILURE_EXCEPTION AssertFailedException^ +#else + +#if defined(INTERNAL_CATCH_VS_NATIVE) + #define INTERNAL_CATCH_TEST_THROW_FAILURE \ + { \ + Catch::IResultCapture& cap = Catch::getResultCapture(); \ + const Catch::AssertionResult* r = cap.getLastResult(); \ + std::wstringstream _s; \ + _s << r->getSourceInfo().file.c_str(); \ + std::wstring ws = _s.str(); \ + std::string testName = cap.getCurrentTestName(); \ + __LineInfo li(ws.c_str(), testName.c_str(), r->getSourceInfo().line); \ + std::wstringstream _sf; \ + _sf << r->getExpandedExpression().c_str() << ", " << r->getMessage().c_str(); \ + std::wstring ws2 = _sf.str(); \ + Assert::Fail(ws2.c_str(), &li); \ + } + + #define INTERNAL_CATCH_TEST_FAILURE_EXCEPTION const Catch::TestFailureException& + +#endif // INTERNAL_CATCH_VS_MANAGED + +#endif // detect CLR + +#endif // VS integration + /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_ACCEPT_EXPR( evaluatedExpr, resultDisposition, originalExpr ) \ if( Catch::ResultAction::Value internal_catch_action = Catch::getResultCapture().acceptExpression( evaluatedExpr, INTERNAL_CATCH_ASSERTIONINFO_NAME ) ) { \ if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \ - if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \ - if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \ + if( internal_catch_action & Catch::ResultAction::Abort ) { INTERNAL_CATCH_TEST_THROW_FAILURE } \ + if( !Catch::shouldContinueOnFailure( resultDisposition ) ) { INTERNAL_CATCH_TEST_THROW_FAILURE } \ Catch::isTrue( false && originalExpr ); \ } @@ -82,7 +133,7 @@ struct TestFailureException{}; INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, resultDisposition ); \ try { \ INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionDecomposer()->*expr ).endExpression( resultDisposition ), resultDisposition, expr ); \ - } catch( Catch::TestFailureException& ) { \ + } catch( INTERNAL_CATCH_TEST_FAILURE_EXCEPTION ) { \ throw; \ } catch( ... ) { \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \ @@ -121,7 +172,7 @@ struct TestFailureException{}; INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::DidntThrowException ), resultDisposition, false ); \ } \ } \ - catch( Catch::TestFailureException& ) { \ + catch( INTERNAL_CATCH_TEST_FAILURE_EXCEPTION ) { \ throw; \ } \ catch( exceptionType ) { \ @@ -165,7 +216,7 @@ struct TestFailureException{}; INTERNAL_CATCH_ACCEPT_INFO( #arg " " #matcher, macroName, resultDisposition ); \ try { \ INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::expressionResultBuilderFromMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), resultDisposition, false ); \ - } catch( Catch::TestFailureException& ) { \ + } catch( INTERNAL_CATCH_TEST_FAILURE_EXCEPTION ) { \ throw; \ } catch( ... ) { \ INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \ diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 92489a05..bd392f94 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -277,9 +277,15 @@ namespace Catch { } duration = timer.getElapsedSeconds(); } - catch( TestFailureException& ) { +#ifdef INTERNAL_CATCH_VS_MANAGED // detect CLR + catch(AssertFailedException^) { + throw; // CLR always rethrows - stop on first assert + } +#else + catch( INTERNAL_CATCH_TEST_FAILURE_EXCEPTION ) { // This just means the test was aborted due to failure } +#endif catch(...) { ExpressionResultBuilder exResult( ResultWas::ThrewException ); exResult << translateActiveException(); diff --git a/include/internal/catch_vs_managed_impl.hpp b/include/internal/catch_vs_managed_impl.hpp index 1fb80578..df7043a3 100644 --- a/include/internal/catch_vs_managed_impl.hpp +++ b/include/internal/catch_vs_managed_impl.hpp @@ -11,6 +11,84 @@ #ifdef INTERNAL_CATCH_VS_MANAGED +#include +using namespace System; +using namespace System::Text; +using namespace System::Collections::Generic; +using namespace Microsoft::VisualStudio::TestTools::UnitTesting; + +namespace Catch { + inline String^ convert_string_to_managed(const std::string& s) + { + String^ result = gcnew String(s.c_str()); + return result; + } + +} + +#include "internal/catch_timer.hpp" +#include "internal/catch_vs_test_registry.hpp" +#include "reporters/catch_vs_reporter.hpp" + +#include "internal/catch_exception_translator_registry.hpp" + +namespace Catch { + + class ExceptionRegistryHub : public IRegistryHub, public IMutableRegistryHub { + + ExceptionRegistryHub( ExceptionRegistryHub const& ); + void operator=( ExceptionRegistryHub const& ); + + public: // IRegistryHub + ExceptionRegistryHub() { + } + virtual IReporterRegistry const& getReporterRegistry() const { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual ITestCaseRegistry const& getTestCaseRegistry() const { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { + return m_exceptionTranslatorRegistry; + } + + public: // IMutableRegistryHub + virtual void registerReporter( std::string const&, IReporterFactory* ) { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual void registerTest( TestCase const& ) { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual void registerTranslator( const IExceptionTranslator* translator ) { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + + private: + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + }; + + template + struct GlobalRegistryHub + { + static T& instance() + { + if( !theRegistryHub ) + theRegistryHub = new T(); + return *theRegistryHub; + } + static T* theRegistryHub; + }; + template + T* GlobalRegistryHub::theRegistryHub = NULL; + + INTERNAL_CATCH_INLINE IMutableRegistryHub& getMutableRegistryHub() { + return GlobalRegistryHub::instance(); + } + INTERNAL_CATCH_INLINE std::string translateActiveException() { + return GlobalRegistryHub::instance().getExceptionTranslatorRegistry().translateActiveException(); + } + +} #endif -#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED +#endif // TWOBLUECUBES_CATCH_VS_MANAGED_HPP_INCLUDED diff --git a/include/internal/catch_vs_native_impl.hpp b/include/internal/catch_vs_native_impl.hpp index d2b165e3..6930b213 100644 --- a/include/internal/catch_vs_native_impl.hpp +++ b/include/internal/catch_vs_native_impl.hpp @@ -11,6 +11,80 @@ #ifdef INTERNAL_CATCH_VS_NATIVE -#endif +#include "CppUnitTest.h" +using Microsoft::VisualStudio::CppUnitTestFramework::Logger; +using Microsoft::VisualStudio::CppUnitTestFramework::Assert; +using Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo; + +#define INTERNAL_CATCH_INLINE inline + +#include +#include + +#include "internal/catch_timer.hpp" +#include "internal/catch_vs_test_registry.hpp" +#include "reporters/catch_vs_reporter.hpp" + +#include "internal/catch_exception_translator_registry.hpp" + +namespace Catch { + + class ExceptionRegistryHub : public IRegistryHub, public IMutableRegistryHub { + + ExceptionRegistryHub( ExceptionRegistryHub const& ); + void operator=( ExceptionRegistryHub const& ); + + public: // IRegistryHub + ExceptionRegistryHub() { + } + virtual IReporterRegistry const& getReporterRegistry() const { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual ITestCaseRegistry const& getTestCaseRegistry() const { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { + return m_exceptionTranslatorRegistry; + } + + public: // IMutableRegistryHub + virtual void registerReporter( std::string const&, IReporterFactory* ) { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual void registerTest( TestCase const& ) { + throw std::runtime_error("can't do this for Visual Studio tests!"); + } + virtual void registerTranslator( const IExceptionTranslator* translator ) { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + + private: + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + }; + + template + struct GlobalRegistryHub + { + static T& instance() + { + if( !theRegistryHub ) + theRegistryHub = new T(); + return *theRegistryHub; + } + static T* theRegistryHub; + }; + template + T* GlobalRegistryHub::theRegistryHub = NULL; + + INTERNAL_CATCH_INLINE IMutableRegistryHub& getMutableRegistryHub() { + return GlobalRegistryHub::instance(); + } + INTERNAL_CATCH_INLINE std::string translateActiveException() { + return GlobalRegistryHub::instance().getExceptionTranslatorRegistry().translateActiveException(); + } + +} + +#endif // INTERNAL_CATCH_VS_NATIVE #endif // TWOBLUECUBES_CATCH_VS_NATIVE_HPP_INCLUDED diff --git a/include/internal/catch_vs_test_registry.hpp b/include/internal/catch_vs_test_registry.hpp new file mode 100644 index 00000000..a144903a --- /dev/null +++ b/include/internal/catch_vs_test_registry.hpp @@ -0,0 +1,405 @@ +/* + * Created by Malcolm on 6/11/2013. + * Copyright 2013 Malcolm Noyes. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_MSTEST_REGISTRY_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_MSTEST_REGISTRY_HPP_INCLUDED + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +#include "catch_common.h" +#include "catch_interfaces_testcase.h" +#include "internal/catch_compiler_capabilities.h" +//#include "catch_config.hpp" +#include + +namespace Catch { + + typedef void(*TestFunction)(); + + class FreeFunctionTestCase : public SharedImpl { + public: + + FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} + + virtual void invoke() const { + m_fun(); + } + + private: + virtual ~FreeFunctionTestCase(); + + TestFunction m_fun; + }; + + /*inline std::string translateActiveException() { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + throw; + } + @catch (NSException *exception) { + return toString( [exception description] ); + } +#else + throw; +#endif + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + }*/ + +class MethodTestCase : public SharedImpl { + + struct placeholder + { + virtual ~placeholder() {} + virtual placeholder* clone() const = 0; + virtual void invoke() const = 0; + }; + + template + struct holder : public placeholder + { + holder( void (C::*method)() ) : m_method( method ) {} + virtual placeholder* clone() const {return new holder(*this);} + void invoke() const { + C obj; + (obj.*m_method)(); + } + void (C::*m_method)(); + }; + + virtual void invoke() const + { + if( held ) held->invoke(); + } +public: + template + MethodTestCase( void (C::*method)() ) : held(new holder(method) ) {} + ~MethodTestCase() { delete held;} + + +private: + MethodTestCase(); // not implemented + MethodTestCase(const MethodTestCase&); // not implemented + MethodTestCase& operator=(const MethodTestCase&); // not implemented + + placeholder* held; +}; + +typedef void(*TestFunction)(); + +struct NameAndDesc { +#if (_MANAGED == 1) || (_M_CEE == 1) // detect CLR + NameAndDesc( const char* _name = "", const char* _description= "" ) + : name( _name ), description( _description ) + {} + NameAndDesc( const char* _name, int ) + : name( _name ), description( "" ) + {} +#else + NameAndDesc( const wchar_t* _name, const char* _description= "" ) + : name(), description( _description ) + { + stdext::cvt::wstring_convert > conv1; + name = conv1.to_bytes(_name); + } + NameAndDesc( const wchar_t* _name, int ) + : name(), description( "" ) + { + stdext::cvt::wstring_convert > conv1; + name = conv1.to_bytes(_name); + } +#endif + + std::string name; + std::string description; +}; + +} // end namespace Catch + +#if (_MANAGED == 1) || (_M_CEE == 1) // detect CLR + +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM2( name ) name##"" +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM(...) CATCH_INTERNAL_HANDLE_EMPTY_PARAM2( INTERNAL_CATCH_SPLIT_ARGS_2(__VA_ARGS__) ) + +#define INTERNAL_CATCH_CLASS_DEFINITION( cls ) \ + [TestClass] \ + public ref class cls + +#define INTERNAL_CATCH_CLASS_CONTEXT \ + private: \ + TestContext^ testContextInstance; \ + public: \ + property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext \ + { \ + Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get() \ + { \ + return testContextInstance; \ + } \ + System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value) \ + { \ + testContextInstance = value; \ + } \ + }; + +#define CATCH_INTERNAL_NAMESPACE( Ext ) + +#define INTERNAL_CATCH_TEST_METHOD( Method, UniqueExt, Name, Desc ) \ + public: \ + [TestMethod] \ + [Description( CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name) )] \ + [TestProperty( "Description", CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name) )] \ + void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) () \ + { \ + Catch::NameAndDesc name_desc( CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name), Desc ); \ + CATCH_INTERNAL_RUN_SINGLE_TEST( Method ); \ + } + +#define INTERNAL_CATCH_TEST_CLASS_METHOD( Method, UniqueExt, Name, Desc ) \ + public: \ + [TestMethod] \ + [Description( CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name) )] \ + [TestProperty( "Description", CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name) )] \ + void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) () \ + { \ + Catch::NameAndDesc name_desc( CATCH_INTERNAL_HANDLE_EMPTY_PARAM(Name), Desc ); \ + CATCH_INTERNAL_RUN_SINGLE_CLASS_TEST( Method ); \ + } + +#define CHECK_FOR_TEST_CASE_CLASH + +#else // detect CLR + +// Native tests + +#define INTERNAL_CATCH_CLASS_DEFINITION( cls ) \ + TEST_CLASS( cls ) + +#define INTERNAL_CATCH_CLASS_CONTEXT + +#define CATCH_INTERNAL_NAMESPACE( Ext ) INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___N_S_, Ext ) + +#define TEST2( ... ) TEST_IMPL_2( (__VA_ARGS__, 2, 1) ) +#define TEST_IMPL_2(tuple) TEST_IMPL2 tuple +#define TEST_IMPL2( INTERNAL_CATCH_SPLIT_ARG_1,INTERNAL_CATCH_SPLIT_ARG_2,N,...) L#INTERNAL_CATCH_SPLIT_ARG_1 + +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM(...) CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL( (__VA_ARGS__, 2, 1) ) +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL(tuple) CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL2 tuple +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL2( INTERNAL_CATCH_SPLIT_ARG_1,INTERNAL_CATCH_SPLIT_ARG_2,N,...) #INTERNAL_CATCH_SPLIT_ARG_1 +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(...) CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPLW( (__VA_ARGS__, 2, 1) ) +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPLW(tuple) CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL2W tuple +#define CATCH_INTERNAL_HANDLE_EMPTY_PARAM_IMPL2W( INTERNAL_CATCH_SPLIT_ARG_1,INTERNAL_CATCH_SPLIT_ARG_2,N,...) L#INTERNAL_CATCH_SPLIT_ARG_1 + +#define INTERNAL_CATCH_TEST_METHOD( Method, UniqueExt, Name, Desc ) \ + public: \ + BEGIN_TEST_METHOD_ATTRIBUTE( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) ) \ + TEST_OWNER( CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name) ) \ + TEST_DESCRIPTION( CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name) ) \ + END_TEST_METHOD_ATTRIBUTE() \ + TEST_METHOD( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) ) \ + { \ + Catch::NameAndDesc name_desc(CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name), Desc ); \ + CATCH_INTERNAL_RUN_SINGLE_TEST( Method ); \ + } + +#define INTERNAL_CATCH_TEST_CLASS_METHOD( Method, UniqueExt, Name, Desc ) \ + public: \ + BEGIN_TEST_METHOD_ATTRIBUTE( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) ) \ + TEST_OWNER( CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name) ) \ + TEST_DESCRIPTION( CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name) ) \ + END_TEST_METHOD_ATTRIBUTE() \ + TEST_METHOD( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H___M_E_T_H_O_D___, UniqueExt) ) \ + { \ + Catch::NameAndDesc name_desc( CATCH_INTERNAL_HANDLE_EMPTY_PARAMW(Name), Desc ); \ + CATCH_INTERNAL_RUN_SINGLE_CLASS_TEST( Method ); \ + } + +#define CHECK_FOR_TEST_CASE_CLASH void INTERNAL_CATCH_UNIQUE_NAME_LINE( if_you_get_this_error_you_have_a_test_case_name_clash_please_put_a_namespace_around_the_test_case_at_line_, __LINE__ )() {} + +#endif // detect CLR + +#define INTERNAL_CATCH_CONCAT_LINE_COUNTER INTERNAL_CATCH_UNIQUE_NAME_LINE( INTERNAL_CATCH_UNIQUE_NAME_LINE( __LINE__, _ ), __COUNTER__ ) + +#define CATCH_INTERNAL_RUN_SINGLE_TEST( Method ) \ + { Catch::ConfigData cd; \ + cd.name = name_desc.name; \ + Catch::Ptr config(new Catch::Config(cd)); \ + Catch::MSTestReporter* rep = new Catch::MSTestReporter(config.get()); \ + Catch::RunContext tr(config.get(), rep); \ + Catch::TestCase tc = Catch::makeTestCase( new Catch::FreeFunctionTestCase( & Method ), "", name_desc.name, name_desc.description, CATCH_INTERNAL_LINEINFO ); \ + tr.runTest(tc); \ + } + +#define CATCH_INTERNAL_RUN_SINGLE_CLASS_TEST( ClassMethod ) \ + { Catch::ConfigData cd; \ + cd.name = name_desc.name; \ + Catch::Ptr config(new Catch::Config(cd)); \ + Catch::MSTestReporter* rep = new Catch::MSTestReporter(config.get()); \ + Catch::RunContext tr(config.get(), rep); \ + Catch::TestCase tc = Catch::makeTestCase( new Catch::MethodTestCase( & ClassMethod ), # ClassMethod, name_desc.name, name_desc.description, CATCH_INTERNAL_LINEINFO ); \ + tr.runTest(tc); \ + } + +#define INTERNAL_CATCH_TESTCASE2( UniqueExt, Name, Desc ) \ + CHECK_FOR_TEST_CASE_CLASH \ + static void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt )(); \ + namespace CATCH_INTERNAL_NAMESPACE( UniqueExt ) { \ + INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, UniqueExt ) ) \ + { \ + INTERNAL_CATCH_CLASS_CONTEXT \ + INTERNAL_CATCH_TEST_METHOD( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt ), UniqueExt, Name, Desc ) \ + }; \ + } \ + void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt )() + +#define INTERNAL_CATCH_METHOD_AS_TEST_CASE2( QualifiedMethod, UniqueExt, Name, Desc ) \ + CHECK_FOR_TEST_CASE_CLASH \ + namespace CATCH_INTERNAL_NAMESPACE( UniqueExt ) { \ + INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, UniqueExt ) ) \ + { \ + INTERNAL_CATCH_CLASS_CONTEXT \ + INTERNAL_CATCH_TEST_CLASS_METHOD( QualifiedMethod, UniqueExt, Name, Desc ) \ + }; \ + }; + +#define INTERNAL_CATCH_TEST_CASE_METHOD2( ClassName, UniqueExt, TestName, Desc ) \ + CHECK_FOR_TEST_CASE_CLASH \ + struct INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt ) : ClassName { \ + void test(); \ + static void invoke() { INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt ) tmp; tmp.test(); } \ + }; \ + namespace CATCH_INTERNAL_NAMESPACE( UniqueExt ) { \ + INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, UniqueExt ) ) \ + { \ + INTERNAL_CATCH_CLASS_CONTEXT \ + INTERNAL_CATCH_TEST_METHOD( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt )::invoke, UniqueExt, TestName, Desc ) \ + }; \ + } \ + void INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____, UniqueExt )::test() + +//#undef CATCH_CONFIG_VARIADIC_MACROS + +#ifdef CATCH_CONFIG_VARIADIC_MACROS + + #define INTERNAL_CATCH_SPLIT_ARGS_2( ... ) INTERNAL_CATCH_SPLIT_ARGS_IMPL_2((__VA_ARGS__, 2,1)) + #define INTERNAL_CATCH_SPLIT_ARGS_IMPL_2(tuple) INTERNAL_CATCH_SPLIT_ARGS_IMPL2 tuple + #define INTERNAL_CATCH_SPLIT_ARGS_IMPL2(INTERNAL_CATCH_SPLIT_ARG_1,INTERNAL_CATCH_SPLIT_ARG_2,N,...) INTERNAL_CATCH_SPLIT_ARG_1 + #define INTERNAL_CATCH_SPLIT_TAGS( ... ) INTERNAL_CATCH_SPLIT_TAGS_IMPL((__VA_ARGS__, 2,1)) + #define INTERNAL_CATCH_SPLIT_TAGS_IMPL(tuple) INTERNAL_CATCH_SPLIT_TAGS_IMPL_ tuple + #define INTERNAL_CATCH_SPLIT_TAGS_IMPL_(INTERNAL_CATCH_SPLIT_ARG_1,INTERNAL_CATCH_SPLIT_ARG_2,N,...) INTERNAL_CATCH_SPLIT_ARG_2 + + #define INTERNAL_CATCH_TESTCASE( ... ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_CONCAT_LINE_COUNTER, INTERNAL_CATCH_SPLIT_ARGS_2(__VA_ARGS__), INTERNAL_CATCH_SPLIT_TAGS(__VA_ARGS__) ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ + INTERNAL_CATCH_METHOD_AS_TEST_CASE2( QualifiedMethod, INTERNAL_CATCH_CONCAT_LINE_COUNTER, INTERNAL_CATCH_SPLIT_ARGS_2(__VA_ARGS__), INTERNAL_CATCH_SPLIT_TAGS(__VA_ARGS__) ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... )\ + INTERNAL_CATCH_TEST_CASE_METHOD2(ClassName, INTERNAL_CATCH_CONCAT_LINE_COUNTER, INTERNAL_CATCH_SPLIT_ARGS_2(__VA_ARGS__), INTERNAL_CATCH_SPLIT_TAGS(__VA_ARGS__) ) + +#else + /////////////////////////////////////////////////////////////////////////////// + + #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_CONCAT_LINE_COUNTER, Name, Desc ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ + INTERNAL_CATCH_METHOD_AS_TEST_CASE2( QualifiedMethod, INTERNAL_CATCH_CONCAT_LINE_COUNTER, Name, Desc ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ + INTERNAL_CATCH_TEST_CASE_METHOD2(ClassName, INTERNAL_CATCH_CONCAT_LINE_COUNTER, TestName, Desc ) + +#endif + +#include "catch_test_case_info.hpp" +#include "catch_assertionresult.hpp" +#include "catch_expressionresult_builder.hpp" +#include "catch_version.hpp" +#include "catch_text.h" +#include "catch_text.hpp" +#include "catch_runner_impl.hpp" +#include "catch_message.hpp" +#include "catch_context_impl.hpp" +#include "catch_generators_impl.hpp" +#include "catch_test_case_info.hpp" +#include "catch_notimplemented_exception.hpp" + +#include "catch_exception_translator_registry.hpp" + +namespace Catch { + inline NonCopyable::~NonCopyable() {} + inline IShared::~IShared() {} + inline StreamBufBase::~StreamBufBase() throw() {} + inline IContext::~IContext() {} + inline IResultCapture::~IResultCapture() {} + inline ITestCase::~ITestCase() {} + inline ITestCaseRegistry::~ITestCaseRegistry() {} + inline IRegistryHub::~IRegistryHub() {} + inline IMutableRegistryHub::~IMutableRegistryHub() {} + inline IExceptionTranslator::~IExceptionTranslator() {} + inline IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} + inline IReporter::~IReporter() {} + inline IReporterFactory::~IReporterFactory() {} + inline IReporterRegistry::~IReporterRegistry() {} + inline IStreamingReporter::~IStreamingReporter() {} + inline AssertionStats::~AssertionStats() {} + inline SectionStats::~SectionStats() {} + inline TestCaseStats::~TestCaseStats() {} + inline TestGroupStats::~TestGroupStats() {} + inline TestRunStats::~TestRunStats() {} + //CumulativeReporterBase::SectionNode::~SectionNode() {} + //CumulativeReporterBase::~CumulativeReporterBase() {} + + //StreamingReporterBase::~StreamingReporterBase() {} + //ConsoleReporter::~ConsoleReporter() {} + inline IRunner::~IRunner() {} + inline IMutableContext::~IMutableContext() {} + inline IConfig::~IConfig() {} + //XmlReporter::~XmlReporter() {} + //JunitReporter::~JunitReporter() {} + //TestRegistry::~TestRegistry() {} + inline FreeFunctionTestCase::~FreeFunctionTestCase() {} + inline IGeneratorInfo::~IGeneratorInfo() {} + inline IGeneratorsForTest::~IGeneratorsForTest() {} + inline TagParser::~TagParser() {} + inline TagExtracter::~TagExtracter() {} + inline TagExpressionParser::~TagExpressionParser() {} + + inline Matchers::Impl::StdString::Equals::~Equals() {} + inline Matchers::Impl::StdString::Contains::~Contains() {} + inline Matchers::Impl::StdString::StartsWith::~StartsWith() {} + inline Matchers::Impl::StdString::EndsWith::~EndsWith() {} + + inline void Config::dummy() {} + + //INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( "xml", XmlReporter ) +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#endif // TWOBLUECUBES_CATCH_MSTEST_REGISTRY_HPP_INCLUDED diff --git a/include/reporters/catch_vs_reporter.hpp b/include/reporters/catch_vs_reporter.hpp new file mode 100644 index 00000000..54ef5c68 --- /dev/null +++ b/include/reporters/catch_vs_reporter.hpp @@ -0,0 +1,458 @@ +/* + * Created by Malcolm on 4/11/2013. + * Copyright 2013 Malcolm Noyes. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_REPORTER_MSTEST_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_REPORTER_MSTEST_HPP_INCLUDED + +#include "../internal/catch_interfaces_reporter.h" +//#include "../internal/catch_reporter_registrars.hpp" +#include "../internal/catch_text.h" +//#include "../internal/catch_console_colour.hpp" +#include "../internal/catch_version.h" +//#include + +namespace Catch { + +#if (_MANAGED == 1) || (_M_CEE == 1) // detect CLR + + inline void write_output_message(const std::string& msg) + { + String^ tmp = gcnew String(msg.c_str()); + Console::WriteLine(tmp); + } + +#else // detect CLR + +#ifdef _WINDLL + +#ifdef _UNICODE + inline void write_output_message(const std::string& msg) + { + std::wstringstream _s; + _s << msg.c_str(); + std::wstring ws = _s.str(); + Logger::WriteMessage(ws.c_str()); + } +#else + inline void write_output_message(const std::string& msg) + { + Logger::WriteMessage(msg.c_str()); + } +#endif + +#endif // _WINDLL + +#endif // detect CLR + + struct MSTestReporter : SharedImpl { + MSTestReporter( Ptr const& _fullConfig ) + : m_config( _fullConfig ), + m_headerPrinted( false ), + m_atLeastOneTestCasePrinted( false ) + {} + + virtual ~MSTestReporter() { + if( m_atLeastOneTestCasePrinted ) { + write_output_message(stream.str()); + } + } + + static std::string getDescription() { + return "Reports test results to MSTest"; + } + virtual ReporterPreferences getPreferences() const { + ReporterPreferences prefs; + prefs.shouldRedirectStdOut = true; + return prefs; + } + + //base + virtual void noMatchingTestCases( std::string const& ) {} + + virtual void testRunStarting( TestRunInfo const& _testRunInfo ) { + currentTestRunInfo = _testRunInfo; + } + virtual void testGroupStarting( GroupInfo const& _groupInfo ) { + currentGroupInfo = _groupInfo; + } + + virtual void testCaseStarting( TestCaseInfo const& _testInfo ) { + currentTestCaseInfo = _testInfo; + } + virtual void sectionStarting( SectionInfo const& _sectionInfo ) { + m_headerPrinted = false; + m_sectionStack.push_back( _sectionInfo ); + } + + virtual void sectionEnded( SectionStats const& _sectionStats ) { + if( _sectionStats.missingAssertions ) { + lazyPrint(); + if( m_sectionStack.size() > 1 ) + stream << "\r\n" << "No assertions in section"; + else + stream << "\r\n" << "No assertions in test case"; + stream << " '" << _sectionStats.sectionInfo.name << "'" << "\r\n" << "\r\n"; + } + if( m_headerPrinted ) { + if( m_config->showDurations() == ShowDurations::Always ) + stream << "Completed in " << _sectionStats.durationInSeconds << "s" << "\r\n"; + m_headerPrinted = false; + } + else { + if( m_config->showDurations() == ShowDurations::Always ) + stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << "\r\n"; + } + m_sectionStack.pop_back(); + } + virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) { + if( !_testCaseStats.stdOut.empty() ) { + write_output_message(getDoubleDashes()); + write_output_message("Output to std::cout :"); + write_output_message(getDashes()); + write_output_message(_testCaseStats.stdOut); + write_output_message(getDoubleDashes()); + } + if( !_testCaseStats.stdErr.empty() ) { + write_output_message(getDoubleDashes()); + write_output_message("Output to std::cerr :"); + write_output_message(getDashes()); + write_output_message(_testCaseStats.stdErr); + write_output_message(getDoubleDashes()); + } + if( _testCaseStats.totals.assertions.failed ) { + Assert::IsTrue(false, L"At least one test failed - examine output for CHECK failures."); + } + m_headerPrinted = false; + currentTestCaseInfo.reset(); + assert( m_sectionStack.empty() ); + } + virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) { + if( currentGroupInfo.used ) { + printSummaryDivider(); + stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':" << "\r\n"; + printTotals( _testGroupStats.totals ); + stream << "\r\n" << "\r\n"; + } + currentGroupInfo.reset(); + } + virtual void testRunEnded( TestRunStats const& _testRunStats ) { + if( m_atLeastOneTestCasePrinted ) + printTotalsDivider(); + printTotals( _testRunStats.totals ); + stream << "\r\n" << "\r\n"; + currentTestCaseInfo.reset(); + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + // base end + + virtual void assertionStarting( AssertionInfo const& ) { + } + + virtual bool assertionEnded( AssertionStats const& _assertionStats ) { + AssertionResult const& result = _assertionStats.assertionResult; + + // Drop out if result was successful and we're not printing those + if( !m_config->includeSuccessfulResults() && result.isOk() ) + return false; + + lazyPrint(); + + AssertionPrinter printer( stream, _assertionStats ); + printer.print(); + stream << "\r\n"; + return true; + } + + private: + + class AssertionPrinter { + void operator= ( AssertionPrinter const& ); + public: + AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats ) + : stream( _stream ), + stats( _stats ), + result( _stats.assertionResult ), + message( result.getMessage() ), + messages( _stats.infoMessages ) + { + switch( result.getResultType() ) { + case ResultWas::Ok: + passOrFail = "PASSED"; + //if( result.hasMessage() ) + if( _stats.infoMessages.size() == 1 ) + messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; + break; + case ResultWas::ExpressionFailed: + if( result.isOk() ) { + passOrFail = "FAILED - but was ok"; + } + else { + passOrFail = "FAILED"; + } + if( _stats.infoMessages.size() == 1 ) + messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; + break; + case ResultWas::ThrewException: + passOrFail = "FAILED"; + messageLabel = "due to unexpected exception with message"; + break; + case ResultWas::DidntThrowException: + passOrFail = "FAILED"; + messageLabel = "because no exception was thrown where one was expected"; + break; + case ResultWas::Info: + messageLabel = "info"; + break; + case ResultWas::Warning: + messageLabel = "warning"; + break; + case ResultWas::ExplicitFailure: + passOrFail = "FAILED"; + if( _stats.infoMessages.size() == 1 ) + messageLabel = "explicitly with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "explicitly with messages"; + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + passOrFail = "** internal error **"; + break; + } + } + + void print() const { + printSourceInfo(); + if( stats.totals.assertions.total() > 0 ) { + if( result.isOk() ) + stream << "\r\n"; + printResultType(); + printOriginalExpression(); + printReconstructedExpression(); + } + else { + stream << "\r\n"; + } + printMessage(); + } + + private: + void printResultType() const { + if( !passOrFail.empty() ) { + stream << passOrFail << ":" << "\r\n"; + } + } + void printOriginalExpression() const { + if( result.hasExpression() ) { + stream << " "; + stream << result.getExpressionInMacro(); + stream << "\r\n"; + } + } + void printReconstructedExpression() const { + if( result.hasExpandedExpression() ) { + stream << "with expansion:" << "\r\n"; + stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\r\n"; + } + } + void printMessage() const { + if( !messageLabel.empty() ) + stream << messageLabel << ":" << "\r\n"; + for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); + it != itEnd; + ++it ) { + stream << Text( it->message, TextAttributes().setIndent(2) ) << "\r\n"; + } + } + void printSourceInfo() const { + stream << result.getSourceInfo() << ": "; + } + + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + std::string passOrFail; + std::string messageLabel; + std::string message; + std::vector messages; + }; + + void lazyPrint() { + + if( !currentTestRunInfo.used ) + lazyPrintRunInfo(); + if( !currentGroupInfo.used ) + lazyPrintGroupInfo(); + + if( !m_headerPrinted ) { + printTestCaseAndSectionHeader(); + m_headerPrinted = true; + } + m_atLeastOneTestCasePrinted = true; + } + void lazyPrintRunInfo() { + stream << getTildes() << "\r\n"; + stream << "Using Catch v" << libraryVersion::value.majorVersion << "." + << libraryVersion::value.minorVersion << " b" + << libraryVersion::value.buildNumber; + if( libraryVersion::value.branchName != "master" ) + stream << " (" << libraryVersion::value.branchName << ")"; +#if (_MANAGED == 1) || (_M_CEE == 1) // detect CLR + stream << " for a managed MSTest project." << "\r\n"; +#else +#ifdef _WINDLL + stream << " for a native MSTest project." << "\r\n"; +#endif +#endif + + currentTestRunInfo.used = true; + } + void lazyPrintGroupInfo() { + if( currentGroupInfo.some() ) + { + if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) { + printClosedHeader( "Group: " + currentGroupInfo->name ); + currentGroupInfo.used = true; + } + } + } + void printTestCaseAndSectionHeader() { + assert( !m_sectionStack.empty() ); + printOpenHeader( currentTestCaseInfo->name ); + + if( m_sectionStack.size() > 1 ) { + + std::vector::const_iterator + it = m_sectionStack.begin()+1, // Skip first section (test case) + itEnd = m_sectionStack.end(); + for( ; it != itEnd; ++it ) + printHeaderString( it->name, 2 ); + } + + SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; + + if( !lineInfo.empty() ){ + stream << getDashes() << "\r\n"; + stream << lineInfo << "\r\n"; + } + stream << getDots() << "\r\n" << "\r\n"; + } + + void printClosedHeader( std::string const& _name ) { + printOpenHeader( _name ); + stream << getDots() << "\r\n"; + } + void printOpenHeader( std::string const& _name ) { + stream << getDashes() << "\r\n"; + { + printHeaderString( _name ); + } + } + + // if string has a : in first line will set indent to follow it on + // subsequent lines + void printHeaderString( std::string const& _string, std::size_t indent = 0 ) { + std::size_t i = _string.find( ": " ); + if( i != std::string::npos ) + i+=2; + else + i = 0; + stream << Text( _string, TextAttributes() + .setIndent( indent+i) + .setInitialIndent( indent ) ) << "\r\n"; + } + + void printTotals( const Totals& totals ) { + if( totals.assertions.total() == 0 ) { + stream << "No tests ran"; + } + else if( totals.assertions.failed ) { + printCounts( "test case", totals.testCases ); + if( totals.testCases.failed > 0 ) { + stream << " ("; + printCounts( "assertion", totals.assertions ); + stream << ")"; + } + } + else { + stream << "All tests passed (" + << pluralise( totals.assertions.passed, "assertion" ) << " in " + << pluralise( totals.testCases.passed, "test case" ) << ")"; + } + } + void printCounts( std::string const& label, Counts const& counts ) { + if( counts.total() == 1 ) { + stream << "1 " << label << " - "; + if( counts.failed ) + stream << "failed"; + else + stream << "passed"; + } + else { + stream << counts.total() << " " << label << "s "; + if( counts.passed ) { + if( counts.failed ) + stream << "- " << counts.failed << " failed"; + else if( counts.passed == 2 ) + stream << "- both passed"; + else + stream << "- all passed"; + } + else { + if( counts.failed == 2 ) + stream << "- both failed"; + else + stream << "- all failed"; + } + } + } + + void printTotalsDivider() { + stream << getDoubleDashes() << "\r\n"; + } + void printSummaryDivider() { + stream << getDashes() << "\r\n"; + } + static std::string getDashes() { + std::string dashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '-' ); + return dashes; + } + static std::string getDots() { + std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '.' ); + return dots; + } + static std::string getDoubleDashes() { + std::string doubleDashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); + return doubleDashes; + } + static std::string getTildes() { + std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '~' ); + return dots; + } + + private: + Ptr m_config; + std::ostringstream stream; + + LazyStat currentTestRunInfo; + LazyStat currentGroupInfo; + LazyStat currentTestCaseInfo; + + std::vector m_sectionStack; + bool m_headerPrinted; + bool m_atLeastOneTestCasePrinted; + }; + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_REPORTER_MSTEST_HPP_INCLUDED diff --git a/projects/SelfTest/ClassTests.cpp b/projects/SelfTest/ClassTests.cpp index 573f5aaa..78cbda61 100644 --- a/projects/SelfTest/ClassTests.cpp +++ b/projects/SelfTest/ClassTests.cpp @@ -8,7 +8,7 @@ #include "catch.hpp" -namespace +namespace ClassTests { class TestClass { @@ -28,13 +28,13 @@ namespace REQUIRE( s == "world" ); } }; + + // Note: TestClass conflicts with template class with same name in VS2012 native tests + METHOD_AS_TEST_CASE( ClassTests::TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds [class]" ) + METHOD_AS_TEST_CASE( ClassTests::TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails [class]" ) + } - -METHOD_AS_TEST_CASE( TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds [class]" ) -METHOD_AS_TEST_CASE( TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails [class]" ) - - struct Fixture { Fixture() : m_a( 1 ) {} diff --git a/projects/SelfTest/ConditionTests.cpp b/projects/SelfTest/ConditionTests.cpp index b298de1d..93fc3b4e 100644 --- a/projects/SelfTest/ConditionTests.cpp +++ b/projects/SelfTest/ConditionTests.cpp @@ -42,165 +42,167 @@ struct TestDef { // The "failing" tests all use the CHECK macro, which continues if the specific test fails. // This allows us to see all results, even if an earlier check fails -// Equality tests -TEST_CASE( "./succeeding/conditions/equality", - "Equality checks that should succeed" ) -{ +namespace ConditionTests { - TestDef td; - td + "hello" + "hello"; + // Equality tests + TEST_CASE( "./succeeding/conditions/equality", + "Equality checks that should succeed" ) + { + + TestDef td; + td + "hello" + "hello"; - TestData data; + TestData data; - REQUIRE( data.int_seven == 7 ); - REQUIRE( data.float_nine_point_one == Approx( 9.1f ) ); - REQUIRE( data.double_pi == Approx( 3.1415926535 ) ); - REQUIRE( data.str_hello == "hello" ); - REQUIRE( "hello" == data.str_hello ); - REQUIRE( data.str_hello.size() == 5 ); + REQUIRE( data.int_seven == 7 ); + REQUIRE( data.float_nine_point_one == Approx( 9.1f ) ); + REQUIRE( data.double_pi == Approx( 3.1415926535 ) ); + REQUIRE( data.str_hello == "hello" ); + REQUIRE( "hello" == data.str_hello ); + REQUIRE( data.str_hello.size() == 5 ); - double x = 1.1 + 0.1 + 0.1; - REQUIRE( x == Approx( 1.3 ) ); -} + double x = 1.1 + 0.1 + 0.1; + REQUIRE( x == Approx( 1.3 ) ); + } -TEST_CASE( "./failing/conditions/equality", - "Equality checks that should fail" ) -{ - TestData data; + TEST_CASE( "./failing/conditions/equality", + "Equality checks that should fail" ) + { + TestData data; - CHECK( data.int_seven == 6 ); - CHECK( data.int_seven == 8 ); - CHECK( data.int_seven == 0 ); - CHECK( data.float_nine_point_one == Approx( 9.11f ) ); - CHECK( data.float_nine_point_one == Approx( 9.0f ) ); - CHECK( data.float_nine_point_one == Approx( 1 ) ); - CHECK( data.float_nine_point_one == Approx( 0 ) ); - CHECK( data.double_pi == Approx( 3.1415 ) ); - CHECK( data.str_hello == "goodbye" ); - CHECK( data.str_hello == "hell" ); - CHECK( data.str_hello == "hello1" ); - CHECK( data.str_hello.size() == 6 ); + CHECK( data.int_seven == 6 ); + CHECK( data.int_seven == 8 ); + CHECK( data.int_seven == 0 ); + CHECK( data.float_nine_point_one == Approx( 9.11f ) ); + CHECK( data.float_nine_point_one == Approx( 9.0f ) ); + CHECK( data.float_nine_point_one == Approx( 1 ) ); + CHECK( data.float_nine_point_one == Approx( 0 ) ); + CHECK( data.double_pi == Approx( 3.1415 ) ); + CHECK( data.str_hello == "goodbye" ); + CHECK( data.str_hello == "hell" ); + CHECK( data.str_hello == "hello1" ); + CHECK( data.str_hello.size() == 6 ); - double x = 1.1 + 0.1 + 0.1; - CHECK( x == Approx( 1.301 ) ); -} + double x = 1.1 + 0.1 + 0.1; + CHECK( x == Approx( 1.301 ) ); + } -TEST_CASE( "./succeeding/conditions/inequality", - "Inequality checks that should succeed" ) -{ - TestData data; + TEST_CASE( "./succeeding/conditions/inequality", + "Inequality checks that should succeed" ) + { + TestData data; - REQUIRE( data.int_seven != 6 ); - REQUIRE( data.int_seven != 8 ); - REQUIRE( data.float_nine_point_one != Approx( 9.11f ) ); - REQUIRE( data.float_nine_point_one != Approx( 9.0f ) ); - REQUIRE( data.float_nine_point_one != Approx( 1 ) ); - REQUIRE( data.float_nine_point_one != Approx( 0 ) ); - REQUIRE( data.double_pi != Approx( 3.1415 ) ); - REQUIRE( data.str_hello != "goodbye" ); - REQUIRE( data.str_hello != "hell" ); - REQUIRE( data.str_hello != "hello1" ); - REQUIRE( data.str_hello.size() != 6 ); -} + REQUIRE( data.int_seven != 6 ); + REQUIRE( data.int_seven != 8 ); + REQUIRE( data.float_nine_point_one != Approx( 9.11f ) ); + REQUIRE( data.float_nine_point_one != Approx( 9.0f ) ); + REQUIRE( data.float_nine_point_one != Approx( 1 ) ); + REQUIRE( data.float_nine_point_one != Approx( 0 ) ); + REQUIRE( data.double_pi != Approx( 3.1415 ) ); + REQUIRE( data.str_hello != "goodbye" ); + REQUIRE( data.str_hello != "hell" ); + REQUIRE( data.str_hello != "hello1" ); + REQUIRE( data.str_hello.size() != 6 ); + } -TEST_CASE( "./failing/conditions/inequality", - "Inequality checks that should fails" ) -{ - TestData data; + TEST_CASE( "./failing/conditions/inequality", + "Inequality checks that should fails" ) + { + TestData data; - CHECK( data.int_seven != 7 ); - CHECK( data.float_nine_point_one != Approx( 9.1f ) ); - CHECK( data.double_pi != Approx( 3.1415926535 ) ); - CHECK( data.str_hello != "hello" ); - CHECK( data.str_hello.size() != 5 ); -} + CHECK( data.int_seven != 7 ); + CHECK( data.float_nine_point_one != Approx( 9.1f ) ); + CHECK( data.double_pi != Approx( 3.1415926535 ) ); + CHECK( data.str_hello != "hello" ); + CHECK( data.str_hello.size() != 5 ); + } -// Ordering comparison tests -TEST_CASE( "./succeeding/conditions/ordered", - "Ordering comparison checks that should succeed" ) -{ - TestData data; + // Ordering comparison tests + TEST_CASE( "./succeeding/conditions/ordered", + "Ordering comparison checks that should succeed" ) + { + TestData data; - REQUIRE( data.int_seven < 8 ); - REQUIRE( data.int_seven > 6 ); - REQUIRE( data.int_seven > 0 ); - REQUIRE( data.int_seven > -1 ); + REQUIRE( data.int_seven < 8 ); + REQUIRE( data.int_seven > 6 ); + REQUIRE( data.int_seven > 0 ); + REQUIRE( data.int_seven > -1 ); - REQUIRE( data.int_seven >= 7 ); - REQUIRE( data.int_seven >= 6 ); - REQUIRE( data.int_seven <= 7 ); - REQUIRE( data.int_seven <= 8 ); + REQUIRE( data.int_seven >= 7 ); + REQUIRE( data.int_seven >= 6 ); + REQUIRE( data.int_seven <= 7 ); + REQUIRE( data.int_seven <= 8 ); - REQUIRE( data.float_nine_point_one > 9 ); - REQUIRE( data.float_nine_point_one < 10 ); - REQUIRE( data.float_nine_point_one < 9.2 ); + REQUIRE( data.float_nine_point_one > 9 ); + REQUIRE( data.float_nine_point_one < 10 ); + REQUIRE( data.float_nine_point_one < 9.2 ); - REQUIRE( data.str_hello <= "hello" ); - REQUIRE( data.str_hello >= "hello" ); + REQUIRE( data.str_hello <= "hello" ); + REQUIRE( data.str_hello >= "hello" ); - REQUIRE( data.str_hello < "hellp" ); - REQUIRE( data.str_hello < "zebra" ); - REQUIRE( data.str_hello > "hellm" ); - REQUIRE( data.str_hello > "a" ); -} + REQUIRE( data.str_hello < "hellp" ); + REQUIRE( data.str_hello < "zebra" ); + REQUIRE( data.str_hello > "hellm" ); + REQUIRE( data.str_hello > "a" ); + } -TEST_CASE( "./failing/conditions/ordered", - "Ordering comparison checks that should fail" ) -{ - TestData data; + TEST_CASE( "./failing/conditions/ordered", + "Ordering comparison checks that should fail" ) + { + TestData data; - CHECK( data.int_seven > 7 ); - CHECK( data.int_seven < 7 ); - CHECK( data.int_seven > 8 ); - CHECK( data.int_seven < 6 ); - CHECK( data.int_seven < 0 ); - CHECK( data.int_seven < -1 ); + CHECK( data.int_seven > 7 ); + CHECK( data.int_seven < 7 ); + CHECK( data.int_seven > 8 ); + CHECK( data.int_seven < 6 ); + CHECK( data.int_seven < 0 ); + CHECK( data.int_seven < -1 ); - CHECK( data.int_seven >= 8 ); - CHECK( data.int_seven <= 6 ); + CHECK( data.int_seven >= 8 ); + CHECK( data.int_seven <= 6 ); - CHECK( data.float_nine_point_one < 9 ); - CHECK( data.float_nine_point_one > 10 ); - CHECK( data.float_nine_point_one > 9.2 ); + CHECK( data.float_nine_point_one < 9 ); + CHECK( data.float_nine_point_one > 10 ); + CHECK( data.float_nine_point_one > 9.2 ); - CHECK( data.str_hello > "hello" ); - CHECK( data.str_hello < "hello" ); - CHECK( data.str_hello > "hellp" ); - CHECK( data.str_hello > "z" ); - CHECK( data.str_hello < "hellm" ); - CHECK( data.str_hello < "a" ); + CHECK( data.str_hello > "hello" ); + CHECK( data.str_hello < "hello" ); + CHECK( data.str_hello > "hellp" ); + CHECK( data.str_hello > "z" ); + CHECK( data.str_hello < "hellm" ); + CHECK( data.str_hello < "a" ); - CHECK( data.str_hello >= "z" ); - CHECK( data.str_hello <= "a" ); -} + CHECK( data.str_hello >= "z" ); + CHECK( data.str_hello <= "a" ); + } -// Comparisons with int literals -TEST_CASE( "./succeeding/conditions/int literals", - "Comparisons with int literals don't warn when mixing signed/ unsigned" ) -{ - int i = 1; - unsigned int ui = 2; - long l = 3; - unsigned long ul = 4; - char c = 5; - unsigned char uc = 6; + // Comparisons with int literals + TEST_CASE( "./succeeding/conditions/int literals", + "Comparisons with int literals don't warn when mixing signed/ unsigned" ) + { + int i = 1; + unsigned int ui = 2; + long l = 3; + unsigned long ul = 4; + char c = 5; + unsigned char uc = 6; - REQUIRE( i == 1 ); - REQUIRE( ui == 2 ); - REQUIRE( l == 3 ); - REQUIRE( ul == 4 ); - REQUIRE( c == 5 ); - REQUIRE( uc == 6 ); + REQUIRE( i == 1 ); + REQUIRE( ui == 2 ); + REQUIRE( l == 3 ); + REQUIRE( ul == 4 ); + REQUIRE( c == 5 ); + REQUIRE( uc == 6 ); - REQUIRE( 1 == i ); - REQUIRE( 2 == ui ); - REQUIRE( 3 == l ); - REQUIRE( 4 == ul ); - REQUIRE( 5 == c ); - REQUIRE( 6 == uc ); + REQUIRE( 1 == i ); + REQUIRE( 2 == ui ); + REQUIRE( 3 == l ); + REQUIRE( 4 == ul ); + REQUIRE( 5 == c ); + REQUIRE( 6 == uc ); - REQUIRE( (std::numeric_limits::max)() > ul ); -} + REQUIRE( (std::numeric_limits::max)() > ul ); + } // Disable warnings about sign conversions for the next two tests // (as we are deliberately invoking them) @@ -214,63 +216,63 @@ TEST_CASE( "./succeeding/conditions/int literals", #pragma warning(disable:4389) // '==' : signed/unsigned mismatch #endif -TEST_CASE( "./succeeding/conditions//long_to_unsigned_x", - "comparisons between int variables" ) -{ - long long_var = 1L; - unsigned char unsigned_char_var = 1; - unsigned short unsigned_short_var = 1; - unsigned int unsigned_int_var = 1; - unsigned long unsigned_long_var = 1L; + TEST_CASE( "./succeeding/conditions//long_to_unsigned_x", + "comparisons between int variables" ) + { + long long_var = 1L; + unsigned char unsigned_char_var = 1; + unsigned short unsigned_short_var = 1; + unsigned int unsigned_int_var = 1; + unsigned long unsigned_long_var = 1L; - REQUIRE( long_var == unsigned_char_var ); - REQUIRE( long_var == unsigned_short_var ); - REQUIRE( long_var == unsigned_int_var ); - REQUIRE( long_var == unsigned_long_var ); -} + REQUIRE( long_var == unsigned_char_var ); + REQUIRE( long_var == unsigned_short_var ); + REQUIRE( long_var == unsigned_int_var ); + REQUIRE( long_var == unsigned_long_var ); + } -TEST_CASE( "./succeeding/conditions/const ints to int literal", - "comparisons between const int variables" ) -{ - const unsigned char unsigned_char_var = 1; - const unsigned short unsigned_short_var = 1; - const unsigned int unsigned_int_var = 1; - const unsigned long unsigned_long_var = 1L; + TEST_CASE( "./succeeding/conditions/const ints to int literal", + "comparisons between const int variables" ) + { + const unsigned char unsigned_char_var = 1; + const unsigned short unsigned_short_var = 1; + const unsigned int unsigned_int_var = 1; + const unsigned long unsigned_long_var = 1L; - REQUIRE( unsigned_char_var == 1 ); - REQUIRE( unsigned_short_var == 1 ); - REQUIRE( unsigned_int_var == 1 ); - REQUIRE( unsigned_long_var == 1 ); -} + REQUIRE( unsigned_char_var == 1 ); + REQUIRE( unsigned_short_var == 1 ); + REQUIRE( unsigned_int_var == 1 ); + REQUIRE( unsigned_long_var == 1 ); + } -TEST_CASE( "./succeeding/conditions/negative ints", - "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" ) -{ - CHECK( ( -1 > 2u ) ); - CHECK( -1 > 2u ); + TEST_CASE( "./succeeding/conditions/negative ints", + "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" ) + { + CHECK( ( -1 > 2u ) ); + CHECK( -1 > 2u ); - CHECK( ( 2u < -1 ) ); - CHECK( 2u < -1 ); + CHECK( ( 2u < -1 ) ); + CHECK( 2u < -1 ); - const int minInt = (std::numeric_limits::min)(); - CHECK( ( minInt > 2u ) ); - CHECK( minInt > 2u ); -} + const int minInt = (std::numeric_limits::min)(); + CHECK( ( minInt > 2u ) ); + CHECK( minInt > 2u ); + } -template -struct Ex -{ - Ex( T ){} + template + struct Ex + { + Ex( T ){} - bool operator == ( const T& ) const { return true; } - T operator * ( const T& ) const { return T(); } -}; + bool operator == ( const T& ) const { return true; } + T operator * ( const T& ) const { return T(); } + }; -TEST_CASE( "./succeeding/conditions/computed ints", - "Comparisons between ints where one side is computed" ) -{ - CHECK( 54 == 6*9 ); -} + TEST_CASE( "./succeeding/conditions/computed ints", + "Comparisons between ints where one side is computed" ) + { + CHECK( 54 == 6*9 ); + } #ifdef __GNUC__ #pragma GCC diagnostic pop @@ -279,70 +281,70 @@ TEST_CASE( "./succeeding/conditions/computed ints", inline const char* returnsConstNull(){ return NULL; } inline char* returnsNull(){ return NULL; } -TEST_CASE( "./succeeding/conditions/ptr", - "Pointers can be compared to null" ) -{ - TestData* p = NULL; - TestData* pNULL = NULL; + TEST_CASE( "./succeeding/conditions/ptr", + "Pointers can be compared to null" ) + { + TestData* p = NULL; + TestData* pNULL = NULL; - REQUIRE( p == NULL ); - REQUIRE( p == pNULL ); + REQUIRE( p == NULL ); + REQUIRE( p == pNULL ); - TestData data; - p = &data; + TestData data; + p = &data; - REQUIRE( p != NULL ); + REQUIRE( p != NULL ); - const TestData* cp = p; - REQUIRE( cp != NULL ); + const TestData* cp = p; + REQUIRE( cp != NULL ); - const TestData* const cpc = p; - REQUIRE( cpc != NULL ); + const TestData* const cpc = p; + REQUIRE( cpc != NULL ); - REQUIRE( returnsNull() == NULL ); - REQUIRE( returnsConstNull() == NULL ); + REQUIRE( returnsNull() == NULL ); + REQUIRE( returnsConstNull() == NULL ); - REQUIRE( NULL != p ); + REQUIRE( NULL != p ); + } + + // Not (!) tests + // The problem with the ! operator is that it has right-to-left associativity. + // This means we can't isolate it when we decompose. The simple REQUIRE( !false ) form, therefore, + // cannot have the operand value extracted. The test will work correctly, and the situation + // is detected and a warning issued. + // An alternative form of the macros (CHECK_FALSE and REQUIRE_FALSE) can be used instead to capture + // the operand value. + TEST_CASE( "./succeeding/conditions/not", + "'Not' checks that should succeed" ) + { + bool falseValue = false; + + REQUIRE( false == false ); + REQUIRE( true == true ); + REQUIRE( !false ); + REQUIRE_FALSE( false ); + + REQUIRE( !falseValue ); + REQUIRE_FALSE( falseValue ); + + REQUIRE( !(1 == 2) ); + REQUIRE_FALSE( 1 == 2 ); + } + + TEST_CASE( "./failing/conditions/not", + "'Not' checks that should fail" ) + { + bool trueValue = true; + + CHECK( false != false ); + CHECK( true != true ); + CHECK( !true ); + CHECK_FALSE( true ); + + CHECK( !trueValue ); + CHECK_FALSE( trueValue ); + + CHECK( !(1 == 1) ); + CHECK_FALSE( 1 == 1 ); + } } - -// Not (!) tests -// The problem with the ! operator is that it has right-to-left associativity. -// This means we can't isolate it when we decompose. The simple REQUIRE( !false ) form, therefore, -// cannot have the operand value extracted. The test will work correctly, and the situation -// is detected and a warning issued. -// An alternative form of the macros (CHECK_FALSE and REQUIRE_FALSE) can be used instead to capture -// the operand value. -TEST_CASE( "./succeeding/conditions/not", - "'Not' checks that should succeed" ) -{ - bool falseValue = false; - - REQUIRE( false == false ); - REQUIRE( true == true ); - REQUIRE( !false ); - REQUIRE_FALSE( false ); - - REQUIRE( !falseValue ); - REQUIRE_FALSE( falseValue ); - - REQUIRE( !(1 == 2) ); - REQUIRE_FALSE( 1 == 2 ); -} - -TEST_CASE( "./failing/conditions/not", - "'Not' checks that should fail" ) -{ - bool trueValue = true; - - CHECK( false != false ); - CHECK( true != true ); - CHECK( !true ); - CHECK_FALSE( true ); - - CHECK( !trueValue ); - CHECK_FALSE( trueValue ); - - CHECK( !(1 == 1) ); - CHECK_FALSE( 1 == 1 ); -} - diff --git a/projects/SelfTest/ExceptionTests.cpp b/projects/SelfTest/ExceptionTests.cpp index 123e8cef..a175df4d 100644 --- a/projects/SelfTest/ExceptionTests.cpp +++ b/projects/SelfTest/ExceptionTests.cpp @@ -28,116 +28,120 @@ namespace } } -TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) +namespace ExceptionTests { - REQUIRE_THROWS_AS( thisThrows(), std::domain_error ); - REQUIRE_NOTHROW( thisDoesntThrow() ); - REQUIRE_THROWS( thisThrows() ); -} -TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) -{ - CHECK_THROWS_AS( thisThrows(), std::string ); - CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error ); - CHECK_NOTHROW( thisThrows() ); -} - -TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) -{ - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); -} - -TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) -{ - CHECK( 1 == 1 ); - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); -} -TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" ) -{ - SECTION( "section name", "" ) + TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) { - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); + REQUIRE_THROWS_AS( thisThrows(), std::domain_error ); + REQUIRE_NOTHROW( thisDoesntThrow() ); + REQUIRE_THROWS( thisThrows() ); } -} -TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) -{ - CHECK( thisThrows() == 0 ); -} - -TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) -{ - try + TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) { - throw std::domain_error( "unexpected exception" ); + CHECK_THROWS_AS( thisThrows(), std::string ); + CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error ); + CHECK_NOTHROW( thisThrows() ); } - catch(...) - { - } -} -class CustomException -{ -public: - CustomException( const std::string& msg ) - : m_msg( msg ) - {} + TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) + { + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); + } + + TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) + { + CHECK( 1 == 1 ); + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); + } + TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" ) + { + SECTION( "section name", "" ) + { + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); + } + } + + TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) + { + CHECK( thisThrows() == 0 ); + } + + TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) + { + try + { + throw std::domain_error( "unexpected exception" ); + } + catch(...) + { + } + } + + class CustomException + { + public: + CustomException( const std::string& msg ) + : m_msg( msg ) + {} - std::string getMessage() const - { - return m_msg; - } + std::string getMessage() const + { + return m_msg; + } -private: - std::string m_msg; -}; + private: + std::string m_msg; + }; -CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) -{ - return ex.getMessage(); -} - -CATCH_TRANSLATE_EXCEPTION( double& ex ) -{ - return Catch::toString( ex ); -} - -TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) -{ - if( Catch::isTrue( true ) ) - throw CustomException( "custom exception" ); -} - -inline void throwCustom() { - if( Catch::isTrue( true ) ) - throw CustomException( "custom exception - not std" ); -} - -TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" ) -{ - REQUIRE_NOTHROW( throwCustom() ); -} - -TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" ) -{ - REQUIRE_THROWS_AS( throwCustom(), std::exception ); -} - - -TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated" ) -{ - if( Catch::isTrue( true ) ) - throw double( 3.14 ); -} - -inline int thisFunctionNotImplemented( int ) { - CATCH_NOT_IMPLEMENTED; -} - -TEST_CASE( "./succeeding/exceptions/notimplemented", "" ) -{ - REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ); + CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) + { + return ex.getMessage(); + } + + CATCH_TRANSLATE_EXCEPTION( double& ex ) + { + return Catch::toString( ex ); + } + + TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) + { + if( Catch::isTrue( true ) ) + throw CustomException( "custom exception" ); + } + + inline void throwCustom() { + if( Catch::isTrue( true ) ) + throw CustomException( "custom exception - not std" ); + } + + TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" ) + { + REQUIRE_NOTHROW( throwCustom() ); + } + + TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" ) + { + REQUIRE_THROWS_AS( throwCustom(), std::exception ); + } + + + TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated" ) + { + if( Catch::isTrue( true ) ) + throw double( 3.14 ); + } + + inline int thisFunctionNotImplemented( int ) { + CATCH_NOT_IMPLEMENTED; + } + + TEST_CASE( "./succeeding/exceptions/notimplemented", "" ) + { + REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ); + } } diff --git a/projects/SelfTest/MessageTests.cpp b/projects/SelfTest/MessageTests.cpp index 9ba6eaec..0a02bb24 100644 --- a/projects/SelfTest/MessageTests.cpp +++ b/projects/SelfTest/MessageTests.cpp @@ -8,95 +8,99 @@ #include "catch.hpp" -TEST_CASE( "./succeeding/message", "INFO and WARN do not abort tests" ) +namespace MessageTests { - INFO( "this is a " << "message" ); // This should output the message if a failure occurs - WARN( "this is a " << "warning" ); // This should always output the message but then continue -} -TEST_CASE( "./succeeding/succeed", "SUCCEED counts as a test pass" ) -{ - SUCCEED( "this is a " << "success" ); -} -TEST_CASE( "./failing/message/info/1", "INFO gets logged on failure" ) -{ - INFO( "this message should be logged" ); - INFO( "so should this" ); - int a = 2; - REQUIRE( a == 1 ); -} + TEST_CASE( "./succeeding/message", "INFO and WARN do not abort tests" ) + { + INFO( "this is a " << "message" ); // This should output the message if a failure occurs + WARN( "this is a " << "warning" ); // This should always output the message but then continue + } + TEST_CASE( "./succeeding/succeed", "SUCCEED counts as a test pass" ) + { + SUCCEED( "this is a " << "success" ); + } -TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" ) -{ - INFO( "this message may be logged later" ); - int a = 2; - CHECK( a == 2 ); + TEST_CASE( "./failing/message/info/1", "INFO gets logged on failure" ) + { + INFO( "this message should be logged" ); + INFO( "so should this" ); + int a = 2; + REQUIRE( a == 1 ); + } - INFO( "this message should be logged" ); + TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" ) + { + INFO( "this message may be logged later" ); + int a = 2; + CHECK( a == 2 ); + + INFO( "this message should be logged" ); - CHECK( a == 1 ); + CHECK( a == 1 ); - INFO( "and this, but later" ); + INFO( "and this, but later" ); - CHECK( a == 0 ); + CHECK( a == 0 ); - INFO( "but not this" ); + INFO( "but not this" ); - CHECK( a == 2 ); -} - -TEST_CASE( "./failing/message/fail", "FAIL aborts the test" ) -{ - if( Catch::isTrue( true ) ) - FAIL( "This is a " << "failure" ); // This should output the message and abort -} - -TEST_CASE( "./failing/message/sections", "Output from all sections is reported" ) -{ - SECTION( "one", "" ) - { - FAIL( "Message from section one" ); + CHECK( a == 2 ); } - SECTION( "two", "" ) + TEST_CASE( "./failing/message/fail", "FAIL aborts the test" ) { - FAIL( "Message from section two" ); + if( Catch::isTrue( true ) ) + FAIL( "This is a " << "failure" ); // This should output the message and abort } -} -TEST_CASE( "./succeeding/message/sections/stdout", "Output from all sections is reported" ) -{ - SECTION( "one", "" ) + TEST_CASE( "./failing/message/sections", "Output from all sections is reported" ) { - std::cout << "Message from section one" << std::endl; + SECTION( "one", "" ) + { + FAIL( "Message from section one" ); + } + + SECTION( "two", "" ) + { + FAIL( "Message from section two" ); + } } + + TEST_CASE( "./succeeding/message/sections/stdout", "Output from all sections is reported" ) + { + SECTION( "one", "" ) + { + std::cout << "Message from section one" << std::endl; + } - SECTION( "two", "" ) - { - std::cout << "Message from section two" << std::endl; + SECTION( "two", "" ) + { + std::cout << "Message from section two" << std::endl; + } } -} -TEST_CASE( "./mixed/message/scoped", "" ) -{ - for( int i=0; i<100; i++ ) + TEST_CASE( "./mixed/message/scoped", "" ) { - SCOPED_INFO( "current counter " << i ); - SCOPED_CAPTURE( i ); - REQUIRE( i < 10 ); + for( int i=0; i<100; i++ ) + { + SCOPED_INFO( "current counter " << i ); + SCOPED_CAPTURE( i ); + REQUIRE( i < 10 ); + } } -} -TEST_CASE( "./succeeding/nofail", "The NO_FAIL macro reports a failure but does not fail the test" ) -{ - CHECK_NOFAIL( 1 == 2 ); -} + TEST_CASE( "./succeeding/nofail", "The NO_FAIL macro reports a failure but does not fail the test" ) + { + CHECK_NOFAIL( 1 == 2 ); + } -TEST_CASE( "just info", "[info][isolated info][.]" ) -{ - INFO( "this should never be seen" ); -} -TEST_CASE( "just failure", "[fail][isolated info][.]" ) -{ - FAIL( "Previous info should not be seen" ); -} + TEST_CASE( "just info", "[info][isolated info][.]" ) + { + INFO( "this should never be seen" ); + } + TEST_CASE( "just failure", "[fail][isolated info][.]" ) + { + FAIL( "Previous info should not be seen" ); + } + } diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index ad3b239c..e980fb84 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -11,356 +11,360 @@ #include -TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" ) +namespace MiscTests { - int a = 1; - int b = 2; - - SECTION( "s1", "doesn't equal" ) - { - REQUIRE( a != b ); - REQUIRE( b != a ); - } - SECTION( "s2", "not equal" ) + TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" ) { - REQUIRE( a != b); - } -} - -TEST_CASE( "./succeeding/Misc/Sections/nested", "nested SECTION tests" ) -{ - int a = 1; - int b = 2; + int a = 1; + int b = 2; - SECTION( "s1", "doesn't equal" ) - { - REQUIRE( a != b ); - REQUIRE( b != a ); + SECTION( "s1", "doesn't equal" ) + { + REQUIRE( a != b ); + REQUIRE( b != a ); + } SECTION( "s2", "not equal" ) { REQUIRE( a != b); } } -} -TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" ) -{ - int a = 1; - int b = 2; - - SECTION( "s1", "doesn't equal" ) + TEST_CASE( "./succeeding/Misc/Sections/nested", "nested SECTION tests" ) { - SECTION( "s2", "equal" ) - { - REQUIRE( a == b ); - } - - SECTION( "s3", "not equal" ) + int a = 1; + int b = 2; + + SECTION( "s1", "doesn't equal" ) { REQUIRE( a != b ); - } - SECTION( "s4", "less than" ) - { - REQUIRE( a < b ); + REQUIRE( b != a ); + + SECTION( "s2", "not equal" ) + { + REQUIRE( a != b); + } } } -} -TEST_CASE( "./Sections/nested/a/b", "nested SECTION tests" ) -{ - SECTION( "c", "" ) + TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" ) { - SECTION( "d (leaf)", "" ) + int a = 1; + int b = 2; + + SECTION( "s1", "doesn't equal" ) { + SECTION( "s2", "equal" ) + { + REQUIRE( a == b ); + } + + SECTION( "s3", "not equal" ) + { + REQUIRE( a != b ); + } + SECTION( "s4", "less than" ) + { + REQUIRE( a < b ); + } } + } + + TEST_CASE( "./Sections/nested/a/b", "nested SECTION tests" ) + { + SECTION( "c", "" ) + { + SECTION( "d (leaf)", "" ) + { + } - SECTION( "e (leaf)", "" ) + SECTION( "e (leaf)", "" ) + { + } + } + + SECTION( "f (leaf)", "" ) { } } - SECTION( "f (leaf)", "" ) + TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" ) { - } -} - -TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" ) -{ - int a = 1; + int a = 1; - for( int b = 0; b < 10; ++b ) - { - std::ostringstream oss; - oss << "b is currently: " << b; - SECTION( "s1", oss.str() ) + for( int b = 0; b < 10; ++b ) { - CHECK( b > a ); + std::ostringstream oss; + oss << "b is currently: " << b; + SECTION( "s1", oss.str() ) + { + CHECK( b > a ); + } } } -} -TEST_CASE( "./mixed/Misc/loops", "looped tests" ) -{ - static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; - - for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i ) + TEST_CASE( "./mixed/Misc/loops", "looped tests" ) { - INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" ); - CHECK( ( fib[i] % 2 ) == 0 ); - } -} - -TEST_CASE( "./succeeding/Misc/stdout,stderr", "Sends stuff to stdout and stderr" ) -{ - std::cout << "Some information" << std::endl; + static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; - std::cerr << "An error" << std::endl; -} + for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i ) + { + INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" ); + CHECK( ( fib[i] % 2 ) == 0 ); + } + } -inline const char* makeString( bool makeNull ) -{ - return makeNull ? NULL : "valid string"; -} + TEST_CASE( "./succeeding/Misc/stdout,stderr", "Sends stuff to stdout and stderr" ) + { + std::cout << "Some information" << std::endl; + + std::cerr << "An error" << std::endl; + } -TEST_CASE( "./succeeding/Misc/null strings", "" ) -{ - REQUIRE( makeString( false ) != static_cast(NULL)); - REQUIRE( makeString( true ) == static_cast(NULL)); -} + inline const char* makeString( bool makeNull ) + { + return makeNull ? NULL : "valid string"; + } -TEST_CASE( "./failing/info", "sends information to INFO" ) -{ - INFO( "hi" ); - int i = 7; - CAPTURE( i ); - REQUIRE( false ); -} + TEST_CASE( "./succeeding/Misc/null strings", "" ) + { + REQUIRE( makeString( false ) != static_cast(NULL)); + REQUIRE( makeString( true ) == static_cast(NULL)); + } -inline bool testCheckedIf( bool flag ) -{ - CHECKED_IF( flag ) + TEST_CASE( "./failing/info", "sends information to INFO" ) + { + INFO( "hi" ); + int i = 7; + CAPTURE( i ); + REQUIRE( false ); + } + + inline bool testCheckedIf( bool flag ) + { + CHECKED_IF( flag ) + return true; + else + return false; + } + + TEST_CASE( "./succeeding/checkedif", "" ) + { + REQUIRE( testCheckedIf( true ) ); + } + + TEST_CASE( "./failing/checkedif", "" ) + { + REQUIRE( testCheckedIf( false ) ); + } + + inline bool testCheckedElse( bool flag ) + { + CHECKED_ELSE( flag ) + return false; + return true; - else - return false; -} + } -TEST_CASE( "./succeeding/checkedif", "" ) -{ - REQUIRE( testCheckedIf( true ) ); -} - -TEST_CASE( "./failing/checkedif", "" ) -{ - REQUIRE( testCheckedIf( false ) ); -} - -inline bool testCheckedElse( bool flag ) -{ - CHECKED_ELSE( flag ) - return false; - - return true; -} - -TEST_CASE( "./succeeding/checkedelse", "" ) -{ - REQUIRE( testCheckedElse( true ) ); -} - -TEST_CASE( "./failing/checkedelse", "" ) -{ - REQUIRE( testCheckedElse( false ) ); -} - -TEST_CASE( "./misc/xmlentitycheck", "" ) -{ - SECTION( "embedded xml", "it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) + TEST_CASE( "./succeeding/checkedelse", "" ) { - // No test + REQUIRE( testCheckedElse( true ) ); } - SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) + + TEST_CASE( "./failing/checkedelse", "" ) { - // No test + REQUIRE( testCheckedElse( false ) ); } -} -TEST_CASE( "./manual/onechar", "send a single char to INFO" ) -{ - INFO(3); - REQUIRE(false); -} - -TEST_CASE("./succeeding/atomic if", "") -{ - size_t x = 0; - - if( x ) - REQUIRE(x > 0); - else - REQUIRE(x == 0); -} - -inline const char* testStringForMatching() -{ - return "this string contains 'abc' as a substring"; -} - -TEST_CASE("./succeeding/matchers", "") -{ - REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); - CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); - - CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); - CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ); -} - -TEST_CASE("./failing/matchers/Contains", "") -{ - CHECK_THAT( testStringForMatching(), Contains( "not there" ) ); -} - -TEST_CASE("./failing/matchers/StartsWith", "") -{ - CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ); -} - -TEST_CASE("./failing/matchers/EndsWith", "") -{ - CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); -} - -TEST_CASE("./failing/matchers/Equals", "") -{ - CHECK_THAT( testStringForMatching(), Equals( "something else" ) ); -} -TEST_CASE("string", "Equals with NULL") -{ - REQUIRE_THAT("", Equals(NULL)); -} -TEST_CASE("./succeeding/matchers/AllOf", "") -{ - CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ); -} -TEST_CASE("./succeeding/matchers/AnyOf", "") -{ - CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ); - CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ); -} - -TEST_CASE("./succeeding/matchers/Equals", "") -{ - CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); -} - -inline unsigned int Factorial( unsigned int number ) -{ -// return number <= 1 ? number : Factorial(number-1)*number; - return number > 1 ? Factorial(number-1)*number : 1; -} - -TEST_CASE( "Factorials are computed", "[factorial]" ) { - REQUIRE( Factorial(0) == 1 ); - REQUIRE( Factorial(1) == 1 ); - REQUIRE( Factorial(2) == 2 ); - REQUIRE( Factorial(3) == 6 ); - REQUIRE( Factorial(10) == 3628800 ); -} - -TEST_CASE( "empty", "An empty test with no assertions" ) -{ -} - -TEST_CASE( "Nice descriptive name", "[tag1][tag2][tag3][.]" ) -{ - WARN( "This one ran" ); -} -TEST_CASE( "first tag", "[tag1]" ) -{ -} -TEST_CASE( "second tag", "[tag2]" ) -{ -} -// -//TEST_CASE( "spawn a new process", "[.]" ) -//{ -// // !TBD Work in progress -// char line[200]; -// FILE* output = popen("./CatchSelfTest ./failing/matchers/StartsWith", "r"); -// while ( fgets(line, 199, output) ) -// std::cout << line; -//} - -TEST_CASE( "vectors can be sized and resized", "[vector]" ) { - - std::vector v( 5 ); - - REQUIRE( v.size() == 5 ); - REQUIRE( v.capacity() >= 5 ); - - SECTION( "resizing bigger changes size and capacity", "" ) { - v.resize( 10 ); - - REQUIRE( v.size() == 10 ); - REQUIRE( v.capacity() >= 10 ); - } - SECTION( "resizing smaller changes size but not capacity", "" ) { - v.resize( 0 ); - - REQUIRE( v.size() == 0 ); - REQUIRE( v.capacity() >= 5 ); - - SECTION( "We can use the 'swap trick' to reset the capacity", "" ) { - std::vector empty; - empty.swap( v ); - - REQUIRE( v.capacity() == 0 ); + TEST_CASE( "./misc/xmlentitycheck", "" ) + { + SECTION( "embedded xml", "it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) + { + // No test + } + SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) + { + // No test } } - SECTION( "reserving bigger changes capacity but not size", "" ) { - v.reserve( 10 ); - - REQUIRE( v.size() == 5 ); - REQUIRE( v.capacity() >= 10 ); + + TEST_CASE( "./manual/onechar", "send a single char to INFO" ) + { + INFO(3); + REQUIRE(false); } - SECTION( "reserving smaller does not change size or capacity", "" ) { - v.reserve( 0 ); - + + TEST_CASE("./succeeding/atomic if", "") + { + size_t x = 0; + + if( x ) + REQUIRE(x > 0); + else + REQUIRE(x == 0); + } + + inline const char* testStringForMatching() + { + return "this string contains 'abc' as a substring"; + } + + TEST_CASE("./succeeding/matchers", "") + { + REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); + CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); + + CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); + CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ); + } + + TEST_CASE("./failing/matchers/Contains", "") + { + CHECK_THAT( testStringForMatching(), Contains( "not there" ) ); + } + + TEST_CASE("./failing/matchers/StartsWith", "") + { + CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ); + } + + TEST_CASE("./failing/matchers/EndsWith", "") + { + CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); + } + + TEST_CASE("./failing/matchers/Equals", "") + { + CHECK_THAT( testStringForMatching(), Equals( "something else" ) ); + } + TEST_CASE("string", "Equals with NULL") + { + REQUIRE_THAT("", Equals(NULL)); + } + TEST_CASE("./succeeding/matchers/AllOf", "") + { + CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ); + } + TEST_CASE("./succeeding/matchers/AnyOf", "") + { + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ); + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ); + } + + TEST_CASE("./succeeding/matchers/Equals", "") + { + CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); + } + + inline unsigned int Factorial( unsigned int number ) + { + // return number <= 1 ? number : Factorial(number-1)*number; + return number > 1 ? Factorial(number-1)*number : 1; + } + + TEST_CASE( "Factorials are computed", "[factorial]" ) { + REQUIRE( Factorial(0) == 1 ); + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); + } + + TEST_CASE( "empty", "An empty test with no assertions" ) + { + } + + TEST_CASE( "Nice descriptive name", "[tag1][tag2][tag3][.]" ) + { + WARN( "This one ran" ); + } + TEST_CASE( "first tag", "[tag1]" ) + { + } + TEST_CASE( "second tag", "[tag2]" ) + { + } + // + //TEST_CASE( "spawn a new process", "[.]" ) + //{ + // // !TBD Work in progress + // char line[200]; + // FILE* output = popen("./CatchSelfTest ./failing/matchers/StartsWith", "r"); + // while ( fgets(line, 199, output) ) + // std::cout << line; + //} + + TEST_CASE( "vectors can be sized and resized", "[vector]" ) { + + std::vector v( 5 ); + REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 5 ); + + SECTION( "resizing bigger changes size and capacity", "" ) { + v.resize( 10 ); + + REQUIRE( v.size() == 10 ); + REQUIRE( v.capacity() >= 10 ); + } + SECTION( "resizing smaller changes size but not capacity", "" ) { + v.resize( 0 ); + + REQUIRE( v.size() == 0 ); + REQUIRE( v.capacity() >= 5 ); + + SECTION( "We can use the 'swap trick' to reset the capacity", "" ) { + std::vector empty; + empty.swap( v ); + + REQUIRE( v.capacity() == 0 ); + } + } + SECTION( "reserving bigger changes capacity but not size", "" ) { + v.reserve( 10 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 10 ); + } + SECTION( "reserving smaller does not change size or capacity", "" ) { + v.reserve( 0 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 5 ); + } } + + // https://github.com/philsquared/Catch/issues/166 + TEST_CASE("./failing/CatchSectionInfiniteLoop", "") + { + SECTION("Outer", "") + SECTION("Inner", "") + SUCCEED("that's not flying - that's failing in style"); + + FAIL("to infinity and beyond"); + } + + + //#include "internal/catch_timer.h" + // + //TEST_CASE( "Timer", "[work-in-progress]" ) + //{ + // Catch::Timer t; + // t.start(); + // + // std::cout << "starting..." << std::endl; + // + // double d = 0; + // for( int i = 0; i < 100000; ++i ) + // for( int j = 0; j < 1000; ++j ) + // d += (double)i*(double)j; + // + // double duration = t.getElapsedSeconds(); + // + // std::cout << "finished in " << duration << std::endl; + // + // SUCCEED("yay"); + // + //} } - -// https://github.com/philsquared/Catch/issues/166 -TEST_CASE("./failing/CatchSectionInfiniteLoop", "") -{ - SECTION("Outer", "") - SECTION("Inner", "") - SUCCEED("that's not flying - that's failing in style"); - - FAIL("to infinity and beyond"); -} - - -//#include "internal/catch_timer.h" -// -//TEST_CASE( "Timer", "[work-in-progress]" ) -//{ -// Catch::Timer t; -// t.start(); -// -// std::cout << "starting..." << std::endl; -// -// double d = 0; -// for( int i = 0; i < 100000; ++i ) -// for( int j = 0; j < 1000; ++j ) -// d += (double)i*(double)j; -// -// double duration = t.getElapsedSeconds(); -// -// std::cout << "finished in " << duration << std::endl; -// -// SUCCEED("yay"); -// -//} diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 27e1b8fd..6d07d56f 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -24,94 +24,98 @@ namespace Catch } } -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./succeeding/Tricky/std::pair", - "Parsing a std::pair" -) +namespace TrickTests { - std::pair aNicePair( 1, 2 ); - REQUIRE( (std::pair( 1, 2 )) == aNicePair ); -} - -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./inprogress/failing/Tricky/trailing expression", - "Where the is more to the expression after the RHS" -) -{ -// int a = 1, b = 2; -// REQUIRE( a == 2 || b == 2 ); - WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); -} -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./inprogress/failing/Tricky/compound lhs", - "Where the LHS is not a simple value" -) -{ - /* - int a = 1; - int b = 2; - - // This only captures part of the expression, but issues a warning about the rest - REQUIRE( a+1 == b-1 ); - */ - WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); -} - -struct Opaque -{ - int val; - bool operator ==( const Opaque& o ) const + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./succeeding/Tricky/std::pair", + "Parsing a std::pair" + ) { - return val == o.val; + std::pair aNicePair( 1, 2 ); + + REQUIRE( (std::pair( 1, 2 )) == aNicePair ); } -}; -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./failing/Tricky/non streamable type", - "A failing expression with a non streamable type is still captured" -) -{ + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./inprogress/failing/Tricky/trailing expression", + "Where the is more to the expression after the RHS" + ) + { + // int a = 1, b = 2; + // REQUIRE( a == 2 || b == 2 ); + WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); + } + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./inprogress/failing/Tricky/compound lhs", + "Where the LHS is not a simple value" + ) + { + /* + int a = 1; + int b = 2; - Opaque o1, o2; - o1.val = 7; - o2.val = 8; + // This only captures part of the expression, but issues a warning about the rest + REQUIRE( a+1 == b-1 ); + */ + WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); + } + + struct Opaque + { + int val; + bool operator ==( const Opaque& o ) const + { + return val == o.val; + } + }; + + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./failing/Tricky/non streamable type", + "A failing expression with a non streamable type is still captured" + ) + { + + Opaque o1, o2; + o1.val = 7; + o2.val = 8; - CHECK( &o1 == &o2 ); - CHECK( o1 == o2 ); -} + CHECK( &o1 == &o2 ); + CHECK( o1 == o2 ); + } -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./failing/string literals", - "string literals of different sizes can be compared" -) -{ - REQUIRE( std::string( "first" ) == "second" ); + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./failing/string literals", + "string literals of different sizes can be compared" + ) + { + REQUIRE( std::string( "first" ) == "second" ); -} + } -/////////////////////////////////////////////////////////////////////////////// -TEST_CASE -( - "./succeeding/side-effects", - "An expression with side-effects should only be evaluated once" -) -{ - int i = 7; + /////////////////////////////////////////////////////////////////////////////// + TEST_CASE + ( + "./succeeding/side-effects", + "An expression with side-effects should only be evaluated once" + ) + { + int i = 7; - REQUIRE( i++ == 7 ); - REQUIRE( i++ == 8 ); + REQUIRE( i++ == 7 ); + REQUIRE( i++ == 8 ); + } } namespace A { diff --git a/projects/SelfTest/VariadicMacrosTests.cpp b/projects/SelfTest/VariadicMacrosTests.cpp index b784076d..d680432e 100644 --- a/projects/SelfTest/VariadicMacrosTests.cpp +++ b/projects/SelfTest/VariadicMacrosTests.cpp @@ -10,22 +10,25 @@ #ifdef CATCH_CONFIG_VARIADIC_MACROS -TEST_CASE() +namespace VariadicMacroTests { - SUCCEED( "anonymous test case" ); -} + TEST_CASE() + { + SUCCEED( "anonymous test case" ); + } -TEST_CASE( "Test case with one argument" ) -{ - SUCCEED( "no assertions" ); -} - -TEST_CASE( "Variadic macros", "[variadic][sections]" ) -{ - SECTION( "Section with one argument" ) + TEST_CASE( "Test case with one argument" ) { SUCCEED( "no assertions" ); } + + TEST_CASE( "Variadic macros", "[variadic][sections]" ) + { + SECTION( "Section with one argument" ) + { + SUCCEED( "no assertions" ); + } + } } #endif diff --git a/projects/VS2010/ManagedTestCatch/AssemblyInfo.cpp b/projects/VS2010/ManagedTestCatch/AssemblyInfo.cpp new file mode 100644 index 00000000..a4276585 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/AssemblyInfo.cpp @@ -0,0 +1,34 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ManagedTestCatch")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("Instron")]; +[assembly:AssemblyProductAttribute("ManagedTestCatch")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) Instron 2013")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Build and Revision Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; +[assembly:ComVisible(false)]; + diff --git a/projects/VS2010/ManagedTestCatch/Local.testsettings b/projects/VS2010/ManagedTestCatch/Local.testsettings new file mode 100644 index 00000000..a3ce38d6 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/Local.testsettings @@ -0,0 +1,10 @@ + + + These are default test settings for a local test run. + + + + + + + \ No newline at end of file diff --git a/projects/VS2010/ManagedTestCatch/ManagedTestCatch.sln b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.sln new file mode 100644 index 00000000..8d265189 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManagedTestCatch", "ManagedTestCatch.vcxproj", "{7CC06A6B-763E-42B3-AF6C-8F1E340372A1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EAFF2A33-B90A-4957-A39D-F49589A088C8}" + ProjectSection(SolutionItems) = preProject + Local.testsettings = Local.testsettings + ManagedTestCatch.vsmdi = ManagedTestCatch.vsmdi + TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings + EndProjectSection +EndProject +Global + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = ManagedTestCatch.vsmdi + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7CC06A6B-763E-42B3-AF6C-8F1E340372A1}.Debug|Win32.ActiveCfg = Debug|Win32 + {7CC06A6B-763E-42B3-AF6C-8F1E340372A1}.Debug|Win32.Build.0 = Debug|Win32 + {7CC06A6B-763E-42B3-AF6C-8F1E340372A1}.Release|Win32.ActiveCfg = Release|Win32 + {7CC06A6B-763E-42B3-AF6C-8F1E340372A1}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj new file mode 100644 index 00000000..b14d3a5f --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj @@ -0,0 +1,115 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + DefaultTest + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942} + {7CC06A6B-763E-42B3-AF6C-8F1E340372A1} + ManagedCProj + ManagedTestCatch + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + Safe + Unicode + + + + + + + + + + + + if exist app.config copy app.config "$(OutDir)app.config" + true + false + + + + Level4 + Disabled + WIN32;_DEBUG;%(PreprocessorDefinitions) + NotUsing + ..\..\..\include + true + MultiThreadedDebugDLL + + + true + + + + + + + Level3 + WIN32;NDEBUG;%(PreprocessorDefinitions) + NotUsing + true + ../../../include + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj.filters b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj.filters new file mode 100644 index 00000000..0f1c9922 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vcxproj.filters @@ -0,0 +1,85 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vsmdi b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vsmdi new file mode 100644 index 00000000..04402af4 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/ManagedTestCatch.vsmdi @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/projects/VS2010/ManagedTestCatch/TraceAndTestImpact.testsettings b/projects/VS2010/ManagedTestCatch/TraceAndTestImpact.testsettings new file mode 100644 index 00000000..6d465319 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/TraceAndTestImpact.testsettings @@ -0,0 +1,9 @@ + + + These are test settings for Trace and Test Impact. + + + + + + \ No newline at end of file diff --git a/projects/VS2010/ManagedTestCatch/app.ico b/projects/VS2010/ManagedTestCatch/app.ico new file mode 100644 index 0000000000000000000000000000000000000000..3a5525fd794f7a7c5c8e6187f470ea3af38cd2b6 GIT binary patch literal 1078 zcmeHHJr05}7=1t!Hp3A*8IHkVf+j?-!eHY14Gtcw1Eb*_9>Bq^zETJ@GKj{_2j4$w zo9}xCh!8{T3=X##Skq>ikMjsvB|y%crWBM2iW(4pI}c%z6%lW!=~4v77#3{z!dmB1 z__&l)-{KUYR+|8|;wB^R|9ET$J@(@=#rd^=)qs85?vAy(PSF5CyNkus435LVkZ$rj zNw|JG-P7^hF<(;#o*Vk}5R#e|^13tBbQkeF?djULtvqyxd3<{9 literal 0 HcmV?d00001 diff --git a/projects/VS2010/ManagedTestCatch/app.rc b/projects/VS2010/ManagedTestCatch/app.rc new file mode 100644 index 00000000..a30366af --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/app.rc @@ -0,0 +1,52 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 2 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/projects/VS2010/ManagedTestCatch/resource.h b/projects/VS2010/ManagedTestCatch/resource.h new file mode 100644 index 00000000..d5ac7c42 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/projects/VS2010/ManagedTestCatch/stdafx.cpp b/projects/VS2010/ManagedTestCatch/stdafx.cpp new file mode 100644 index 00000000..c7888519 --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// ManagedTestCatch.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/projects/VS2010/ManagedTestCatch/stdafx.h b/projects/VS2010/ManagedTestCatch/stdafx.h new file mode 100644 index 00000000..3cc4c24e --- /dev/null +++ b/projects/VS2010/ManagedTestCatch/stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + + diff --git a/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters new file mode 100644 index 00000000..b358c13d --- /dev/null +++ b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters @@ -0,0 +1,300 @@ + + + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + Sources + + + + + Sources + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + + + + + + {18bce7d6-45c2-4f57-8334-f3e8469d4d41} + + + {fea8fbb4-5032-451a-ba31-e5cb8f32e0de} + + + \ No newline at end of file diff --git a/projects/VS2012/ManagedTestCatch/AssemblyInfo.cpp b/projects/VS2012/ManagedTestCatch/AssemblyInfo.cpp new file mode 100644 index 00000000..04d565a3 --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/AssemblyInfo.cpp @@ -0,0 +1,34 @@ +#include "stdafx.h" + +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute("ManagedTestCatch2012")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("Instron")]; +[assembly:AssemblyProductAttribute("ManagedTestCatch2012")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) Instron 2013")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Build and Revision Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; +[assembly:ComVisible(false)]; + diff --git a/projects/VS2012/ManagedTestCatch/ManagedTestCatch.sln b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.sln new file mode 100644 index 00000000..b41b17a4 --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManagedTestCatch", "ManagedTestCatch.vcxproj", "{9757CB21-B840-49A6-B057-9F322E543DD6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9757CB21-B840-49A6-B057-9F322E543DD6}.Debug|Win32.ActiveCfg = Debug|Win32 + {9757CB21-B840-49A6-B057-9F322E543DD6}.Debug|Win32.Build.0 = Debug|Win32 + {9757CB21-B840-49A6-B057-9F322E543DD6}.Release|Win32.ActiveCfg = Release|Win32 + {9757CB21-B840-49A6-B057-9F322E543DD6}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj new file mode 100644 index 00000000..e5bcc201 --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj @@ -0,0 +1,125 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + DefaultTest + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942} + {9757CB21-B840-49A6-B057-9F322E543DD6} + ManagedCProj + ManagedTestCatch2012 + + + + DynamicLibrary + v110 + Safe + Unicode + + + DynamicLibrary + v110 + Safe + Unicode + + + + + + + + + + + + if exist app.config copy app.config "$(OutDir)app.config" + + + true + + + false + + + + Level3 + Disabled + WIN32;_DEBUG;%(PreprocessorDefinitions) + NotUsing + ../../../include + true + MultiThreadedDebugDLL + + + true + + + + taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1" + + + + + Level3 + WIN32;NDEBUG;%(PreprocessorDefinitions) + NotUsing + ../../../include + true + + + true + + + + + + ..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll + false + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj.filters b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj.filters new file mode 100644 index 00000000..f32e36cb --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/ManagedTestCatch.vcxproj.filters @@ -0,0 +1,85 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/projects/VS2012/ManagedTestCatch/app.ico b/projects/VS2012/ManagedTestCatch/app.ico new file mode 100644 index 0000000000000000000000000000000000000000..301942f6075098f1a121e634050e89a01fa02cb8 GIT binary patch literal 10134 zcmeHL&2GXl40fSINRuW`JNL+AAP#$s9Vgyk$Mp&J96Sb(v(tVq<=A~rYLtXlkQ7wb z*;`^ew&V1}grr0n&1kV$fakQ#h+c@G6ZAQ4?ugzoX7z$LIZ-tuDhliWF(G=sXWja5 z=R{8rq8GHqJfDw5OP&)AZp3+*O4GM>u&}W#Ekh3xt)$&<2SaWCsjgW`e<3<2` z&d~!-L&`jwPP2(a*#LUDo)dcTJmCYkKoGig>c{(RVSHD4XGpREdvo2lVV|#4n&jnJ z{7ytQj?sAg*^L3ezV$O?ywqU|PyXUIftT243e2@alXEZO%-l{T4!N-4oNE|*h*9TW zM4v@+ZtdjuoGX1@i)1-;HxkO|bq|0RJbKz)I9udXAF3O2%J-6X$;?$_adWdQzF?^L6u*YX#k2qb literal 0 HcmV?d00001 diff --git a/projects/VS2012/ManagedTestCatch/app.rc b/projects/VS2012/ManagedTestCatch/app.rc new file mode 100644 index 00000000..a30366af --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/app.rc @@ -0,0 +1,52 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon placed first or with lowest ID value becomes application icon + +LANGUAGE 9, 2 +#pragma code_page(1252) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/projects/VS2012/ManagedTestCatch/resource.h b/projects/VS2012/ManagedTestCatch/resource.h new file mode 100644 index 00000000..d5ac7c42 --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/projects/VS2012/ManagedTestCatch/stdafx.cpp b/projects/VS2012/ManagedTestCatch/stdafx.cpp new file mode 100644 index 00000000..defbf61a --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// ManagedTestCatch2012.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/projects/VS2012/ManagedTestCatch/stdafx.h b/projects/VS2012/ManagedTestCatch/stdafx.h new file mode 100644 index 00000000..3cc4c24e --- /dev/null +++ b/projects/VS2012/ManagedTestCatch/stdafx.h @@ -0,0 +1,7 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + + diff --git a/projects/VS2012/NativeTestCatch/NativeTestCatch.sln b/projects/VS2012/NativeTestCatch/NativeTestCatch.sln new file mode 100644 index 00000000..18ec7dc0 --- /dev/null +++ b/projects/VS2012/NativeTestCatch/NativeTestCatch.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeTestCatch", "NativeTestCatch.vcxproj", "{977CE524-3FC7-4281-9C1B-77C210F24A9B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {977CE524-3FC7-4281-9C1B-77C210F24A9B}.Debug|Win32.ActiveCfg = Debug|Win32 + {977CE524-3FC7-4281-9C1B-77C210F24A9B}.Debug|Win32.Build.0 = Debug|Win32 + {977CE524-3FC7-4281-9C1B-77C210F24A9B}.Release|Win32.ActiveCfg = Release|Win32 + {977CE524-3FC7-4281-9C1B-77C210F24A9B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj b/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj new file mode 100644 index 00000000..87bdb6d4 --- /dev/null +++ b/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj @@ -0,0 +1,111 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {977CE524-3FC7-4281-9C1B-77C210F24A9B} + Win32Proj + NativeTestCatch + + + + DynamicLibrary + true + v110 + Unicode + false + + + DynamicLibrary + false + v110 + true + Unicode + false + + + + + + + + + + + + + true + + + true + + + + NotUsing + Level3 + Disabled + ../../../include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + NotUsing + MaxSpeed + true + true + ../../../include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + \ No newline at end of file diff --git a/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj.filters b/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj.filters new file mode 100644 index 00000000..24538c37 --- /dev/null +++ b/projects/VS2012/NativeTestCatch/NativeTestCatch.vcxproj.filters @@ -0,0 +1,72 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/projects/VS2012/NativeTestCatch/stdafx.cpp b/projects/VS2012/NativeTestCatch/stdafx.cpp new file mode 100644 index 00000000..7734a57c --- /dev/null +++ b/projects/VS2012/NativeTestCatch/stdafx.cpp @@ -0,0 +1,9 @@ +// stdafx.cpp : source file that includes just the standard includes +// NativeTestCatch.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file + diff --git a/projects/VS2012/NativeTestCatch/stdafx.h b/projects/VS2012/NativeTestCatch/stdafx.h new file mode 100644 index 00000000..43280fca --- /dev/null +++ b/projects/VS2012/NativeTestCatch/stdafx.h @@ -0,0 +1,13 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +// Headers for CppUnitTest +#include "CppUnitTest.h" + +// TODO: reference additional headers your program requires here diff --git a/projects/VS2012/NativeTestCatch/targetver.h b/projects/VS2012/NativeTestCatch/targetver.h new file mode 100644 index 00000000..87c0086d --- /dev/null +++ b/projects/VS2012/NativeTestCatch/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include