LLVM: include/llvm/Testing/Support/SupportHelpers.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
10#define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
11
17#include "gmock/gmock-matchers.h"
18#include "gtest/gtest-printers.h"
19
20#include
21#include
22
23namespace llvm {
26 std::vector<std::shared_ptr> Infos;
27
29};
30
37
40 OS << (Err.Success() ? "succeeded" : "failed");
41 if (!Err.Success()) {
42 const char *Delim = " (";
43 for (const auto &Info : Err.Infos) {
44 OS << Delim;
45 Delim = "; ";
46 Info->log(OS);
47 }
48 OS << ")";
49 }
50}
51
52template
55 *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
56 } else {
58 }
59}
60
62public:
64 : ValueMatcher(ValueMatcher) {}
65
66 template
67 operator ::testing::Matcher<const std::optional &>() const {
68 return ::testing::MakeMatcher(
69 new Impl(::testing::SafeMatcherCast(ValueMatcher)));
70 }
71
72 template <class T, class O = std::optional>
73 class Impl : public ::testing::MatcherInterface<const O &> {
74 public:
75 explicit Impl(const ::testing::Matcher &ValueMatcher)
76 : ValueMatcher(ValueMatcher) {}
77
79 testing::MatchResultListener *L) const override {
80 return Input && ValueMatcher.MatchAndExplain(*Input, L);
81 }
82
83 void DescribeTo(std::ostream *OS) const override {
84 *OS << "has a value that ";
85 ValueMatcher.DescribeTo(OS);
86 }
88 *OS << "does not have a value that ";
89 ValueMatcher.DescribeTo(OS);
90 }
91
92 private:
93 testing::Matcher ValueMatcher;
94 };
95
96private:
97 InnerMatcher ValueMatcher;
98};
99}
100
101
102
103template
108
110
111
112
115
116public:
117
118
119
120
121
123 std::error_code EC;
124 if (Unique) {
126 if (!EC) {
127
128 std::string UnresolvedPath(Path.str());
130 }
131 } else {
132 Path = Name;
134 }
135 if (EC)
136 Path.clear();
137 EXPECT_FALSE(EC) << EC.message();
138 }
139
141 if (!Path.empty()) {
143 }
144 }
145
148
151
152
154
155
156 const char *c_str() { return Path.c_str(); }
157
158
159
167};
168
169
170
171
172
175
176public:
177
179 Path = Link;
181 if (EC)
182 Path.clear();
183 EXPECT_FALSE(EC);
184 }
186 if (!Path.empty()) {
188 }
189 }
190
193
196
197
199};
200
201
202
205
206public:
207
208
209
210
211
212
214 bool Unique = false) {
215 std::error_code EC;
216 int fd;
217 if (Unique) {
219 } else {
220 Path = Name;
221 if (!Suffix.empty()) {
222 Path.append(".");
223 Path.append(Suffix);
224 }
226 }
227 EXPECT_FALSE(EC);
229 OS << Contents;
231 EXPECT_FALSE(OS.error());
232 if (EC || OS.error())
233 Path.clear();
234 }
236 if (!Path.empty()) {
238 }
239 }
240
243
246
247
249};
250
251}
252}
253
254#endif
Analysis containing CSE Info
This file defines the SmallString class.
The Input class is used to parse a yaml document into in-memory structs and vectors.
Tagged union holding either a T or a Error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void DescribeNegationTo(std::ostream *OS) const override
Definition SupportHelpers.h:87
void DescribeTo(std::ostream *OS) const override
Definition SupportHelpers.h:83
Impl(const ::testing::Matcher< T > &ValueMatcher)
Definition SupportHelpers.h:75
bool MatchAndExplain(const O &Input, testing::MatchResultListener *L) const override
Definition SupportHelpers.h:78
Definition SupportHelpers.h:61
ValueIsMatcher(InnerMatcher ValueMatcher)
Definition SupportHelpers.h:63
A raw_ostream that writes to a file descriptor.
std::error_code error() const
raw_os_ostream - A raw_ostream that writes to an std::ostream.
const char * c_str()
The null-terminated C string pointing to the path.
Definition SupportHelpers.h:156
StringRef path() const
The path to the temporary directory.
Definition SupportHelpers.h:153
TempDir(StringRef Name, bool Unique=false)
Creates a managed temporary directory.
Definition SupportHelpers.h:122
TempDir & operator=(TempDir &&)=default
TempDir & operator=(const TempDir &)=delete
SmallString< 128 > path(StringRef component) const
Creates a new path by appending the argument to the path of the managed directory using the native pa...
Definition SupportHelpers.h:160
TempDir(TempDir &&)=default
TempDir(const TempDir &)=delete
~TempDir()
Definition SupportHelpers.h:140
StringRef path() const
The path to the file.
Definition SupportHelpers.h:248
TempFile(StringRef Name, StringRef Suffix="", StringRef Contents="", bool Unique=false)
Creates a managed file.
Definition SupportHelpers.h:213
TempFile(const TempFile &)=delete
TempFile(TempFile &&)=default
TempFile & operator=(TempFile &&)=default
~TempFile()
Definition SupportHelpers.h:235
TempFile & operator=(const TempFile &)=delete
StringRef path() const
The path to the link.
Definition SupportHelpers.h:198
TempLink & operator=(TempLink &&)=default
TempLink & operator=(const TempLink &)=delete
~TempLink()
Definition SupportHelpers.h:185
TempLink(TempLink &&)=default
TempLink(const TempLink &)=delete
TempLink(StringRef Target, StringRef Link)
Creates a managed link at path Link pointing to Target.
Definition SupportHelpers.h:178
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
void PrintTo(const ErrorHolder &Err, std::ostream *Out)
Definition SupportHelpers.h:38
LLVM_ABI std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
LLVM_ABI std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
LLVM_ABI std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
LLVM_ABI std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition SupportHelpers.h:107
SmallString< 128 > getInputFileDirectory(const char *Argv0)
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
detail::ValueIsMatcher< InnerMatcher > ValueIs(const InnerMatcher &ValueMatcher)
Matches an std::optional with a value that conforms to an inner matcher.
Definition SupportHelpers.h:104
Implement std::hash so that hash_code can be used in STL containers.
Definition SupportHelpers.h:25
std::vector< std::shared_ptr< ErrorInfoBase > > Infos
Definition SupportHelpers.h:26
bool Success() const
Definition SupportHelpers.h:28
Definition SupportHelpers.h:31
Expected< T > & Exp
Definition SupportHelpers.h:35
ExpectedHolder(ErrorHolder Err, Expected< T > &Exp)
Definition SupportHelpers.h:32