diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-30 07:51:23 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-30 07:51:23 +0100 |
| commit | 034cd404a129103a8dd7747e6bd00ffd5550da93 (patch) | |
| tree | d27946517d4d9333abd26ac50bbd4a436093e2ce /nihil.posix/test.getenv.cc | |
| parent | 3e7902f7d790a486d3d9cb978df193f07f3a6ad9 (diff) | |
| download | nihil-034cd404a129103a8dd7747e6bd00ffd5550da93.tar.gz nihil-034cd404a129103a8dd7747e6bd00ffd5550da93.tar.bz2 | |
refactoring
Diffstat (limited to 'nihil.posix/test.getenv.cc')
| -rw-r--r-- | nihil.posix/test.getenv.cc | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/nihil.posix/test.getenv.cc b/nihil.posix/test.getenv.cc deleted file mode 100644 index 9e10c16..0000000 --- a/nihil.posix/test.getenv.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This source code is released into the public domain. - */ - -#include <ranges> -#include <string> -#include <system_error> - -#include <unistd.h> - -#include <catch2/catch_test_macros.hpp> - -import nihil.error; -import nihil.posix; - -TEST_CASE("getenv: existing value", "[getenv]") -{ - auto constexpr *name = "NIHIL_TEST_VAR"; - auto constexpr *value = "test is a test"; - - REQUIRE(::setenv(name, value, 1) == 0); - - auto const s = nihil::getenv(name); - REQUIRE(s); - REQUIRE(*s == value); -} - -TEST_CASE("getenv: non-existing value", "[getenv]") -{ - auto constexpr *name = "NIHIL_TEST_VAR"; - - REQUIRE(::unsetenv(name) == 0); - - auto const s = nihil::getenv(name); - REQUIRE(!s); - REQUIRE(s.error() == std::errc::no_such_file_or_directory); -} - -// Force the call to getenv_r() to reallocate. -TEST_CASE("getenv: long value") -{ - auto constexpr *name = "NIHIL_TEST_VAR"; - auto const value = std::string(4096, 'a'); - - REQUIRE(::setenv(name, value.c_str(), 1) == 0); - - auto const s = nihil::getenv(name); - REQUIRE(s); - REQUIRE(*s == value); -} |
