Mercurial > hg > sv-dependency-builds
comparison win32-mingw/include/kj/test.h @ 149:279b18cc7785
Update Win32 capnp builds to v0.6
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 23 May 2017 09:16:54 +0100 |
parents | 38d1c0e7850b |
children |
comparison
equal
deleted
inserted
replaced
148:b4bfdf10c4b3 | 149:279b18cc7785 |
---|---|
26 #pragma GCC system_header | 26 #pragma GCC system_header |
27 #endif | 27 #endif |
28 | 28 |
29 #include "debug.h" | 29 #include "debug.h" |
30 #include "vector.h" | 30 #include "vector.h" |
31 #include "function.h" | |
31 | 32 |
32 namespace kj { | 33 namespace kj { |
33 | 34 |
34 class TestRunner; | 35 class TestRunner; |
35 | 36 |
72 KJ_LOG(ERROR, ##__VA_ARGS__); | 73 KJ_LOG(ERROR, ##__VA_ARGS__); |
73 #define KJ_EXPECT(cond, ...) \ | 74 #define KJ_EXPECT(cond, ...) \ |
74 if (cond); else KJ_FAIL_EXPECT("failed: expected " #cond, ##__VA_ARGS__) | 75 if (cond); else KJ_FAIL_EXPECT("failed: expected " #cond, ##__VA_ARGS__) |
75 #endif | 76 #endif |
76 | 77 |
77 #define KJ_EXPECT_THROW(type, code) \ | 78 #define KJ_EXPECT_THROW_RECOVERABLE(type, code) \ |
78 do { \ | 79 do { \ |
79 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \ | 80 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \ |
80 KJ_EXPECT(e->getType() == ::kj::Exception::Type::type, \ | 81 KJ_EXPECT(e->getType() == ::kj::Exception::Type::type, \ |
81 "code threw wrong exception type: " #code, e->getType()); \ | 82 "code threw wrong exception type: " #code, e->getType()); \ |
82 } else { \ | 83 } else { \ |
83 KJ_FAIL_EXPECT("code did not throw: " #code); \ | 84 KJ_FAIL_EXPECT("code did not throw: " #code); \ |
84 } \ | 85 } \ |
85 } while (false) | 86 } while (false) |
86 | 87 |
87 #define KJ_EXPECT_THROW_MESSAGE(message, code) \ | 88 #define KJ_EXPECT_THROW_RECOVERABLE_MESSAGE(message, code) \ |
88 do { \ | 89 do { \ |
89 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \ | 90 KJ_IF_MAYBE(e, ::kj::runCatchingExceptions([&]() { code; })) { \ |
90 KJ_EXPECT(::kj::_::hasSubstring(e->getDescription(), message), \ | 91 KJ_EXPECT(::kj::_::hasSubstring(e->getDescription(), message), \ |
91 "exception description didn't contain expected substring", e->getDescription()); \ | 92 "exception description didn't contain expected substring", e->getDescription()); \ |
92 } else { \ | 93 } else { \ |
93 KJ_FAIL_EXPECT("code did not throw: " #code); \ | 94 KJ_FAIL_EXPECT("code did not throw: " #code); \ |
94 } \ | 95 } \ |
95 } while (false) | 96 } while (false) |
97 | |
98 #if KJ_NO_EXCEPTIONS | |
99 #define KJ_EXPECT_THROW(type, code) \ | |
100 do { \ | |
101 KJ_EXPECT(::kj::_::expectFatalThrow(type, nullptr, [&]() { code; })); \ | |
102 } while (false) | |
103 #define KJ_EXPECT_THROW_MESSAGE(message, code) \ | |
104 do { \ | |
105 KJ_EXPECT(::kj::_::expectFatalThrow(nullptr, kj::StringPtr(message), [&]() { code; })); \ | |
106 } while (false) | |
107 #else | |
108 #define KJ_EXPECT_THROW KJ_EXPECT_THROW_RECOVERABLE | |
109 #define KJ_EXPECT_THROW_MESSAGE KJ_EXPECT_THROW_RECOVERABLE_MESSAGE | |
110 #endif | |
96 | 111 |
97 #define KJ_EXPECT_LOG(level, substring) \ | 112 #define KJ_EXPECT_LOG(level, substring) \ |
98 ::kj::_::LogExpectation KJ_UNIQUE_NAME(_kjLogExpectation)(::kj::LogSeverity::level, substring) | 113 ::kj::_::LogExpectation KJ_UNIQUE_NAME(_kjLogExpectation)(::kj::LogSeverity::level, substring) |
99 // Expects that a log message with the given level and substring text will be printed within | 114 // Expects that a log message with the given level and substring text will be printed within |
100 // the current scope. This message will not cause the test to fail, even if it is an error. | 115 // the current scope. This message will not cause the test to fail, even if it is an error. |
102 // ======================================================================================= | 117 // ======================================================================================= |
103 | 118 |
104 namespace _ { // private | 119 namespace _ { // private |
105 | 120 |
106 bool hasSubstring(kj::StringPtr haystack, kj::StringPtr needle); | 121 bool hasSubstring(kj::StringPtr haystack, kj::StringPtr needle); |
122 | |
123 #if KJ_NO_EXCEPTIONS | |
124 bool expectFatalThrow(Maybe<Exception::Type> type, Maybe<StringPtr> message, | |
125 Function<void()> code); | |
126 // Expects that the given code will throw a fatal exception matching the given type and/or message. | |
127 // Since exceptions are disabled, the test will fork() and run in a subprocess. On Windows, where | |
128 // fork() is not available, this always returns true. | |
129 #endif | |
107 | 130 |
108 class LogExpectation: public ExceptionCallback { | 131 class LogExpectation: public ExceptionCallback { |
109 public: | 132 public: |
110 LogExpectation(LogSeverity severity, StringPtr substring); | 133 LogExpectation(LogSeverity severity, StringPtr substring); |
111 ~LogExpectation(); | 134 ~LogExpectation(); |