2016-12-17 12:46:50 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <cxxreact/RecoverableError.h>
|
|
|
|
|
2017-05-24 14:27:06 +00:00
|
|
|
using namespace facebook::react;
|
2016-12-17 12:46:50 +00:00
|
|
|
|
|
|
|
TEST(RecoverableError, RunRethrowingAsRecoverableRecoverTest) {
|
|
|
|
try {
|
|
|
|
RecoverableError::runRethrowingAsRecoverable<std::runtime_error>([]() {
|
|
|
|
throw std::runtime_error("catch me");
|
|
|
|
});
|
|
|
|
FAIL() << "Unthrown exception";
|
|
|
|
} catch (const RecoverableError &err) {
|
2017-01-10 15:04:53 +00:00
|
|
|
ASSERT_STREQ(err.what(), "facebook::react::Recoverable: catch me");
|
2016-12-17 12:46:50 +00:00
|
|
|
} catch (...) {
|
|
|
|
FAIL() << "Uncaught exception";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RecoverableError, RunRethrowingAsRecoverableFallthroughTest) {
|
|
|
|
try {
|
|
|
|
RecoverableError::runRethrowingAsRecoverable<std::runtime_error>([]() {
|
|
|
|
throw std::logic_error("catch me");
|
|
|
|
});
|
|
|
|
FAIL() << "Unthrown exception";
|
|
|
|
} catch (const RecoverableError &err) {
|
|
|
|
FAIL() << "Recovered exception that should have fallen through";
|
|
|
|
} catch (const std::exception &err) {
|
|
|
|
ASSERT_STREQ(err.what(), "catch me");
|
|
|
|
}
|
|
|
|
}
|