mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
e07f8bd7b6
Summary: This splits `EDEN_BUG()` into three separate version. All three crash in debug mode builds, but in release builds they behave differently: - `EDEN_BUG()` throws an exception - `EDEN_BUG_FUTURE(Type)` returns a `folly::Future<Type>` that has been fulfilled with an exception. - `EDEN_BUG_EXCEPTION()` returns a `folly::exception_wrapper`. The main advantage of this is that this allows the compiler to detect that `EDEN_BUG()` can never return. Previously `EDEN_BUG()` was used for all 3 of these different cases, and its behavior depended on whether `toException()` was ever called. As a result we could not easily get the compiler to identify code paths where we know at compile time that it will never return. Reviewed By: chadaustin Differential Revision: D18652103 fbshipit-source-id: 070107c7520f51b05696905fa243de5f8df15958
33 lines
783 B
C++
33 lines
783 B
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/utils/Bug.h"
|
|
|
|
#include <folly/ExceptionWrapper.h>
|
|
#include <folly/test/TestUtils.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace facebook::eden;
|
|
|
|
namespace {
|
|
void buggyFunction() {
|
|
EDEN_BUG() << "oh noes";
|
|
}
|
|
} // namespace
|
|
|
|
TEST(EdenBug, throws) {
|
|
EdenBugDisabler noCrash;
|
|
EXPECT_THROW_RE(buggyFunction(), std::runtime_error, "oh noes");
|
|
EXPECT_THROW_RE(EDEN_BUG() << "doh", std::runtime_error, "doh");
|
|
}
|
|
|
|
TEST(EdenBug, toException) {
|
|
EdenBugDisabler noCrash;
|
|
auto ew = EDEN_BUG_EXCEPTION() << "whoops";
|
|
EXPECT_THROW_RE(ew.throw_exception(), std::runtime_error, "whoops");
|
|
}
|