Skip to content

Commit

Permalink
fixup! Fix compilation with libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamStepan committed Jun 27, 2019
1 parent 8fc5522 commit 964fa58
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions tests/uncaught_exception_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct CustomDestructible
};



template<typename Callable>
auto makeCustomDestuctible(Callable&& callable)
{
Expand All @@ -40,29 +41,24 @@ go_bandit([](){
it("can count caught exceptions", [&](){
UncaughtExceptionCounter counter{};

AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());

try
{
AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());
throw std::exception{};
}
catch(std::exception&)
{
AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());

try
{
AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());
throw std::exception{};
}
catch(std::exception&)
{
AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());
}
}
Expand All @@ -71,26 +67,22 @@ go_bandit([](){
it("can count uncaught exceptions for one active exception", [&](){
UncaughtExceptionCounter counter{};

AssertThat(uncaughtExceptions(), Equals(0));
AssertThat(counter.isNewUncaughtException(), IsFalse());

/*
* We must write our results in these variables since we are already unwinding
* stack and failed assert would mean double exception situation => std::terminate
*/
int uncaught = -1;
bool newUncaught = false;
try
{
auto something = makeCustomDestuctible([&](){
uncaught = uncaughtExceptions();
newUncaught = counter.isNewUncaughtException();
});
throw std::exception{};
}
catch(std::exception&)
{
AssertThat(uncaught, Equals(1));
AssertThat(counter.isNewUncaughtException(), IsFalse());
AssertThat(newUncaught, IsTrue());
}
Expand All @@ -100,23 +92,19 @@ go_bandit([](){
/*
* Inner job doesn't throw
*/
int uncaughtOuter = -1;
int uncaughtInner = -1;
bool newUncaughtOuter = false;
bool newUncaughtInner = true;

try
{
UncaughtExceptionCounter counterOuter{};
auto something = makeCustomDestuctible([&](){
uncaughtOuter = uncaughtExceptions();
newUncaughtOuter = counterOuter.isNewUncaughtException();

try
{
UncaughtExceptionCounter counterInner{};
auto something = makeCustomDestuctible([&](){
uncaughtInner = uncaughtExceptions();
newUncaughtInner = counterInner.isNewUncaughtException();
});
}
Expand All @@ -128,31 +116,25 @@ go_bandit([](){
}
catch(std::exception&)
{
AssertThat(uncaughtOuter, Equals(1));
AssertThat(newUncaughtOuter, IsTrue());
AssertThat(uncaughtInner, Equals(1));
AssertThat(newUncaughtInner, IsFalse());
}

/*
* Inner job does throw
*/
uncaughtOuter = -1;
uncaughtInner = -1;
newUncaughtOuter = false;
newUncaughtInner = false;
try
{
UncaughtExceptionCounter counterOuter{};
auto something = makeCustomDestuctible([&](){
uncaughtOuter = uncaughtExceptions();
newUncaughtOuter = counterOuter.isNewUncaughtException();

try
{
UncaughtExceptionCounter counterInner{};
auto something = makeCustomDestuctible([&](){
uncaughtInner = uncaughtExceptions();
newUncaughtInner = counterInner.isNewUncaughtException();
});
throw std::exception{};
Expand All @@ -165,9 +147,7 @@ go_bandit([](){
}
catch(std::exception&)
{
AssertThat(uncaughtOuter, Equals(1));
AssertThat(newUncaughtOuter, IsTrue());
AssertThat(uncaughtInner, Equals(2));
AssertThat(newUncaughtInner, IsTrue());
}
});
Expand Down

0 comments on commit 964fa58

Please sign in to comment.