diff options
| author | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 05:25:16 +0000 |
|---|---|---|
| committer | Lexi Winter <lexi@hemlock.eden.le-fay.org> | 2025-03-29 05:25:16 +0000 |
| commit | 624e051bb3244cda572c1d932108bc75116ddfb2 (patch) | |
| tree | 5a76d3a6b687126629fc64de228546f8dfee12ec | |
| parent | 054899c9e5aa8e7d0824646831ed236c99eaae63 (diff) | |
| download | libnvxx-624e051bb3244cda572c1d932108bc75116ddfb2.tar.gz libnvxx-624e051bb3244cda572c1d932108bc75116ddfb2.tar.bz2 | |
add tests for exception types
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | libnvxx/tests/Makefile | 2 | ||||
| -rw-r--r-- | libnvxx/tests/nvxx_exception.cc | 74 |
3 files changed, 76 insertions, 1 deletions
@@ -10,5 +10,6 @@ .depend* Kyuafile /libnvxx/tests/nvxx_basic +/libnvxx/tests/nvxx_exception /libnvxx/tests/nvxx_iterator /libnvxx/tests/nvxx_serialize diff --git a/libnvxx/tests/Makefile b/libnvxx/tests/Makefile index 7ccdfb8..3ea8a5a 100644 --- a/libnvxx/tests/Makefile +++ b/libnvxx/tests/Makefile @@ -3,7 +3,7 @@ PREFIX?= /usr/local TESTSDIR?= ${PREFIX}/tests/nvxx -ATF_TESTS_CXX= nvxx_basic nvxx_iterator nvxx_serialize +ATF_TESTS_CXX= nvxx_basic nvxx_exception nvxx_iterator nvxx_serialize CXXSTD= c++23 # Note that we can't use -Werror here because it breaks ATF. CXXFLAGS+= -W -Wall -Wextra diff --git a/libnvxx/tests/nvxx_exception.cc b/libnvxx/tests/nvxx_exception.cc new file mode 100644 index 0000000..2efcc75 --- /dev/null +++ b/libnvxx/tests/nvxx_exception.cc @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: Unlicense OR MIT + * Refer to the file 'LICENSE' in the nvxx distribution for license terms. + */ + +#include <atf-c++.hpp> + +#include "nvxx.h" + +#define TEST_CASE(name) \ + ATF_TEST_CASE_WITHOUT_HEAD(name) \ + ATF_TEST_CASE_BODY(name) + +TEST_CASE(nv_error) +{ + auto do_throw = []{ + throw bsd::nv_error("{} + {} = {}", 1, 1, 2); + }; + + ATF_REQUIRE_THROW_RE(bsd::nv_error, "1 \\+ 1 = 2", do_throw()); +} + +TEST_CASE(nv_error_state) +{ + auto errv = std::make_error_code(std::errc::invalid_argument); + + auto do_throw = [=]{ + throw bsd::nv_error_state(errv); + }; + + ATF_REQUIRE_THROW(bsd::nv_error_state, do_throw()); + + try { + do_throw(); + } catch (bsd::nv_error_state const &exc) { + ATF_REQUIRE_EQ(true, (errv == exc.error)); + } +} + +TEST_CASE(nv_key_not_found) +{ + using namespace std::literals; + auto constexpr key = "test_key"s; + + auto do_throw = [=]{ + throw bsd::nv_key_not_found(key); + }; + + ATF_REQUIRE_THROW_RE(bsd::nv_key_not_found, + "key \"test_key\" not found", + do_throw()); +} + +TEST_CASE(nv_key_exists) +{ + using namespace std::literals; + auto constexpr key = "test_key"s; + + auto do_throw = [=]{ + throw bsd::nv_key_exists(key); + }; + + ATF_REQUIRE_THROW_RE(bsd::nv_key_exists, + "key \"test_key\" already exists", + do_throw()); +} + +ATF_INIT_TEST_CASES(tcs) +{ + ATF_ADD_TEST_CASE(tcs, nv_error); + ATF_ADD_TEST_CASE(tcs, nv_error_state); + ATF_ADD_TEST_CASE(tcs, nv_key_not_found); + ATF_ADD_TEST_CASE(tcs, nv_key_exists); +} |
