Macros | Functions
plugin_search_path_t.cc File Reference
#include "catch2/catch.hpp"
#include "cetlib/detail/plugin_search_path.h"
#include "cetlib/getenv.h"
#include "cetlib/os_libpath.h"
#include "cetlib/plugin_libpath.h"
#include "cetlib/search_path.h"
#include "cetlib/split_path.h"
#include <cstdlib>
#include <set>
#include <string>

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200112L
 

Functions

 TEST_CASE ("Tests")
 

Macro Definition Documentation

#define _POSIX_C_SOURCE   200112L

Definition at line 3 of file plugin_search_path_t.cc.

Function Documentation

TEST_CASE ( "Tests"  )

Definition at line 57 of file plugin_search_path_t.cc.

58 {
59  // Setup.
60  unsetenv(plugin_libpath());
61  string const default_libpath{cet::getenv(os_libpath(), std::nothrow)};
62  if (default_libpath.empty()) {
63  // Need *something*.
64  setenv(os_libpath(), "/dev/null/libpath", 1);
65  }
66  auto const libpath_before = cet::getenv(os_libpath());
67 
68  ////////////////////////////////////
69  // Tests.
70  ////////////////////////////////////
71 
72  // Test using non-empty plugin_libpath().
73  SECTION("Standard")
74  {
75  setenv(plugin_libpath(), test_path.c_str(), 1);
76  string const expected{remove_dups_from_path(cet::getenv(plugin_libpath()) +
77  ":" + libpath_before)};
79  CHECK(tp_sz == sp.size());
80  auto const libpath = cet::getenv(os_libpath());
81  CHECK(expected == libpath);
82  CHECK(tp_sz < path_entries(libpath));
83  }
84 
85  // Test fallback for null plugin_libpath().
86  SECTION("Standard Null")
87  {
88  auto const sp{
90  auto const libpath = cet::getenv(os_libpath());
91  CHECK(path_entries(libpath) == sp.size());
92  CHECK(remove_dups_from_path(libpath_before) == libpath);
93  }
94 
95  // Test lack of fallback for empty plugin_libpath().
96  SECTION("Standard Empty")
97  {
98  setenv(plugin_libpath(), "", 1);
100  CHECK(1ull == sp.size()); // "."
101  CHECK(remove_dups_from_path(libpath_before) == cet::getenv(os_libpath()));
102  }
103 
104  // Test non-empty arbitrary environment variable.
105  SECTION("Custom")
106  {
107  setenv("SIMPLE_VAR", test_path.c_str(), 1);
108  auto const sp{plugin_search_path(search_path{"SIMPLE_VAR"})};
109  auto const libpath = cet::getenv(os_libpath());
110  CHECK(tp_sz == sp.size());
111  string const expected{cet::getenv("SIMPLE_VAR") + ":" + libpath_before};
112  CHECK(remove_dups_from_path(expected) == libpath);
113  CHECK(tp_sz < path_entries(libpath));
114  }
115 
116  // Test null arbitrary environment variable.
117  SECTION("Custom Null")
118  {
119  auto const sp{plugin_search_path(search_path{"MISSING_VAR", std::nothrow})};
120  CHECK(1ull == sp.size()); // "."
121  CHECK(remove_dups_from_path(libpath_before) == cet::getenv(os_libpath()));
122  }
123 
124  // Test empty arbitrary environment variable.
125  SECTION("Custom Empty")
126  {
127  setenv("EMPTY_VAR", "", 1);
128  auto const sp{plugin_search_path(search_path{"EMPTY_VAR"})};
129  CHECK(1ull == sp.size()); // "."
130  CHECK(remove_dups_from_path(libpath_before) == cet::getenv(os_libpath()));
131  }
132 
133  // Teardown.
134  setenv(os_libpath(), default_libpath.c_str(), 1);
135 }
constexpr char const * os_libpath()
Definition: os_libpath.h:12
const char expected[]
Definition: Exception_t.cc:22
constexpr char const * plugin_libpath()
std::string getenv(std::string const &name)
Definition: getenv.cc:15
search_path plugin_search_path()