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

Fix -fno-exceptions tests.

parent aa1bdc3e
......@@ -42,14 +42,6 @@ namespace capnp {
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) {
kj::EventLoop loop;
kj::WaitScope waitScope(loop);
......@@ -373,7 +365,8 @@ public:
EXPECT_ANY_THROW(context.getParams());
return kj::READY_NOW;
} 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) {
}
}
#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) {
MallocMessageBuilder builder;
auto root = builder.initRoot<DynamicStruct>(Schema::from<TestUnion>());
......
......@@ -138,20 +138,6 @@ TEST(Encoding, DefaultsFromEmptyMessage) {
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) {
MallocMessageBuilder builder;
TestUnion::Builder root = builder.getRoot<TestUnion>();
......
......@@ -138,14 +138,6 @@ TEST(Orphans, Data) {
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) {
MallocMessageBuilder builder1;
MallocMessageBuilder builder2;
......
......@@ -88,14 +88,6 @@ TEST(SchemaLoader, LoadUnnamedUnion) {
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) {
SchemaLoader loader;
......
......@@ -29,11 +29,6 @@ namespace capnp {
namespace _ { // private
namespace {
#if KJ_NO_EXCEPTIONS
#undef EXPECT_ANY_THROW
#define EXPECT_ANY_THROW(code) EXPECT_DEATH(code, ".")
#endif
TEST(Schema, Structs) {
StructSchema schema = Schema::from<TestAllTypes>();
......@@ -46,8 +41,8 @@ TEST(Schema, Structs) {
EXPECT_ANY_THROW(schema.getDependency(typeId<TestDefaults>()));
EXPECT_TRUE(schema.asStruct() == schema);
EXPECT_ANY_THROW(schema.asEnum());
EXPECT_ANY_THROW(schema.asInterface());
EXPECT_NONFATAL_FAILURE(schema.asEnum());
EXPECT_NONFATAL_FAILURE(schema.asInterface());
ASSERT_EQ(schema.getFields().size(), schema.getProto().getStruct().getFields().size());
StructSchema::Field field = schema.getFields()[0];
......@@ -126,8 +121,8 @@ TEST(Schema, Enums) {
EXPECT_ANY_THROW(schema.getDependency(typeId<TestAllTypes>()));
EXPECT_ANY_THROW(schema.getDependency(typeId<TestEnum>()));
EXPECT_ANY_THROW(schema.asStruct());
EXPECT_ANY_THROW(schema.asInterface());
EXPECT_NONFATAL_FAILURE(schema.asStruct());
EXPECT_NONFATAL_FAILURE(schema.asInterface());
EXPECT_TRUE(schema.asEnum() == schema);
ASSERT_EQ(schema.getEnumerants().size(),
......
......@@ -1015,6 +1015,7 @@ kj::Promise<void> TestMoreStuffImpl::neverReturn(NeverReturnContext context) {
// Also attach `cap` to the result struct to make sure that is released.
context.getResults().setCapCopy(context.getParams().getCap());
context.releaseParams();
context.allowCancellation();
return kj::mv(promise);
}
......
......@@ -30,6 +30,20 @@
#include "dynamic.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 {
inline std::ostream& operator<<(std::ostream& os, const Data::Reader& value) {
......
......@@ -614,7 +614,7 @@ TEST(Async, Detach) {
evalLater([&]() { ran1 = true; });
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(ran2);
......
......@@ -330,7 +330,8 @@ private:
getExceptionCallback().logMessage(e.getFile(), e.getLine(), 0, str(
e.getNature(), e.getDurability() == Exception::Durability::TEMPORARY ? " (temporary)" : "",
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) {
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);
#endif
}
} // 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