search_path_test.cc
Go to the documentation of this file.
1 #include <catch2/catch.hpp>
2 
3 #include "cetlib/search_path.h"
4 #include "cetlib_except/exception.h"
5 #include "cetlib_except/exception_category_matcher.h"
6 
7 #include <string>
8 
9 using cet::search_path;
10 
11 using namespace std::string_literals;
12 
13 TEST_CASE("Autodetect env")
14 {
15  auto const path = "xyzzy"s;
16  search_path const xyzzy{path};
17  CHECK(xyzzy.size() == 1);
18  CHECK(xyzzy.showenv() == path);
19 }
20 
21 TEST_CASE("Autodetect missing env")
22 {
23  auto const path = "/MISSING/"s;
24  CHECK_THROWS_MATCHES(search_path{path},
26  cet::exception_category_matcher("getenv"));
27 }
28 
29 TEST_CASE("Autodetect path")
30 {
31  search_path const xyzzy{":xyzzy"};
32  CHECK(xyzzy.size() == 1);
33  CHECK(xyzzy.showenv().empty());
34 }
35 
36 TEST_CASE("Missing env OK")
37 {
38  auto const path{"/MISSING/"s};
39  search_path const sp{path, std::nothrow};
40  CHECK(sp.size() == 1);
41  CHECK(sp.showenv() == path);
42 }
43 
44 TEST_CASE("Specified path")
45 {
46  search_path const sp{"/onedir", cet::path_tag};
47  CHECK(sp.size() == 1);
48  CHECK(sp.showenv().empty());
49 }
50 
51 TEST_CASE("Path entry count checks")
52 {
53  CHECK(search_path{":xyzzy:"}.size() == 1);
54  CHECK(search_path{"xyzzy:plugh"}.size() == 2);
55  CHECK(search_path{"xyzzy:::plugh"}.size() == 2);
56  CHECK(search_path{"xyzzy:plugh:twisty:grue"}.size() == 4);
57 
58  CHECK(!search_path{""}.empty());
59  CHECK(!search_path{":"}.empty());
60  CHECK(!search_path{"::"}.empty());
61 
62  CHECK(search_path{""}.size() == 1);
63  CHECK(search_path{":"}.size() == 1);
64  CHECK(search_path{"::"}.size() == 1);
65 }
66 
67 TEST_CASE("Null find check")
68 {
69  search_path const sp{":/tmp:"};
70  CHECK_THROWS_MATCHES(sp.find_file(""),
72  cet::exception_category_matcher("search_path"));
73 }
74 
75 TEST_CASE("Path reproduction check")
76 {
77  CHECK(search_path{"a:bb:c.c"}.to_string() == "a:bb:c.c"s);
78 }
std::string to_string() const
Definition: search_path.cc:161
path_tag_t const path_tag
Definition: search_path.cc:60
std::size_t size() const
Definition: search_path.cc:82
TEST_CASE("Autodetect env")
bool empty() const
Definition: search_path.cc:76
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33