Skip to content

Commit

Permalink
test: use EXPECT_THROW in place of try catch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dqhntt committed Nov 19, 2023
1 parent f68e8b1 commit bf7537e
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ TEST(example, example_test) {
}

TEST(ctor, bad_library) {
try {
EXPECT_THROW({
dylib lib("./", "no_such_library");
EXPECT_EQ(true, false);
}
catch (const dylib::load_error &) {
EXPECT_EQ(true, true);
}
}, dylib::load_error);
}

TEST(multiple_handles, basic_test) {
Expand All @@ -36,25 +32,17 @@ TEST(multiple_handles, basic_test) {
}

TEST(get_function, bad_symbol) {
try {
EXPECT_THROW({
dylib lib("./", "dynamic_lib");
lib.get_function<double(double, double)>("unknown");
EXPECT_EQ(true, false);
}
catch (const dylib::symbol_error &) {
EXPECT_EQ(true, true);
}
}, dylib::symbol_error);
}

TEST(get_variable, bad_symbol) {
try {
EXPECT_THROW({
dylib lib("./", "dynamic_lib");
lib.get_variable<double>("unknown");
EXPECT_EQ(true, false);
}
catch (const dylib::symbol_error &) {
EXPECT_EQ(true, true);
}
}, dylib::symbol_error);
}

TEST(get_variable, alter_variables) {
Expand All @@ -74,29 +62,23 @@ TEST(get_variable, alter_variables) {
}

TEST(invalid_argument, null_pointer) {
try {
EXPECT_THROW({
dylib(nullptr);
EXPECT_EQ(true, false);
}
catch (const std::invalid_argument &) {
EXPECT_EQ(true, true);
}
try {
}, std::invalid_argument);

EXPECT_THROW({
dylib(nullptr, "dynamic_lib");
}, std::invalid_argument);

EXPECT_THROW({
dylib lib("./", "dynamic_lib");
lib.get_function<void()>(nullptr);
EXPECT_EQ(true, false);
}
catch (const std::invalid_argument &) {
EXPECT_EQ(true, true);
}
try {
}, std::invalid_argument);

EXPECT_THROW({
dylib lib("./", "dynamic_lib");
lib.get_variable<void *>(nullptr);
EXPECT_EQ(true, false);
}
catch (const std::invalid_argument &) {
EXPECT_EQ(true, true);
}
}, std::invalid_argument);
}

TEST(manual_decorations, basic_test) {
Expand All @@ -106,7 +88,7 @@ TEST(manual_decorations, basic_test) {
}

TEST(std_move, basic_test) {
try {
EXPECT_THROW({
dylib lib("./", "dynamic_lib");
dylib other(std::move(lib));
auto pi = other.get_variable<double>("pi_value");
Expand All @@ -115,11 +97,7 @@ TEST(std_move, basic_test) {
auto ptr = lib.get_variable<void *>("ptr");
EXPECT_EQ(ptr, (void *)1);
other.get_variable<double>("pi_value");
EXPECT_EQ(true, false);
}
catch (const std::logic_error &) {
EXPECT_EQ(true, true);
}
}, std::logic_error);
}

TEST(has_symbol, basic_test) {
Expand Down

0 comments on commit bf7537e

Please sign in to comment.