Commit 2d67f0b8 authored by Kenton Varda's avatar Kenton Varda

Fix -fno-exceptions tests.

parent aa1bdc3e
...@@ -42,14 +42,6 @@ namespace capnp { ...@@ -42,14 +42,6 @@ namespace capnp {
namespace _ { namespace _ {
namespace { namespace {
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#define EXPECT_NONFATAL_FAILURE(code) code
#else
#define EXPECT_NONFATAL_FAILURE EXPECT_ANY_THROW
#endif
TEST(Capability, Basic) { TEST(Capability, Basic) {
kj::EventLoop loop; kj::EventLoop loop;
kj::WaitScope waitScope(loop); kj::WaitScope waitScope(loop);
...@@ -373,7 +365,8 @@ public: ...@@ -373,7 +365,8 @@ public:
EXPECT_ANY_THROW(context.getParams()); EXPECT_ANY_THROW(context.getParams());
return kj::READY_NOW; return kj::READY_NOW;
} else { } else {
KJ_FAIL_ASSERT("Method not implemented", methodName); KJ_FAIL_ASSERT("Method not implemented", methodName) { break; }
return kj::READY_NOW;
} }
} }
}; };
......
...@@ -313,14 +313,6 @@ TEST(DynamicApi, UnionsRead) { ...@@ -313,14 +313,6 @@ TEST(DynamicApi, UnionsRead) {
} }
} }
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#define EXPECT_NONFATAL_FAILURE(code) code
#else
#define EXPECT_NONFATAL_FAILURE EXPECT_ANY_THROW
#endif
TEST(DynamicApi, UnionsWrite) { TEST(DynamicApi, UnionsWrite) {
MallocMessageBuilder builder; MallocMessageBuilder builder;
auto root = builder.initRoot<DynamicStruct>(Schema::from<TestUnion>()); auto root = builder.initRoot<DynamicStruct>(Schema::from<TestUnion>());
......
...@@ -138,20 +138,6 @@ TEST(Encoding, DefaultsFromEmptyMessage) { ...@@ -138,20 +138,6 @@ TEST(Encoding, DefaultsFromEmptyMessage) {
checkTestMessage(readMessageUnchecked<TestDefaults>(emptyMessage.words)); checkTestMessage(readMessageUnchecked<TestDefaults>(emptyMessage.words));
} }
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#define EXPECT_NONFATAL_FAILURE(code) code
#else
#define EXPECT_NONFATAL_FAILURE EXPECT_ANY_THROW
#endif
#ifdef KJ_DEBUG
#define EXPECT_DEBUG_ANY_THROW EXPECT_ANY_THROW
#else
#define EXPECT_DEBUG_ANY_THROW(EXP)
#endif
TEST(Encoding, Unions) { TEST(Encoding, Unions) {
MallocMessageBuilder builder; MallocMessageBuilder builder;
TestUnion::Builder root = builder.getRoot<TestUnion>(); TestUnion::Builder root = builder.getRoot<TestUnion>();
......
...@@ -138,14 +138,6 @@ TEST(Orphans, Data) { ...@@ -138,14 +138,6 @@ TEST(Orphans, Data) {
EXPECT_EQ(data("foo"), root.getDataField()); EXPECT_EQ(data("foo"), root.getDataField());
} }
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#define EXPECT_NONFATAL_FAILURE(code) code
#else
#define EXPECT_NONFATAL_FAILURE EXPECT_ANY_THROW
#endif
TEST(Orphans, NoCrossMessageTransfers) { TEST(Orphans, NoCrossMessageTransfers) {
MallocMessageBuilder builder1; MallocMessageBuilder builder1;
MallocMessageBuilder builder2; MallocMessageBuilder builder2;
......
...@@ -88,14 +88,6 @@ TEST(SchemaLoader, LoadUnnamedUnion) { ...@@ -88,14 +88,6 @@ TEST(SchemaLoader, LoadUnnamedUnion) {
EXPECT_TRUE(schema.findFieldByName("after") != nullptr); EXPECT_TRUE(schema.findFieldByName("after") != nullptr);
} }
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#define EXPECT_NONFATAL_FAILURE(code) code
#else
#define EXPECT_NONFATAL_FAILURE EXPECT_ANY_THROW
#endif
TEST(SchemaLoader, Use) { TEST(SchemaLoader, Use) {
SchemaLoader loader; SchemaLoader loader;
......
...@@ -29,11 +29,6 @@ namespace capnp { ...@@ -29,11 +29,6 @@ namespace capnp {
namespace _ { // private namespace _ { // private
namespace { namespace {
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#endif
TEST(Schema, Structs) { TEST(Schema, Structs) {
StructSchema schema = Schema::from<TestAllTypes>(); StructSchema schema = Schema::from<TestAllTypes>();
...@@ -46,8 +41,8 @@ TEST(Schema, Structs) { ...@@ -46,8 +41,8 @@ TEST(Schema, Structs) {
EXPECT_ANY_THROW(schema.getDependency(typeId<TestDefaults>())); EXPECT_ANY_THROW(schema.getDependency(typeId<TestDefaults>()));
EXPECT_TRUE(schema.asStruct() == schema); EXPECT_TRUE(schema.asStruct() == schema);
EXPECT_ANY_THROW(schema.asEnum()); EXPECT_NONFATAL_FAILURE(schema.asEnum());
EXPECT_ANY_THROW(schema.asInterface()); EXPECT_NONFATAL_FAILURE(schema.asInterface());
ASSERT_EQ(schema.getFields().size(), schema.getProto().getStruct().getFields().size()); ASSERT_EQ(schema.getFields().size(), schema.getProto().getStruct().getFields().size());
StructSchema::Field field = schema.getFields()[0]; StructSchema::Field field = schema.getFields()[0];
...@@ -126,8 +121,8 @@ TEST(Schema, Enums) { ...@@ -126,8 +121,8 @@ TEST(Schema, Enums) {
EXPECT_ANY_THROW(schema.getDependency(typeId<TestAllTypes>())); EXPECT_ANY_THROW(schema.getDependency(typeId<TestAllTypes>()));
EXPECT_ANY_THROW(schema.getDependency(typeId<TestEnum>())); EXPECT_ANY_THROW(schema.getDependency(typeId<TestEnum>()));
EXPECT_ANY_THROW(schema.asStruct()); EXPECT_NONFATAL_FAILURE(schema.asStruct());
EXPECT_ANY_THROW(schema.asInterface()); EXPECT_NONFATAL_FAILURE(schema.asInterface());
EXPECT_TRUE(schema.asEnum() == schema); EXPECT_TRUE(schema.asEnum() == schema);
ASSERT_EQ(schema.getEnumerants().size(), ASSERT_EQ(schema.getEnumerants().size(),
......
...@@ -1015,6 +1015,7 @@ kj::Promise<void> TestMoreStuffImpl::neverReturn(NeverReturnContext context) { ...@@ -1015,6 +1015,7 @@ kj::Promise<void> TestMoreStuffImpl::neverReturn(NeverReturnContext context) {
// Also attach `cap` to the result struct to make sure that is released. // Also attach `cap` to the result struct to make sure that is released.
context.getResults().setCapCopy(context.getParams().getCap()); context.getResults().setCapCopy(context.getParams().getCap());
context.releaseParams();
context.allowCancellation(); context.allowCancellation();
return kj::mv(promise); return kj::mv(promise);
} }
......
...@@ -30,6 +30,20 @@ ...@@ -30,6 +30,20 @@
#include "dynamic.h" #include "dynamic.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#endif
#define EXPECT_NONFATAL_FAILURE(code) \
EXPECT_TRUE(kj::runCatchingExceptions([&]() { code; }) != nullptr);
#ifdef KJ_DEBUG
#define EXPECT_DEBUG_ANY_THROW EXPECT_ANY_THROW
#else
#define EXPECT_DEBUG_ANY_THROW(EXP)
#endif
namespace capnp { namespace capnp {
inline std::ostream& operator<<(std::ostream& os, const Data::Reader& value) { inline std::ostream& operator<<(std::ostream& os, const Data::Reader& value) {
......
...@@ -614,7 +614,7 @@ TEST(Async, Detach) { ...@@ -614,7 +614,7 @@ TEST(Async, Detach) {
evalLater([&]() { ran1 = true; }); evalLater([&]() { ran1 = true; });
evalLater([&]() { ran2 = true; }).detach([](kj::Exception&&) { ADD_FAILURE(); }); evalLater([&]() { ran2 = true; }).detach([](kj::Exception&&) { ADD_FAILURE(); });
evalLater([]() { KJ_FAIL_ASSERT("foo"); }).detach([&](kj::Exception&& e) { ran3 = true; }); evalLater([]() { KJ_FAIL_ASSERT("foo"){break;} }).detach([&](kj::Exception&& e) { ran3 = true; });
EXPECT_FALSE(ran1); EXPECT_FALSE(ran1);
EXPECT_FALSE(ran2); EXPECT_FALSE(ran2);
......
...@@ -330,7 +330,8 @@ private: ...@@ -330,7 +330,8 @@ private:
getExceptionCallback().logMessage(e.getFile(), e.getLine(), 0, str( getExceptionCallback().logMessage(e.getFile(), e.getLine(), 0, str(
e.getNature(), e.getDurability() == Exception::Durability::TEMPORARY ? " (temporary)" : "", e.getNature(), e.getDurability() == Exception::Durability::TEMPORARY ? " (temporary)" : "",
e.getDescription() == nullptr ? "" : ": ", e.getDescription(), e.getDescription() == nullptr ? "" : ": ", e.getDescription(),
"\nstack: ", strArray(e.getStackTrace(), " "), "\n")); e.getStackTrace().size() > 0 ? "\nstack: " : "", strArray(e.getStackTrace(), " "),
getStackSymbols(e.getStackTrace()), "\n"));
} }
}; };
......
...@@ -157,7 +157,13 @@ TEST(Mutex, LazyException) { ...@@ -157,7 +157,13 @@ TEST(Mutex, LazyException) {
return space.construct(456); return space.construct(456);
}); });
// Unfortunately, the results differ depending on whether exceptions are enabled.
// TODO(someday): Fix this? Does it matter?
#if KJ_NO_EXCEPTIONS
EXPECT_EQ(123, i);
#else
EXPECT_EQ(456, i); EXPECT_EQ(456, i);
#endif
} }
} // namespace } // namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment