From e1c1417c5086d57752fa85a951749c97a7c8555a Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Thu, 27 Aug 2015 21:01:40 +0300 Subject: [PATCH] Update testing.h (win32 related fixes) --- tests/testing.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/testing.h b/tests/testing.h index bfb586b..20178cd 100644 --- a/tests/testing.h +++ b/tests/testing.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Dmitry Marakasov + * Copyright (c) 2011-2015 Dmitry Marakasov * All rights reserved. * * See https://github.com/AMDmi3/testing.h for updates, bug reports, @@ -36,6 +36,10 @@ #include #include +#ifdef _WIN32 +# define TESTING_NO_COLOR +#endif + // // Helper class for literal quoting / extra processing // @@ -120,7 +124,10 @@ private: default: return str; } - return std::string("\033[") + (bright ? "1" : "0") + ";" + std::to_string(30 + color) + "m" + str + "\033[0m"; + + std::ostringstream ss; + ss << "\033[" << (bright ? '1' : '0') << ';' << (30 + color) << 'm' << str << "\033[0m"; + return ss.str(); } // @@ -202,7 +209,7 @@ public: try { func(); - } catch (E& e) { + } catch (E&) { as_expected = true; thrown = true; } catch (std::exception& e) { @@ -312,13 +319,18 @@ public: // wrappers to allow true variable number of arguments #define METHOD_WRAPPER(method, expr, ...) tester_.method(#expr, expr, __VA_ARGS__) -#define METHOD_WRAPPER_LAMBDA(method, expr, ...) tester_.method(#expr, [&](){return expr;}, __VA_ARGS__) #define METHOD_WRAPPER_EXCEPTION(expr, exception, ...) tester_.ExpectException(#expr, [&](){expr;}, #exception, __VA_ARGS__) // checks -#define EXPECT_TRUE(...) do { METHOD_WRAPPER(ExpectTrue, __VA_ARGS__, Tester::DummyArgument()); } while(0) -#define EXPECT_EQUAL(...) do { METHOD_WRAPPER(ExpectEqual, __VA_ARGS__, Tester::DummyArgument()); } while(0) -#define EXPECT_EXCEPTION(...) do { METHOD_WRAPPER_EXCEPTION(__VA_ARGS__, Tester::DummyArgument()); } while(0) +#ifdef _MSC_VER +# define EXPECT_TRUE(expr, ...) do { tester_.ExpectTrue(#expr, expr, __VA_ARGS__, Tester::DummyArgument()); } while(0) +# define EXPECT_EQUAL(expr, ...) do { tester_.ExpectEqual(#expr, expr, __VA_ARGS__, Tester::DummyArgument()); } while(0) +# define EXPECT_EXCEPTION(expr, exception, ...) do { tester_.ExpectException(#expr, [&](){expr;}, #exception, __VA_ARGS__, Tester::DummyArgument()); } while(0) +#else +# define EXPECT_TRUE(...) do { METHOD_WRAPPER(ExpectTrue, __VA_ARGS__, Tester::DummyArgument()); } while(0) +# define EXPECT_EQUAL(...) do { METHOD_WRAPPER(ExpectEqual, __VA_ARGS__, Tester::DummyArgument()); } while(0) +# define EXPECT_EXCEPTION(...) do { METHOD_WRAPPER_EXCEPTION(__VA_ARGS__, Tester::DummyArgument()); } while(0) +#endif // functions #define ENABLE_FLAGS(flags) do { tester_.EnableFlags(flags); } while(0)