Commit c717aa6c authored by Kenton Varda's avatar Kenton Varda

Fix exception-catching test to work on platforms that don't provide a stack trace.

parent 147f6208
......@@ -264,7 +264,10 @@ TEST(Debug, Catch) {
KJ_IF_MAYBE(e, exception) {
String what = str(*e);
std::string text(what.cStr(), strchr(what.cStr(), '\n') - what.cStr());
KJ_IF_MAYBE(eol, what.findFirst('\n')) {
what = kj::str(what.slice(0, *eol));
}
std::string text(what.cStr());
EXPECT_EQ(fileLine(__FILE__, line) + ": bug in code: foo", text);
} else {
ADD_FAILURE() << "Expected exception.";
......@@ -280,7 +283,10 @@ TEST(Debug, Catch) {
KJ_IF_MAYBE(e, exception) {
String what = str(*e);
std::string text(what.cStr(), strchr(what.cStr(), '\n') - what.cStr());
KJ_IF_MAYBE(eol, what.findFirst('\n')) {
what = kj::str(what.slice(0, *eol));
}
std::string text(what.cStr());
EXPECT_EQ(fileLine(__FILE__, line) + ": bug in code: foo", text);
} else {
ADD_FAILURE() << "Expected exception.";
......@@ -293,8 +299,13 @@ TEST(Debug, Catch) {
line = __LINE__; KJ_FAIL_ASSERT("foo");
ADD_FAILURE() << "Expected exception.";
} catch (const std::exception& e) {
const char* what = e.what();
std::string text(what, strchr(what, '\n') - what);
kj::StringPtr what = e.what();
std::string text = e.what();
KJ_IF_MAYBE(eol, what.findFirst('\n')) {
text.assign(what.cStr(), *eol);
} else {
text.assign(what.cStr());
}
EXPECT_EQ(fileLine(__FILE__, line) + ": bug in code: foo", text);
}
}
......
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