Michael J. Spencer | 3ef91c5 | 2010-11-29 22:29:04 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/Path.cpp - Path tests ------------------------===// |
Michael J. Spencer | 9884778 | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Rafael Espindola | 3bc8e71 | 2013-06-11 22:21:28 +0000 | [diff] [blame] | 10 | #include "llvm/Support/Path.h" |
Pawel Bylica | 7187e4b | 2015-10-16 09:08:59 +0000 | [diff] [blame] | 11 | #include "llvm/Support/ConvertUTF.h" |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Errc.h" |
Michael J. Spencer | 7ecd94c | 2010-12-06 04:28:42 +0000 | [diff] [blame] | 13 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | 130cec2 | 2012-12-04 10:23:08 +0000 | [diff] [blame] | 14 | #include "llvm/Support/FileSystem.h" |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 15 | #include "llvm/Support/MemoryBuffer.h" |
Michael J. Spencer | 1f06360 | 2011-01-06 05:57:54 +0000 | [diff] [blame] | 16 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 9884778 | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 17 | #include "gtest/gtest.h" |
| 18 | |
Rafael Espindola | a813d60 | 2014-06-11 03:58:34 +0000 | [diff] [blame] | 19 | #ifdef LLVM_ON_WIN32 |
NAKAMURA Takumi | b94f052 | 2015-06-16 06:46:16 +0000 | [diff] [blame] | 20 | #include <windows.h> |
Rafael Espindola | a813d60 | 2014-06-11 03:58:34 +0000 | [diff] [blame] | 21 | #include <winerror.h> |
| 22 | #endif |
| 23 | |
Frederic Riss | 6b9396c | 2015-08-06 21:04:55 +0000 | [diff] [blame] | 24 | #ifdef LLVM_ON_UNIX |
| 25 | #include <sys/stat.h> |
| 26 | #endif |
| 27 | |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 28 | using namespace llvm; |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 29 | using namespace llvm::sys; |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 30 | |
Rafael Espindola | c049c65 | 2014-06-13 03:20:08 +0000 | [diff] [blame] | 31 | #define ASSERT_NO_ERROR(x) \ |
| 32 | if (std::error_code ASSERT_NO_ERROR_ec = x) { \ |
| 33 | SmallString<128> MessageStorage; \ |
| 34 | raw_svector_ostream Message(MessageStorage); \ |
| 35 | Message << #x ": did not return errc::success.\n" \ |
| 36 | << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ |
| 37 | << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ |
| 38 | GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ |
| 39 | } else { \ |
| 40 | } |
Michael J. Spencer | 3b264ba | 2011-01-04 17:00:18 +0000 | [diff] [blame] | 41 | |
Michael J. Spencer | 9884778 | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 42 | namespace { |
| 43 | |
Zhanyong Wan | 606bb1a | 2011-02-11 21:24:40 +0000 | [diff] [blame] | 44 | TEST(is_separator, Works) { |
| 45 | EXPECT_TRUE(path::is_separator('/')); |
| 46 | EXPECT_FALSE(path::is_separator('\0')); |
| 47 | EXPECT_FALSE(path::is_separator('-')); |
| 48 | EXPECT_FALSE(path::is_separator(' ')); |
| 49 | |
| 50 | #ifdef LLVM_ON_WIN32 |
| 51 | EXPECT_TRUE(path::is_separator('\\')); |
| 52 | #else |
| 53 | EXPECT_FALSE(path::is_separator('\\')); |
| 54 | #endif |
| 55 | } |
| 56 | |
Michael J. Spencer | 3ef91c5 | 2010-11-29 22:29:04 +0000 | [diff] [blame] | 57 | TEST(Support, Path) { |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 58 | SmallVector<StringRef, 40> paths; |
| 59 | paths.push_back(""); |
| 60 | paths.push_back("."); |
| 61 | paths.push_back(".."); |
| 62 | paths.push_back("foo"); |
| 63 | paths.push_back("/"); |
| 64 | paths.push_back("/foo"); |
| 65 | paths.push_back("foo/"); |
| 66 | paths.push_back("/foo/"); |
| 67 | paths.push_back("foo/bar"); |
| 68 | paths.push_back("/foo/bar"); |
| 69 | paths.push_back("//net"); |
| 70 | paths.push_back("//net/foo"); |
| 71 | paths.push_back("///foo///"); |
| 72 | paths.push_back("///foo///bar"); |
| 73 | paths.push_back("/."); |
| 74 | paths.push_back("./"); |
| 75 | paths.push_back("/.."); |
| 76 | paths.push_back("../"); |
| 77 | paths.push_back("foo/."); |
| 78 | paths.push_back("foo/.."); |
| 79 | paths.push_back("foo/./"); |
| 80 | paths.push_back("foo/./bar"); |
| 81 | paths.push_back("foo/.."); |
| 82 | paths.push_back("foo/../"); |
| 83 | paths.push_back("foo/../bar"); |
| 84 | paths.push_back("c:"); |
| 85 | paths.push_back("c:/"); |
| 86 | paths.push_back("c:foo"); |
| 87 | paths.push_back("c:/foo"); |
| 88 | paths.push_back("c:foo/"); |
| 89 | paths.push_back("c:/foo/"); |
| 90 | paths.push_back("c:/foo/bar"); |
| 91 | paths.push_back("prn:"); |
| 92 | paths.push_back("c:\\"); |
| 93 | paths.push_back("c:foo"); |
| 94 | paths.push_back("c:\\foo"); |
| 95 | paths.push_back("c:foo\\"); |
| 96 | paths.push_back("c:\\foo\\"); |
| 97 | paths.push_back("c:\\foo/"); |
| 98 | paths.push_back("c:/foo\\bar"); |
| 99 | |
Justin Bogner | 0c274ae | 2014-07-16 08:18:58 +0000 | [diff] [blame] | 100 | SmallVector<StringRef, 5> ComponentStack; |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 101 | for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(), |
| 102 | e = paths.end(); |
| 103 | i != e; |
| 104 | ++i) { |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 105 | for (sys::path::const_iterator ci = sys::path::begin(*i), |
| 106 | ce = sys::path::end(*i); |
| 107 | ci != ce; |
| 108 | ++ci) { |
Michael J. Spencer | b5ca644 | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 109 | ASSERT_FALSE(ci->empty()); |
Justin Bogner | 0c274ae | 2014-07-16 08:18:58 +0000 | [diff] [blame] | 110 | ComponentStack.push_back(*ci); |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 111 | } |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 112 | |
Michael J. Spencer | 545cbdf | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 113 | for (sys::path::reverse_iterator ci = sys::path::rbegin(*i), |
| 114 | ce = sys::path::rend(*i); |
| 115 | ci != ce; |
| 116 | ++ci) { |
Justin Bogner | 0c274ae | 2014-07-16 08:18:58 +0000 | [diff] [blame] | 117 | ASSERT_TRUE(*ci == ComponentStack.back()); |
| 118 | ComponentStack.pop_back(); |
Michael J. Spencer | 545cbdf | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 119 | } |
Justin Bogner | 0c274ae | 2014-07-16 08:18:58 +0000 | [diff] [blame] | 120 | ASSERT_TRUE(ComponentStack.empty()); |
Michael J. Spencer | 545cbdf | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 121 | |
Michael J. Spencer | f616b21 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 122 | path::has_root_path(*i); |
| 123 | path::root_path(*i); |
| 124 | path::has_root_name(*i); |
| 125 | path::root_name(*i); |
| 126 | path::has_root_directory(*i); |
| 127 | path::root_directory(*i); |
| 128 | path::has_parent_path(*i); |
| 129 | path::parent_path(*i); |
| 130 | path::has_filename(*i); |
| 131 | path::filename(*i); |
| 132 | path::has_stem(*i); |
| 133 | path::stem(*i); |
| 134 | path::has_extension(*i); |
| 135 | path::extension(*i); |
| 136 | path::is_absolute(*i); |
| 137 | path::is_relative(*i); |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 138 | |
Michael J. Spencer | 3b264ba | 2011-01-04 17:00:18 +0000 | [diff] [blame] | 139 | SmallString<128> temp_store; |
Michael J. Spencer | b5ca644 | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 140 | temp_store = *i; |
Michael J. Spencer | 3b264ba | 2011-01-04 17:00:18 +0000 | [diff] [blame] | 141 | ASSERT_NO_ERROR(fs::make_absolute(temp_store)); |
Michael J. Spencer | b5ca644 | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 142 | temp_store = *i; |
Michael J. Spencer | 1e090f0 | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 143 | path::remove_filename(temp_store); |
Michael J. Spencer | 4d0c6fd | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 144 | |
Michael J. Spencer | b5ca644 | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 145 | temp_store = *i; |
Michael J. Spencer | 1e090f0 | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 146 | path::replace_extension(temp_store, "ext"); |
Michael J. Spencer | 4d0c6fd | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 147 | StringRef filename(temp_store.begin(), temp_store.size()), stem, ext; |
Michael J. Spencer | f616b21 | 2010-12-07 17:04:04 +0000 | [diff] [blame] | 148 | stem = path::stem(filename); |
| 149 | ext = path::extension(filename); |
Justin Bogner | 487e764 | 2014-08-04 17:36:41 +0000 | [diff] [blame] | 150 | EXPECT_EQ(*sys::path::rbegin(filename), (stem + ext).str()); |
Michael J. Spencer | 4d0c6fd | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 151 | |
Michael J. Spencer | 1e090f0 | 2010-12-07 03:57:37 +0000 | [diff] [blame] | 152 | path::native(*i, temp_store); |
Michael J. Spencer | ebad2f9 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 153 | } |
Benjamin Kramer | ae1d599 | 2015-10-05 13:02:43 +0000 | [diff] [blame] | 154 | |
| 155 | SmallString<32> Relative("foo.cpp"); |
| 156 | ASSERT_NO_ERROR(sys::fs::make_absolute("/root", Relative)); |
Benjamin Kramer | 2b4e14e | 2015-10-05 14:15:13 +0000 | [diff] [blame] | 157 | Relative[5] = '/'; // Fix up windows paths. |
Benjamin Kramer | ae1d599 | 2015-10-05 13:02:43 +0000 | [diff] [blame] | 158 | ASSERT_EQ("/root/foo.cpp", Relative); |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 159 | } |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 160 | |
Tareq A. Siraj | 73537ea | 2013-08-12 17:10:49 +0000 | [diff] [blame] | 161 | TEST(Support, RelativePathIterator) { |
| 162 | SmallString<64> Path(StringRef("c/d/e/foo.txt")); |
| 163 | typedef SmallVector<StringRef, 4> PathComponents; |
| 164 | PathComponents ExpectedPathComponents; |
| 165 | PathComponents ActualPathComponents; |
| 166 | |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 167 | StringRef(Path).split(ExpectedPathComponents, '/'); |
Tareq A. Siraj | 73537ea | 2013-08-12 17:10:49 +0000 | [diff] [blame] | 168 | |
| 169 | for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; |
| 170 | ++I) { |
| 171 | ActualPathComponents.push_back(*I); |
| 172 | } |
| 173 | |
| 174 | ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); |
| 175 | |
| 176 | for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) { |
| 177 | EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); |
| 178 | } |
| 179 | } |
| 180 | |
Ben Langmuir | 2547f93 | 2015-03-10 00:04:29 +0000 | [diff] [blame] | 181 | TEST(Support, RelativePathDotIterator) { |
| 182 | SmallString<64> Path(StringRef(".c/.d/../.")); |
| 183 | typedef SmallVector<StringRef, 4> PathComponents; |
| 184 | PathComponents ExpectedPathComponents; |
| 185 | PathComponents ActualPathComponents; |
| 186 | |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 187 | StringRef(Path).split(ExpectedPathComponents, '/'); |
Ben Langmuir | 2547f93 | 2015-03-10 00:04:29 +0000 | [diff] [blame] | 188 | |
| 189 | for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; |
| 190 | ++I) { |
| 191 | ActualPathComponents.push_back(*I); |
| 192 | } |
| 193 | |
| 194 | ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); |
| 195 | |
| 196 | for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) { |
| 197 | EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); |
| 198 | } |
| 199 | } |
| 200 | |
Tareq A. Siraj | 73537ea | 2013-08-12 17:10:49 +0000 | [diff] [blame] | 201 | TEST(Support, AbsolutePathIterator) { |
| 202 | SmallString<64> Path(StringRef("/c/d/e/foo.txt")); |
| 203 | typedef SmallVector<StringRef, 4> PathComponents; |
| 204 | PathComponents ExpectedPathComponents; |
| 205 | PathComponents ActualPathComponents; |
| 206 | |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 207 | StringRef(Path).split(ExpectedPathComponents, '/'); |
Tareq A. Siraj | 73537ea | 2013-08-12 17:10:49 +0000 | [diff] [blame] | 208 | |
| 209 | // The root path will also be a component when iterating |
| 210 | ExpectedPathComponents[0] = "/"; |
| 211 | |
| 212 | for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; |
| 213 | ++I) { |
| 214 | ActualPathComponents.push_back(*I); |
| 215 | } |
| 216 | |
| 217 | ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); |
| 218 | |
| 219 | for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) { |
| 220 | EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); |
| 221 | } |
| 222 | } |
| 223 | |
Ben Langmuir | 2547f93 | 2015-03-10 00:04:29 +0000 | [diff] [blame] | 224 | TEST(Support, AbsolutePathDotIterator) { |
| 225 | SmallString<64> Path(StringRef("/.c/.d/../.")); |
| 226 | typedef SmallVector<StringRef, 4> PathComponents; |
| 227 | PathComponents ExpectedPathComponents; |
| 228 | PathComponents ActualPathComponents; |
| 229 | |
Chandler Carruth | e4405e9 | 2015-09-10 06:12:31 +0000 | [diff] [blame] | 230 | StringRef(Path).split(ExpectedPathComponents, '/'); |
Ben Langmuir | 2547f93 | 2015-03-10 00:04:29 +0000 | [diff] [blame] | 231 | |
| 232 | // The root path will also be a component when iterating |
| 233 | ExpectedPathComponents[0] = "/"; |
| 234 | |
| 235 | for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; |
| 236 | ++I) { |
| 237 | ActualPathComponents.push_back(*I); |
| 238 | } |
| 239 | |
| 240 | ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); |
| 241 | |
| 242 | for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) { |
| 243 | EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); |
| 244 | } |
| 245 | } |
| 246 | |
Tareq A. Siraj | 73537ea | 2013-08-12 17:10:49 +0000 | [diff] [blame] | 247 | #ifdef LLVM_ON_WIN32 |
| 248 | TEST(Support, AbsolutePathIteratorWin32) { |
| 249 | SmallString<64> Path(StringRef("c:\\c\\e\\foo.txt")); |
| 250 | typedef SmallVector<StringRef, 4> PathComponents; |
| 251 | PathComponents ExpectedPathComponents; |
| 252 | PathComponents ActualPathComponents; |
| 253 | |
| 254 | StringRef(Path).split(ExpectedPathComponents, "\\"); |
| 255 | |
| 256 | // The root path (which comes after the drive name) will also be a component |
| 257 | // when iterating. |
| 258 | ExpectedPathComponents.insert(ExpectedPathComponents.begin()+1, "\\"); |
| 259 | |
| 260 | for (path::const_iterator I = path::begin(Path), E = path::end(Path); I != E; |
| 261 | ++I) { |
| 262 | ActualPathComponents.push_back(*I); |
| 263 | } |
| 264 | |
| 265 | ASSERT_EQ(ExpectedPathComponents.size(), ActualPathComponents.size()); |
| 266 | |
| 267 | for (size_t i = 0; i <ExpectedPathComponents.size(); ++i) { |
| 268 | EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); |
| 269 | } |
| 270 | } |
| 271 | #endif // LLVM_ON_WIN32 |
| 272 | |
Ben Langmuir | 8d11639 | 2014-03-05 19:56:30 +0000 | [diff] [blame] | 273 | TEST(Support, AbsolutePathIteratorEnd) { |
| 274 | // Trailing slashes are converted to '.' unless they are part of the root path. |
| 275 | SmallVector<StringRef, 4> Paths; |
| 276 | Paths.push_back("/foo/"); |
| 277 | Paths.push_back("/foo//"); |
| 278 | Paths.push_back("//net//"); |
| 279 | #ifdef LLVM_ON_WIN32 |
| 280 | Paths.push_back("c:\\\\"); |
| 281 | #endif |
| 282 | |
| 283 | for (StringRef Path : Paths) { |
Justin Bogner | 487e764 | 2014-08-04 17:36:41 +0000 | [diff] [blame] | 284 | StringRef LastComponent = *path::rbegin(Path); |
Ben Langmuir | 8d11639 | 2014-03-05 19:56:30 +0000 | [diff] [blame] | 285 | EXPECT_EQ(".", LastComponent); |
| 286 | } |
| 287 | |
| 288 | SmallVector<StringRef, 3> RootPaths; |
| 289 | RootPaths.push_back("/"); |
| 290 | RootPaths.push_back("//net/"); |
| 291 | #ifdef LLVM_ON_WIN32 |
| 292 | RootPaths.push_back("c:\\"); |
| 293 | #endif |
| 294 | |
| 295 | for (StringRef Path : RootPaths) { |
Justin Bogner | 487e764 | 2014-08-04 17:36:41 +0000 | [diff] [blame] | 296 | StringRef LastComponent = *path::rbegin(Path); |
Ben Langmuir | 8d11639 | 2014-03-05 19:56:30 +0000 | [diff] [blame] | 297 | EXPECT_EQ(1u, LastComponent.size()); |
| 298 | EXPECT_TRUE(path::is_separator(LastComponent[0])); |
| 299 | } |
| 300 | } |
| 301 | |
Peter Collingbourne | f7d4101 | 2014-01-31 23:46:06 +0000 | [diff] [blame] | 302 | TEST(Support, HomeDirectory) { |
NAKAMURA Takumi | cc275e4 | 2015-10-16 09:40:01 +0000 | [diff] [blame] | 303 | std::string expected; |
Pawel Bylica | 7187e4b | 2015-10-16 09:08:59 +0000 | [diff] [blame] | 304 | #ifdef LLVM_ON_WIN32 |
Pawel Bylica | 2fa025c | 2015-10-16 10:11:07 +0000 | [diff] [blame^] | 305 | if (wchar_t const *path = ::_wgetenv(L"USERPROFILE")) { |
| 306 | auto pathLen = ::wcslen(path); |
| 307 | ArrayRef<char> ref{reinterpret_cast<char const *>(path), |
| 308 | pathLen * sizeof(wchar_t)}; |
| 309 | convertUTF16ToUTF8String(ref, expected); |
| 310 | } |
Pawel Bylica | 7187e4b | 2015-10-16 09:08:59 +0000 | [diff] [blame] | 311 | #else |
Pawel Bylica | 2fa025c | 2015-10-16 10:11:07 +0000 | [diff] [blame^] | 312 | if (char const *path = ::getenv("HOME")) |
| 313 | expected = path; |
Peter Collingbourne | f7d4101 | 2014-01-31 23:46:06 +0000 | [diff] [blame] | 314 | #endif |
Pawel Bylica | 2fa025c | 2015-10-16 10:11:07 +0000 | [diff] [blame^] | 315 | // Do not try to test it if we don't know what to expect. |
| 316 | // On Windows we use something better than env vars. |
| 317 | if (!expected.empty()) { |
NAKAMURA Takumi | cc275e4 | 2015-10-16 09:40:01 +0000 | [diff] [blame] | 318 | SmallString<128> HomeDir; |
| 319 | auto status = path::home_directory(HomeDir); |
Pawel Bylica | 2fa025c | 2015-10-16 10:11:07 +0000 | [diff] [blame^] | 320 | EXPECT_TRUE(status); |
NAKAMURA Takumi | cc275e4 | 2015-10-16 09:40:01 +0000 | [diff] [blame] | 321 | EXPECT_EQ(expected, HomeDir); |
| 322 | } |
Peter Collingbourne | f7d4101 | 2014-01-31 23:46:06 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 325 | class FileSystemTest : public testing::Test { |
| 326 | protected: |
| 327 | /// Unique temporary directory in which all created filesystem entities must |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 328 | /// be placed. It is removed at the end of each test (must be empty). |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 329 | SmallString<128> TestDirectory; |
| 330 | |
Alexander Kornienko | f817c1c | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 331 | void SetUp() override { |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 332 | ASSERT_NO_ERROR( |
Rafael Espindola | 7ffacc4 | 2013-06-27 03:45:31 +0000 | [diff] [blame] | 333 | fs::createUniqueDirectory("file-system-test", TestDirectory)); |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 334 | // We don't care about this specific file. |
Michael J. Spencer | 42368cc | 2011-01-05 16:39:46 +0000 | [diff] [blame] | 335 | errs() << "Test Directory: " << TestDirectory << '\n'; |
| 336 | errs().flush(); |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Alexander Kornienko | f817c1c | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 339 | void TearDown() override { ASSERT_NO_ERROR(fs::remove(TestDirectory.str())); } |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 342 | TEST_F(FileSystemTest, Unique) { |
| 343 | // Create a temp file. |
| 344 | int FileDescriptor; |
| 345 | SmallString<64> TempPath; |
| 346 | ASSERT_NO_ERROR( |
Rafael Espindola | 155cf0f | 2013-07-05 20:14:52 +0000 | [diff] [blame] | 347 | fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 348 | |
| 349 | // The same file should return an identical unique id. |
Rafael Espindola | 7f822a9 | 2013-07-29 21:26:49 +0000 | [diff] [blame] | 350 | fs::UniqueID F1, F2; |
Rafael Espindola | 7cf7c51 | 2013-06-20 15:06:35 +0000 | [diff] [blame] | 351 | ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), F1)); |
| 352 | ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath), F2)); |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 353 | ASSERT_EQ(F1, F2); |
| 354 | |
| 355 | // Different files should return different unique ids. |
| 356 | int FileDescriptor2; |
| 357 | SmallString<64> TempPath2; |
| 358 | ASSERT_NO_ERROR( |
Rafael Espindola | 155cf0f | 2013-07-05 20:14:52 +0000 | [diff] [blame] | 359 | fs::createTemporaryFile("prefix", "temp", FileDescriptor2, TempPath2)); |
| 360 | |
Rafael Espindola | 7f822a9 | 2013-07-29 21:26:49 +0000 | [diff] [blame] | 361 | fs::UniqueID D; |
Rafael Espindola | 7cf7c51 | 2013-06-20 15:06:35 +0000 | [diff] [blame] | 362 | ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath2), D)); |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 363 | ASSERT_NE(D, F1); |
| 364 | ::close(FileDescriptor2); |
| 365 | |
| 366 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); |
| 367 | |
| 368 | // Two paths representing the same file on disk should still provide the |
| 369 | // same unique id. We can test this by making a hard link. |
Rafael Espindola | 83f858e | 2014-03-11 18:40:24 +0000 | [diff] [blame] | 370 | ASSERT_NO_ERROR(fs::create_link(Twine(TempPath), Twine(TempPath2))); |
Rafael Espindola | 7f822a9 | 2013-07-29 21:26:49 +0000 | [diff] [blame] | 371 | fs::UniqueID D2; |
Rafael Espindola | 7cf7c51 | 2013-06-20 15:06:35 +0000 | [diff] [blame] | 372 | ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath2), D2)); |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 373 | ASSERT_EQ(D2, F1); |
| 374 | |
| 375 | ::close(FileDescriptor); |
Rafael Espindola | a5932af | 2013-07-30 20:25:53 +0000 | [diff] [blame] | 376 | |
| 377 | SmallString<128> Dir1; |
| 378 | ASSERT_NO_ERROR( |
| 379 | fs::createUniqueDirectory("dir1", Dir1)); |
| 380 | ASSERT_NO_ERROR(fs::getUniqueID(Dir1.c_str(), F1)); |
| 381 | ASSERT_NO_ERROR(fs::getUniqueID(Dir1.c_str(), F2)); |
| 382 | ASSERT_EQ(F1, F2); |
| 383 | |
| 384 | SmallString<128> Dir2; |
| 385 | ASSERT_NO_ERROR( |
| 386 | fs::createUniqueDirectory("dir2", Dir2)); |
| 387 | ASSERT_NO_ERROR(fs::getUniqueID(Dir2.c_str(), F2)); |
| 388 | ASSERT_NE(F1, F2); |
Aaron Ballman | 9fbe530 | 2013-06-19 21:03:50 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 391 | TEST_F(FileSystemTest, TempFiles) { |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 392 | // Create a temp file. |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 393 | int FileDescriptor; |
| 394 | SmallString<64> TempPath; |
Michael J. Spencer | 3b264ba | 2011-01-04 17:00:18 +0000 | [diff] [blame] | 395 | ASSERT_NO_ERROR( |
Rafael Espindola | 155cf0f | 2013-07-05 20:14:52 +0000 | [diff] [blame] | 396 | fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 397 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 398 | // Make sure it exists. |
Rafael Espindola | c159915 | 2014-09-11 19:11:02 +0000 | [diff] [blame] | 399 | ASSERT_TRUE(sys::fs::exists(Twine(TempPath))); |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 400 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 401 | // Create another temp tile. |
| 402 | int FD2; |
| 403 | SmallString<64> TempPath2; |
Rafael Espindola | 155cf0f | 2013-07-05 20:14:52 +0000 | [diff] [blame] | 404 | ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "temp", FD2, TempPath2)); |
Rafael Espindola | d3c8904 | 2013-07-25 15:00:17 +0000 | [diff] [blame] | 405 | ASSERT_TRUE(TempPath2.endswith(".temp")); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 406 | ASSERT_NE(TempPath.str(), TempPath2.str()); |
| 407 | |
Michael J. Spencer | 203d780 | 2011-12-12 06:04:28 +0000 | [diff] [blame] | 408 | fs::file_status A, B; |
| 409 | ASSERT_NO_ERROR(fs::status(Twine(TempPath), A)); |
| 410 | ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B)); |
| 411 | EXPECT_FALSE(fs::equivalent(A, B)); |
| 412 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 413 | ::close(FD2); |
Rafael Espindola | 213c4cb | 2013-07-18 03:29:51 +0000 | [diff] [blame] | 414 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 415 | // Remove Temp2. |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 416 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); |
| 417 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); |
| 418 | ASSERT_EQ(fs::remove(Twine(TempPath2), false), |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 419 | errc::no_such_file_or_directory); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 420 | |
Rafael Espindola | c049c65 | 2014-06-13 03:20:08 +0000 | [diff] [blame] | 421 | std::error_code EC = fs::status(TempPath2.c_str(), B); |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 422 | EXPECT_EQ(EC, errc::no_such_file_or_directory); |
Rafael Espindola | 107b74c | 2013-07-31 00:10:25 +0000 | [diff] [blame] | 423 | EXPECT_EQ(B.type(), fs::file_type::file_not_found); |
| 424 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 425 | // Make sure Temp2 doesn't exist. |
Rafael Espindola | 281f23a | 2014-09-11 20:30:02 +0000 | [diff] [blame] | 426 | ASSERT_EQ(fs::access(Twine(TempPath2), sys::fs::AccessMode::Exist), |
| 427 | errc::no_such_file_or_directory); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 428 | |
Rafael Espindola | d3c8904 | 2013-07-25 15:00:17 +0000 | [diff] [blame] | 429 | SmallString<64> TempPath3; |
| 430 | ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "", TempPath3)); |
| 431 | ASSERT_FALSE(TempPath3.endswith(".")); |
| 432 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 433 | // Create a hard link to Temp1. |
Rafael Espindola | 83f858e | 2014-03-11 18:40:24 +0000 | [diff] [blame] | 434 | ASSERT_NO_ERROR(fs::create_link(Twine(TempPath), Twine(TempPath2))); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 435 | bool equal; |
Michael J. Spencer | 3b264ba | 2011-01-04 17:00:18 +0000 | [diff] [blame] | 436 | ASSERT_NO_ERROR(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal)); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 437 | EXPECT_TRUE(equal); |
Michael J. Spencer | 203d780 | 2011-12-12 06:04:28 +0000 | [diff] [blame] | 438 | ASSERT_NO_ERROR(fs::status(Twine(TempPath), A)); |
| 439 | ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B)); |
| 440 | EXPECT_TRUE(fs::equivalent(A, B)); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 441 | |
| 442 | // Remove Temp1. |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 443 | ::close(FileDescriptor); |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 444 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath))); |
Michael J. Spencer | 4571040 | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 445 | |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 446 | // Remove the hard link. |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 447 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); |
Michael J. Spencer | 4fb115d | 2010-12-04 03:18:42 +0000 | [diff] [blame] | 448 | |
| 449 | // Make sure Temp1 doesn't exist. |
Rafael Espindola | 281f23a | 2014-09-11 20:30:02 +0000 | [diff] [blame] | 450 | ASSERT_EQ(fs::access(Twine(TempPath), sys::fs::AccessMode::Exist), |
| 451 | errc::no_such_file_or_directory); |
Aaron Ballman | fcdf9a8 | 2013-03-16 15:00:51 +0000 | [diff] [blame] | 452 | |
| 453 | #ifdef LLVM_ON_WIN32 |
| 454 | // Path name > 260 chars should get an error. |
| 455 | const char *Path270 = |
| 456 | "abcdefghijklmnopqrstuvwxyz9abcdefghijklmnopqrstuvwxyz8" |
| 457 | "abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz6" |
| 458 | "abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz4" |
| 459 | "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2" |
| 460 | "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0"; |
Paul Robinson | 1b6c734 | 2014-11-13 00:36:34 +0000 | [diff] [blame] | 461 | EXPECT_EQ(fs::createUniqueFile(Path270, FileDescriptor, TempPath), |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 462 | errc::invalid_argument); |
| 463 | // Relative path < 247 chars, no problem. |
| 464 | const char *Path216 = |
| 465 | "abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz6" |
| 466 | "abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz4" |
| 467 | "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2" |
| 468 | "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0"; |
Paul Robinson | 1b6c734 | 2014-11-13 00:36:34 +0000 | [diff] [blame] | 469 | ASSERT_NO_ERROR(fs::createTemporaryFile(Path216, "", TempPath)); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 470 | ASSERT_NO_ERROR(fs::remove(Twine(TempPath))); |
Aaron Ballman | fcdf9a8 | 2013-03-16 15:00:51 +0000 | [diff] [blame] | 471 | #endif |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 472 | } |
Michael J. Spencer | 7ecd94c | 2010-12-06 04:28:42 +0000 | [diff] [blame] | 473 | |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 474 | TEST_F(FileSystemTest, CreateDir) { |
| 475 | ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); |
| 476 | ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); |
| 477 | ASSERT_EQ(fs::create_directory(Twine(TestDirectory) + "foo", false), |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 478 | errc::file_exists); |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 479 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo")); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 480 | |
Frederic Riss | 6b9396c | 2015-08-06 21:04:55 +0000 | [diff] [blame] | 481 | #ifdef LLVM_ON_UNIX |
| 482 | // Set a 0000 umask so that we can test our directory permissions. |
| 483 | mode_t OldUmask = ::umask(0000); |
| 484 | |
| 485 | fs::file_status Status; |
| 486 | ASSERT_NO_ERROR( |
| 487 | fs::create_directory(Twine(TestDirectory) + "baz500", false, |
| 488 | fs::perms::owner_read | fs::perms::owner_exe)); |
| 489 | ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz500", Status)); |
| 490 | ASSERT_EQ(Status.permissions() & fs::perms::all_all, |
| 491 | fs::perms::owner_read | fs::perms::owner_exe); |
| 492 | ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "baz777", false, |
| 493 | fs::perms::all_all)); |
| 494 | ASSERT_NO_ERROR(fs::status(Twine(TestDirectory) + "baz777", Status)); |
| 495 | ASSERT_EQ(Status.permissions() & fs::perms::all_all, fs::perms::all_all); |
| 496 | |
| 497 | // Restore umask to be safe. |
| 498 | ::umask(OldUmask); |
| 499 | #endif |
| 500 | |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 501 | #ifdef LLVM_ON_WIN32 |
| 502 | // Prove that create_directories() can handle a pathname > 248 characters, |
| 503 | // which is the documented limit for CreateDirectory(). |
| 504 | // (248 is MAX_PATH subtracting room for an 8.3 filename.) |
| 505 | // Generate a directory path guaranteed to fall into that range. |
| 506 | size_t TmpLen = TestDirectory.size(); |
| 507 | const char *OneDir = "\\123456789"; |
| 508 | size_t OneDirLen = strlen(OneDir); |
Aaron Ballman | 493456e | 2014-11-13 13:39:49 +0000 | [diff] [blame] | 509 | ASSERT_LT(OneDirLen, 12U); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 510 | size_t NLevels = ((248 - TmpLen) / OneDirLen) + 1; |
| 511 | SmallString<260> LongDir(TestDirectory); |
| 512 | for (size_t I = 0; I < NLevels; ++I) |
| 513 | LongDir.append(OneDir); |
| 514 | ASSERT_NO_ERROR(fs::create_directories(Twine(LongDir))); |
| 515 | ASSERT_NO_ERROR(fs::create_directories(Twine(LongDir))); |
| 516 | ASSERT_EQ(fs::create_directories(Twine(LongDir), false), |
| 517 | errc::file_exists); |
| 518 | // Tidy up, "recursively" removing the directories. |
| 519 | StringRef ThisDir(LongDir); |
| 520 | for (size_t J = 0; J < NLevels; ++J) { |
| 521 | ASSERT_NO_ERROR(fs::remove(ThisDir)); |
| 522 | ThisDir = path::parent_path(ThisDir); |
| 523 | } |
| 524 | |
| 525 | // Similarly for a relative pathname. Need to set the current directory to |
| 526 | // TestDirectory so that the one we create ends up in the right place. |
| 527 | char PreviousDir[260]; |
| 528 | size_t PreviousDirLen = ::GetCurrentDirectoryA(260, PreviousDir); |
Aaron Ballman | 493456e | 2014-11-13 13:39:49 +0000 | [diff] [blame] | 529 | ASSERT_GT(PreviousDirLen, 0U); |
| 530 | ASSERT_LT(PreviousDirLen, 260U); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 531 | ASSERT_NE(::SetCurrentDirectoryA(TestDirectory.c_str()), 0); |
| 532 | LongDir.clear(); |
| 533 | // Generate a relative directory name with absolute length > 248. |
| 534 | size_t LongDirLen = 249 - TestDirectory.size(); |
| 535 | LongDir.assign(LongDirLen, 'a'); |
| 536 | ASSERT_NO_ERROR(fs::create_directory(Twine(LongDir))); |
| 537 | // While we're here, prove that .. and . handling works in these long paths. |
| 538 | const char *DotDotDirs = "\\..\\.\\b"; |
| 539 | LongDir.append(DotDotDirs); |
Paul Robinson | 1b6c734 | 2014-11-13 00:36:34 +0000 | [diff] [blame] | 540 | ASSERT_NO_ERROR(fs::create_directory("b")); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 541 | ASSERT_EQ(fs::create_directory(Twine(LongDir), false), errc::file_exists); |
| 542 | // And clean up. |
Paul Robinson | 1b6c734 | 2014-11-13 00:36:34 +0000 | [diff] [blame] | 543 | ASSERT_NO_ERROR(fs::remove("b")); |
Paul Robinson | d9c4a9a | 2014-11-13 00:12:14 +0000 | [diff] [blame] | 544 | ASSERT_NO_ERROR(fs::remove( |
| 545 | Twine(LongDir.substr(0, LongDir.size() - strlen(DotDotDirs))))); |
| 546 | ASSERT_NE(::SetCurrentDirectoryA(PreviousDir), 0); |
| 547 | #endif |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Michael J. Spencer | 346a133 | 2011-01-05 16:39:05 +0000 | [diff] [blame] | 550 | TEST_F(FileSystemTest, DirectoryIteration) { |
Rafael Espindola | c049c65 | 2014-06-13 03:20:08 +0000 | [diff] [blame] | 551 | std::error_code ec; |
Michael J. Spencer | 1f06360 | 2011-01-06 05:57:54 +0000 | [diff] [blame] | 552 | for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec)) |
| 553 | ASSERT_NO_ERROR(ec); |
Michael J. Spencer | 0a7625d | 2011-12-08 22:50:09 +0000 | [diff] [blame] | 554 | |
| 555 | // Create a known hierarchy to recurse over. |
Rafael Espindola | 5c20ac0 | 2014-02-23 13:56:14 +0000 | [diff] [blame] | 556 | ASSERT_NO_ERROR( |
| 557 | fs::create_directories(Twine(TestDirectory) + "/recursive/a0/aa1")); |
| 558 | ASSERT_NO_ERROR( |
| 559 | fs::create_directories(Twine(TestDirectory) + "/recursive/a0/ab1")); |
| 560 | ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) + |
| 561 | "/recursive/dontlookhere/da1")); |
| 562 | ASSERT_NO_ERROR( |
| 563 | fs::create_directories(Twine(TestDirectory) + "/recursive/z0/za1")); |
| 564 | ASSERT_NO_ERROR( |
| 565 | fs::create_directories(Twine(TestDirectory) + "/recursive/pop/p1")); |
Michael J. Spencer | 0a7625d | 2011-12-08 22:50:09 +0000 | [diff] [blame] | 566 | typedef std::vector<std::string> v_t; |
| 567 | v_t visited; |
| 568 | for (fs::recursive_directory_iterator i(Twine(TestDirectory) |
| 569 | + "/recursive", ec), e; i != e; i.increment(ec)){ |
| 570 | ASSERT_NO_ERROR(ec); |
NAKAMURA Takumi | 0cfb367 | 2011-12-09 23:20:03 +0000 | [diff] [blame] | 571 | if (path::filename(i->path()) == "p1") { |
Michael J. Spencer | 0a7625d | 2011-12-08 22:50:09 +0000 | [diff] [blame] | 572 | i.pop(); |
NAKAMURA Takumi | 0cfb367 | 2011-12-09 23:20:03 +0000 | [diff] [blame] | 573 | // FIXME: recursive_directory_iterator should be more robust. |
| 574 | if (i == e) break; |
| 575 | } |
Michael J. Spencer | 9b54a3e | 2011-12-09 01:14:41 +0000 | [diff] [blame] | 576 | if (path::filename(i->path()) == "dontlookhere") |
| 577 | i.no_push(); |
Michael J. Spencer | 0a7625d | 2011-12-08 22:50:09 +0000 | [diff] [blame] | 578 | visited.push_back(path::filename(i->path())); |
| 579 | } |
| 580 | v_t::const_iterator a0 = std::find(visited.begin(), visited.end(), "a0"); |
| 581 | v_t::const_iterator aa1 = std::find(visited.begin(), visited.end(), "aa1"); |
| 582 | v_t::const_iterator ab1 = std::find(visited.begin(), visited.end(), "ab1"); |
| 583 | v_t::const_iterator dontlookhere = std::find(visited.begin(), visited.end(), |
| 584 | "dontlookhere"); |
| 585 | v_t::const_iterator da1 = std::find(visited.begin(), visited.end(), "da1"); |
| 586 | v_t::const_iterator z0 = std::find(visited.begin(), visited.end(), "z0"); |
| 587 | v_t::const_iterator za1 = std::find(visited.begin(), visited.end(), "za1"); |
| 588 | v_t::const_iterator pop = std::find(visited.begin(), visited.end(), "pop"); |
| 589 | v_t::const_iterator p1 = std::find(visited.begin(), visited.end(), "p1"); |
| 590 | |
| 591 | // Make sure that each path was visited correctly. |
| 592 | ASSERT_NE(a0, visited.end()); |
| 593 | ASSERT_NE(aa1, visited.end()); |
| 594 | ASSERT_NE(ab1, visited.end()); |
| 595 | ASSERT_NE(dontlookhere, visited.end()); |
| 596 | ASSERT_EQ(da1, visited.end()); // Not visited. |
| 597 | ASSERT_NE(z0, visited.end()); |
| 598 | ASSERT_NE(za1, visited.end()); |
| 599 | ASSERT_NE(pop, visited.end()); |
| 600 | ASSERT_EQ(p1, visited.end()); // Not visited. |
| 601 | |
| 602 | // Make sure that parents were visited before children. No other ordering |
| 603 | // guarantees can be made across siblings. |
| 604 | ASSERT_LT(a0, aa1); |
| 605 | ASSERT_LT(a0, ab1); |
| 606 | ASSERT_LT(z0, za1); |
Rafael Espindola | 78dcc03 | 2014-01-10 20:36:42 +0000 | [diff] [blame] | 607 | |
| 608 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/aa1")); |
| 609 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/ab1")); |
| 610 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0")); |
| 611 | ASSERT_NO_ERROR( |
| 612 | fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere/da1")); |
| 613 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere")); |
| 614 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop/p1")); |
| 615 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop")); |
| 616 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0/za1")); |
| 617 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0")); |
| 618 | ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive")); |
Michael J. Spencer | 1f06360 | 2011-01-06 05:57:54 +0000 | [diff] [blame] | 619 | } |
Michael J. Spencer | 1d3c4a7 | 2011-01-06 05:58:02 +0000 | [diff] [blame] | 620 | |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 621 | const char archive[] = "!<arch>\x0A"; |
| 622 | const char bitcode[] = "\xde\xc0\x17\x0b"; |
Rui Ueyama | 829c439 | 2013-11-14 22:09:08 +0000 | [diff] [blame] | 623 | const char coff_object[] = "\x00\x00......"; |
Rui Ueyama | 5c69ff5 | 2014-09-11 22:34:32 +0000 | [diff] [blame] | 624 | const char coff_bigobj[] = "\x00\x00\xff\xff\x00\x02......" |
Rui Ueyama | 2acb058 | 2014-09-11 21:09:57 +0000 | [diff] [blame] | 625 | "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8"; |
Rui Ueyama | e448f9e | 2013-11-15 21:22:02 +0000 | [diff] [blame] | 626 | const char coff_import_library[] = "\x00\x00\xff\xff...."; |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 627 | const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, |
| 628 | 0, 0, 0, 0, 0, 0, 0, 0, 1 }; |
| 629 | const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\0x00"; |
| 630 | const char macho_object[] = "\xfe\xed\xfa\xce..........\x00\x01"; |
| 631 | const char macho_executable[] = "\xfe\xed\xfa\xce..........\x00\x02"; |
| 632 | const char macho_fixed_virtual_memory_shared_lib[] = |
| 633 | "\xfe\xed\xfa\xce..........\x00\x03"; |
| 634 | const char macho_core[] = "\xfe\xed\xfa\xce..........\x00\x04"; |
| 635 | const char macho_preload_executable[] = "\xfe\xed\xfa\xce..........\x00\x05"; |
| 636 | const char macho_dynamically_linked_shared_lib[] = |
| 637 | "\xfe\xed\xfa\xce..........\x00\x06"; |
| 638 | const char macho_dynamic_linker[] = "\xfe\xed\xfa\xce..........\x00\x07"; |
| 639 | const char macho_bundle[] = "\xfe\xed\xfa\xce..........\x00\x08"; |
| 640 | const char macho_dsym_companion[] = "\xfe\xed\xfa\xce..........\x00\x0a"; |
Justin Bogner | a7ad4b3 | 2015-02-25 22:59:20 +0000 | [diff] [blame] | 641 | const char macho_kext_bundle[] = "\xfe\xed\xfa\xce..........\x00\x0b"; |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 642 | const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff"; |
Nick Kledzik | 2d2b254 | 2014-09-17 00:53:44 +0000 | [diff] [blame] | 643 | const char macho_dynamically_linked_shared_lib_stub[] = |
| 644 | "\xfe\xed\xfa\xce..........\x00\x09"; |
Michael J. Spencer | b8055cb | 2013-04-05 20:10:04 +0000 | [diff] [blame] | 645 | |
Michael J. Spencer | 1d3c4a7 | 2011-01-06 05:58:02 +0000 | [diff] [blame] | 646 | TEST_F(FileSystemTest, Magic) { |
| 647 | struct type { |
| 648 | const char *filename; |
| 649 | const char *magic_str; |
Michael J. Spencer | b8055cb | 2013-04-05 20:10:04 +0000 | [diff] [blame] | 650 | size_t magic_str_len; |
| 651 | fs::file_magic magic; |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 652 | } types[] = { |
| 653 | #define DEFINE(magic) \ |
| 654 | { #magic, magic, sizeof(magic), fs::file_magic::magic } |
| 655 | DEFINE(archive), |
| 656 | DEFINE(bitcode), |
Rui Ueyama | 829c439 | 2013-11-14 22:09:08 +0000 | [diff] [blame] | 657 | DEFINE(coff_object), |
Rui Ueyama | 2acb058 | 2014-09-11 21:09:57 +0000 | [diff] [blame] | 658 | { "coff_bigobj", coff_bigobj, sizeof(coff_bigobj), fs::file_magic::coff_object }, |
Rui Ueyama | e448f9e | 2013-11-15 21:22:02 +0000 | [diff] [blame] | 659 | DEFINE(coff_import_library), |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 660 | DEFINE(elf_relocatable), |
| 661 | DEFINE(macho_universal_binary), |
| 662 | DEFINE(macho_object), |
| 663 | DEFINE(macho_executable), |
| 664 | DEFINE(macho_fixed_virtual_memory_shared_lib), |
| 665 | DEFINE(macho_core), |
| 666 | DEFINE(macho_preload_executable), |
| 667 | DEFINE(macho_dynamically_linked_shared_lib), |
| 668 | DEFINE(macho_dynamic_linker), |
| 669 | DEFINE(macho_bundle), |
Nick Kledzik | 2d2b254 | 2014-09-17 00:53:44 +0000 | [diff] [blame] | 670 | DEFINE(macho_dynamically_linked_shared_lib_stub), |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 671 | DEFINE(macho_dsym_companion), |
Justin Bogner | a7ad4b3 | 2015-02-25 22:59:20 +0000 | [diff] [blame] | 672 | DEFINE(macho_kext_bundle), |
Rui Ueyama | 5e3de7a | 2013-11-13 21:55:41 +0000 | [diff] [blame] | 673 | DEFINE(windows_resource) |
| 674 | #undef DEFINE |
| 675 | }; |
Michael J. Spencer | 1d3c4a7 | 2011-01-06 05:58:02 +0000 | [diff] [blame] | 676 | |
| 677 | // Create some files filled with magic. |
| 678 | for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; |
| 679 | ++i) { |
| 680 | SmallString<128> file_pathname(TestDirectory); |
| 681 | path::append(file_pathname, i->filename); |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 682 | std::error_code EC; |
| 683 | raw_fd_ostream file(file_pathname, EC, sys::fs::F_None); |
Michael J. Spencer | 1d3c4a7 | 2011-01-06 05:58:02 +0000 | [diff] [blame] | 684 | ASSERT_FALSE(file.has_error()); |
| 685 | StringRef magic(i->magic_str, i->magic_str_len); |
| 686 | file << magic; |
Michael J. Spencer | b587180 | 2011-01-15 18:52:49 +0000 | [diff] [blame] | 687 | file.close(); |
Michael J. Spencer | b8055cb | 2013-04-05 20:10:04 +0000 | [diff] [blame] | 688 | EXPECT_EQ(i->magic, fs::identify_magic(magic)); |
Rafael Espindola | 78dcc03 | 2014-01-10 20:36:42 +0000 | [diff] [blame] | 689 | ASSERT_NO_ERROR(fs::remove(Twine(file_pathname))); |
Michael J. Spencer | 7ecd94c | 2010-12-06 04:28:42 +0000 | [diff] [blame] | 690 | } |
Michael J. Spencer | 9884778 | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 693 | #ifdef LLVM_ON_WIN32 |
| 694 | TEST_F(FileSystemTest, CarriageReturn) { |
| 695 | SmallString<128> FilePathname(TestDirectory); |
Reid Kleckner | d83c63b | 2014-08-26 00:24:23 +0000 | [diff] [blame] | 696 | std::error_code EC; |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 697 | path::append(FilePathname, "test"); |
| 698 | |
| 699 | { |
Reid Kleckner | d83c63b | 2014-08-26 00:24:23 +0000 | [diff] [blame] | 700 | raw_fd_ostream File(FilePathname, EC, sys::fs::F_Text); |
| 701 | ASSERT_NO_ERROR(EC); |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 702 | File << '\n'; |
| 703 | } |
| 704 | { |
Reid Kleckner | d83c63b | 2014-08-26 00:24:23 +0000 | [diff] [blame] | 705 | auto Buf = MemoryBuffer::getFile(FilePathname.str()); |
Aaron Ballman | 586ee60 | 2014-07-06 20:20:02 +0000 | [diff] [blame] | 706 | EXPECT_TRUE((bool)Buf); |
Aaron Ballman | e56fe8a | 2014-07-06 19:34:52 +0000 | [diff] [blame] | 707 | EXPECT_EQ(Buf.get()->getBuffer(), "\r\n"); |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | { |
Reid Kleckner | d83c63b | 2014-08-26 00:24:23 +0000 | [diff] [blame] | 711 | raw_fd_ostream File(FilePathname, EC, sys::fs::F_None); |
| 712 | ASSERT_NO_ERROR(EC); |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 713 | File << '\n'; |
| 714 | } |
| 715 | { |
Reid Kleckner | d83c63b | 2014-08-26 00:24:23 +0000 | [diff] [blame] | 716 | auto Buf = MemoryBuffer::getFile(FilePathname.str()); |
Aaron Ballman | 586ee60 | 2014-07-06 20:20:02 +0000 | [diff] [blame] | 717 | EXPECT_TRUE((bool)Buf); |
Aaron Ballman | e56fe8a | 2014-07-06 19:34:52 +0000 | [diff] [blame] | 718 | EXPECT_EQ(Buf.get()->getBuffer(), "\n"); |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 719 | } |
Rafael Espindola | 78dcc03 | 2014-01-10 20:36:42 +0000 | [diff] [blame] | 720 | ASSERT_NO_ERROR(fs::remove(Twine(FilePathname))); |
Rafael Espindola | 84ab9b3 | 2013-07-19 14:41:25 +0000 | [diff] [blame] | 721 | } |
| 722 | #endif |
| 723 | |
Rafael Espindola | 59aaa6c | 2014-12-12 17:55:12 +0000 | [diff] [blame] | 724 | TEST_F(FileSystemTest, Resize) { |
| 725 | int FD; |
| 726 | SmallString<64> TempPath; |
| 727 | ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "temp", FD, TempPath)); |
| 728 | ASSERT_NO_ERROR(fs::resize_file(FD, 123)); |
| 729 | fs::file_status Status; |
| 730 | ASSERT_NO_ERROR(fs::status(FD, Status)); |
| 731 | ASSERT_EQ(Status.getSize(), 123U); |
| 732 | } |
| 733 | |
Nick Kledzik | 18497e9 | 2012-06-20 00:28:54 +0000 | [diff] [blame] | 734 | TEST_F(FileSystemTest, FileMapping) { |
| 735 | // Create a temp file. |
| 736 | int FileDescriptor; |
| 737 | SmallString<64> TempPath; |
| 738 | ASSERT_NO_ERROR( |
Rafael Espindola | 155cf0f | 2013-07-05 20:14:52 +0000 | [diff] [blame] | 739 | fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); |
Rafael Espindola | c69f13b | 2014-12-12 18:13:23 +0000 | [diff] [blame] | 740 | unsigned Size = 4096; |
| 741 | ASSERT_NO_ERROR(fs::resize_file(FileDescriptor, Size)); |
| 742 | |
Nick Kledzik | 18497e9 | 2012-06-20 00:28:54 +0000 | [diff] [blame] | 743 | // Map in temp file and add some content |
Rafael Espindola | c049c65 | 2014-06-13 03:20:08 +0000 | [diff] [blame] | 744 | std::error_code EC; |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 745 | StringRef Val("hello there"); |
| 746 | { |
| 747 | fs::mapped_file_region mfr(FileDescriptor, |
Rafael Espindola | c69f13b | 2014-12-12 18:13:23 +0000 | [diff] [blame] | 748 | fs::mapped_file_region::readwrite, Size, 0, EC); |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 749 | ASSERT_NO_ERROR(EC); |
| 750 | std::copy(Val.begin(), Val.end(), mfr.data()); |
| 751 | // Explicitly add a 0. |
| 752 | mfr.data()[Val.size()] = 0; |
| 753 | // Unmap temp file |
| 754 | } |
Rui Ueyama | 89d1bdb | 2013-11-13 20:31:21 +0000 | [diff] [blame] | 755 | |
Nick Kledzik | 18497e9 | 2012-06-20 00:28:54 +0000 | [diff] [blame] | 756 | // Map it back in read-only |
Rafael Espindola | 71bc507 | 2014-12-11 17:17:26 +0000 | [diff] [blame] | 757 | int FD; |
| 758 | EC = fs::openFileForRead(Twine(TempPath), FD); |
| 759 | ASSERT_NO_ERROR(EC); |
Rafael Espindola | c69f13b | 2014-12-12 18:13:23 +0000 | [diff] [blame] | 760 | fs::mapped_file_region mfr(FD, fs::mapped_file_region::readonly, Size, 0, EC); |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 761 | ASSERT_NO_ERROR(EC); |
Rui Ueyama | 89d1bdb | 2013-11-13 20:31:21 +0000 | [diff] [blame] | 762 | |
Nick Kledzik | 18497e9 | 2012-06-20 00:28:54 +0000 | [diff] [blame] | 763 | // Verify content |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 764 | EXPECT_EQ(StringRef(mfr.const_data()), Val); |
Rui Ueyama | 89d1bdb | 2013-11-13 20:31:21 +0000 | [diff] [blame] | 765 | |
Nick Kledzik | 18497e9 | 2012-06-20 00:28:54 +0000 | [diff] [blame] | 766 | // Unmap temp file |
Rafael Espindola | c69f13b | 2014-12-12 18:13:23 +0000 | [diff] [blame] | 767 | fs::mapped_file_region m(FD, fs::mapped_file_region::readonly, Size, 0, EC); |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 768 | ASSERT_NO_ERROR(EC); |
Rafael Espindola | 71bc507 | 2014-12-11 17:17:26 +0000 | [diff] [blame] | 769 | ASSERT_EQ(close(FD), 0); |
Michael J. Spencer | ef2284f | 2012-08-15 19:05:47 +0000 | [diff] [blame] | 770 | } |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 771 | |
| 772 | TEST(Support, NormalizePath) { |
| 773 | #if defined(LLVM_ON_WIN32) |
| 774 | #define EXPECT_PATH_IS(path__, windows__, not_windows__) \ |
| 775 | EXPECT_EQ(path__, windows__); |
| 776 | #else |
| 777 | #define EXPECT_PATH_IS(path__, windows__, not_windows__) \ |
| 778 | EXPECT_EQ(path__, not_windows__); |
| 779 | #endif |
| 780 | |
| 781 | SmallString<64> Path1("a"); |
| 782 | SmallString<64> Path2("a/b"); |
| 783 | SmallString<64> Path3("a\\b"); |
| 784 | SmallString<64> Path4("a\\\\b"); |
| 785 | SmallString<64> Path5("\\a"); |
| 786 | SmallString<64> Path6("a\\"); |
| 787 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 788 | path::native(Path1); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 789 | EXPECT_PATH_IS(Path1, "a", "a"); |
| 790 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 791 | path::native(Path2); |
Rafael Espindola | ffbabb7 | 2014-08-09 00:37:05 +0000 | [diff] [blame] | 792 | EXPECT_PATH_IS(Path2, "a\\b", "a/b"); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 793 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 794 | path::native(Path3); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 795 | EXPECT_PATH_IS(Path3, "a\\b", "a/b"); |
| 796 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 797 | path::native(Path4); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 798 | EXPECT_PATH_IS(Path4, "a\\\\b", "a\\\\b"); |
| 799 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 800 | path::native(Path5); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 801 | EXPECT_PATH_IS(Path5, "\\a", "/a"); |
| 802 | |
Rafael Espindola | 7e774c2 | 2014-08-08 21:35:52 +0000 | [diff] [blame] | 803 | path::native(Path6); |
Saleem Abdulrasool | afc50b3ed | 2014-03-11 22:05:42 +0000 | [diff] [blame] | 804 | EXPECT_PATH_IS(Path6, "a\\", "a/"); |
| 805 | |
| 806 | #undef EXPECT_PATH_IS |
| 807 | } |
Douglas Katzman | a26be4a | 2015-09-02 21:02:10 +0000 | [diff] [blame] | 808 | |
| 809 | TEST(Support, RemoveLeadingDotSlash) { |
| 810 | StringRef Path1("././/foolz/wat"); |
| 811 | StringRef Path2("./////"); |
| 812 | |
| 813 | Path1 = path::remove_leading_dotslash(Path1); |
| 814 | EXPECT_EQ(Path1, "foolz/wat"); |
| 815 | Path2 = path::remove_leading_dotslash(Path2); |
| 816 | EXPECT_EQ(Path2, ""); |
| 817 | } |
Michael J. Spencer | 9884778 | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 818 | } // anonymous namespace |