RecoverableErrorTest.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #include <gtest/gtest.h>
  8. #include <exception>
  9. #include <stdexcept>
  10. #include <cxxreact/RecoverableError.h>
  11. using namespace facebook::react;
  12. TEST(RecoverableError, RunRethrowingAsRecoverableRecoverTest) {
  13. try {
  14. RecoverableError::runRethrowingAsRecoverable<std::runtime_error>(
  15. []() { throw std::runtime_error("catch me"); });
  16. FAIL() << "Unthrown exception";
  17. } catch (const RecoverableError &err) {
  18. ASSERT_STREQ(err.what(), "facebook::react::Recoverable: catch me");
  19. } catch (...) {
  20. FAIL() << "Uncaught exception";
  21. }
  22. }
  23. TEST(RecoverableError, RunRethrowingAsRecoverableFallthroughTest) {
  24. try {
  25. RecoverableError::runRethrowingAsRecoverable<std::runtime_error>(
  26. []() { throw std::logic_error("catch me"); });
  27. FAIL() << "Unthrown exception";
  28. } catch (const RecoverableError &err) {
  29. FAIL() << "Recovered exception that should have fallen through";
  30. } catch (const std::exception &err) {
  31. ASSERT_STREQ(err.what(), "catch me");
  32. }
  33. }