forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobTest.h
136 lines (111 loc) · 3.68 KB
/
GlobTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <cxxtest/TestSuite.h>
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/Glob.h"
#include <Poco/File.h>
#include <Poco/Path.h>
using namespace Mantid::Kernel;
class GlobTest : public CxxTest::TestSuite {
Poco::Path base;
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static GlobTest *createSuite() { return new GlobTest(); }
static void destroySuite(GlobTest *suite) { delete suite; }
GlobTest() {
base.assign(ConfigService::Instance().getInstrumentDirectory());
base.makeParent();
base.assign(base.toString());
}
void test_Glob() {
std::string pattern = base.toString() + "Framework/*/CMakeLists.*t";
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT(files.size() > 0);
size_t matches = 0;
for (const auto &file : files) {
Poco::Path path = file;
std::string project = path[path.depth() - 1];
if (project == "API")
++matches;
if (project == "Algorithms")
++matches;
if (project == "Kernel")
++matches;
if (project == "Geometry")
++matches;
if (project == "DataObjects")
++matches;
TS_ASSERT_EQUALS(path.getFileName(), "CMakeLists.txt");
}
TS_ASSERT_EQUALS(matches, 5);
}
void test_no_match() {
std::string pattern = base.toString() + "Doesnotexist/*/CMakeLists.*t";
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT(files.empty());
}
void test_no_match_1() {
std::string pattern = "Doesnotexist/*/File.*";
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT(files.empty());
}
void test_match_relative_path() {
Poco::File testDir("GlobTestDir");
testDir.createDirectory();
Poco::File file1("GlobTestDir/File.1");
file1.createFile();
Poco::File file2("GlobTestDir/File.2");
file2.createFile();
std::string pattern = "GlobTestDir/File.*";
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT_EQUALS(files.size(), 2);
file1.remove();
file2.remove();
testDir.remove();
}
void test_double_dots_in_pattern() {
std::string pattern = base.toString() + "Framework/*/CMakeLists.*t";
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT(files.size() > 0);
size_t matches = 0;
for (const auto &file : files) {
Poco::Path path = file;
std::string project = path[path.depth() - 1];
if (project == "API")
++matches;
if (project == "Algorithms")
++matches;
if (project == "Kernel")
++matches;
if (project == "Geometry")
++matches;
if (project == "DataObjects")
++matches;
TS_ASSERT_EQUALS(path.getFileName(), "CMakeLists.txt");
}
TS_ASSERT_EQUALS(matches, 5);
}
void test_filename_contains_directory() {
Poco::Path pattern(base.toString() + "instrument", "unit_testing/DUM_Definition.xml");
std::set<std::string> files;
Glob::glob(pattern, files);
TS_ASSERT(!files.empty());
}
void test_caseless() {
Poco::Path pattern(base.toString() + "instrument", "unit_TESTING/dum_Definition.xml");
std::set<std::string> files;
Glob::glob(pattern, files, Poco::Glob::GLOB_CASELESS);
TS_ASSERT(!files.empty());
}
};