Macros | Functions
getenv_test.cc File Reference
#include "catch2/catch.hpp"
#include "cetlib/getenv.h"
#include "cetlib_except/exception.h"
#include "cetlib_except/exception_category_matcher.h"
#include "cetlib_except/exception_message_matcher.h"
#include <cstdlib>
#include <string>

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200112L
 

Functions

 TEST_CASE ("getenv_value")
 
 TEST_CASE ("getenv_empty")
 
 TEST_CASE ("getenv_unset")
 

Macro Definition Documentation

#define _POSIX_C_SOURCE   200112L

Definition at line 3 of file getenv_test.cc.

Function Documentation

TEST_CASE ( "getenv_value"  )

Definition at line 20 of file getenv_test.cc.

21 {
22  std::string const val{"TEST"};
23  setenv(VAR, val.c_str(), 1);
24  SECTION("Throw") { REQUIRE(val == cet::getenv(VAR)); }
25  SECTION("NoThrow") { REQUIRE(val == cet::getenv(VAR, std::nothrow)); }
26 }
std::string string
Definition: nybbler.cc:12
std::string getenv(std::string const &name)
Definition: getenv.cc:15
TEST_CASE ( "getenv_empty"  )

Definition at line 28 of file getenv_test.cc.

29 {
30  std::string const val; // Empty
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)); }
34 }
std::string string
Definition: nybbler.cc:12
std::string getenv(std::string const &name)
Definition: getenv.cc:15
TEST_CASE ( "getenv_unset"  )

Definition at line 36 of file getenv_test.cc.

37 {
38  unsetenv(VAR);
39 
40  SECTION("Throw")
41  {
42  using namespace std::string_literals;
43  REQUIRE_THROWS_MATCHES(
44  cet::getenv(VAR),
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")));
49  }
50 
51  SECTION("No Throw") { CHECK(cet::getenv(VAR, std::nothrow).empty()); }
52 }
std::string getenv(std::string const &name)
Definition: getenv.cc:15
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97