1 #ifndef _POSIX_C_SOURCE 3 #define _POSIX_C_SOURCE 200112L 6 #include "catch2/catch.hpp" 9 #include "cetlib_except/exception.h" 10 #include "cetlib_except/exception_category_matcher.h" 11 #include "cetlib_except/exception_message_matcher.h" 17 auto const VAR =
"GETENV_TEST";
23 setenv(VAR,
val.c_str(), 1);
25 SECTION(
"NoThrow") { REQUIRE(
val ==
cet::getenv(VAR, std::nothrow)); }
31 setenv(VAR, val.c_str(), 1);
32 SECTION(
"Throw") { REQUIRE(val ==
cet::getenv(VAR)); }
33 SECTION(
"NoThrow") { REQUIRE(val ==
cet::getenv(VAR, std::nothrow)); }
43 REQUIRE_THROWS_MATCHES(
46 cet::exception_category_matcher(
"getenv") &&
47 cet::exception_message_matcher(Catch::Matchers::Contains(
48 "Can't find an environment variable named \""s + VAR +
"\"\n")));
TEST_CASE("getenv_value")
std::string getenv(std::string const &name)
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.