Skip to content

Commit

Permalink
Added sanity check for separate translation unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalz800 committed Nov 5, 2021
1 parent 7f1c388 commit 9af6e5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 1 addition & 6 deletions test/src/sanity_integer_divide.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "test.h"

namespace
{

zpp::throwing<int> integer_divide(int x, int y)
{
if (y == 0) {
Expand All @@ -21,7 +18,7 @@ zpp::throwing<bool> integer_divide_equals(int x, int y, int z)
co_return false;
}

int test_integer_divide_equals(int x, int y, int z)
static int test_integer_divide_equals(int x, int y, int z)
{
return zpp::try_catch([&]() -> zpp::throwing<int> {
if (co_await integer_divide_equals(x, y, z)) {
Expand All @@ -38,8 +35,6 @@ int test_integer_divide_equals(int x, int y, int z)
});
}

}

TEST(sanity_integer_divide, integer_divide)
{
EXPECT_EQ(test_integer_divide_equals(4, 2, 2), 1);
Expand Down
29 changes: 29 additions & 0 deletions test/src/sanity_integer_divide_separate_tu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "test.h"

zpp::throwing<bool> integer_divide_equals(int x, int y, int z);

static int test_integer_divide_equals(int x, int y, int z)
{
return zpp::try_catch([&]() -> zpp::throwing<int> {
if (co_await integer_divide_equals(x, y, z)) {
co_return 1;
} else {
co_return 2;
}
}, [&](const std::overflow_error &) {
return 3;
}, [&](const std::range_error &) {
return 4;
}, [&]() {
return 5;
});
}

TEST(sanity_integer_divide, integer_divide_separate_tu)
{
EXPECT_EQ(test_integer_divide_equals(4, 2, 2), 1);
EXPECT_EQ(test_integer_divide_equals(4, 2, 1), 2);
EXPECT_EQ(test_integer_divide_equals(4, 0, 2), 3);
EXPECT_EQ(test_integer_divide_equals(4, 3, 2), 4);
}

0 comments on commit 9af6e5b

Please sign in to comment.