comparison unittests/Support/Path.cpp @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 60c9769439b8
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #include "llvm/Support/Path.h" 10 #include "llvm/Support/Path.h"
11 #include "llvm/Support/Errc.h"
11 #include "llvm/Support/ErrorHandling.h" 12 #include "llvm/Support/ErrorHandling.h"
12 #include "llvm/Support/FileSystem.h" 13 #include "llvm/Support/FileSystem.h"
13 #include "llvm/Support/MemoryBuffer.h" 14 #include "llvm/Support/MemoryBuffer.h"
14 #include "llvm/Support/raw_ostream.h" 15 #include "llvm/Support/raw_ostream.h"
15 #include "gtest/gtest.h" 16 #include "gtest/gtest.h"
16 17
18 #ifdef LLVM_ON_WIN32
19 #include <winerror.h>
20 #endif
21
17 using namespace llvm; 22 using namespace llvm;
18 using namespace llvm::sys; 23 using namespace llvm::sys;
19 24
20 #define ASSERT_NO_ERROR(x) \ 25 #define ASSERT_NO_ERROR(x) \
21 if (error_code ASSERT_NO_ERROR_ec = x) { \ 26 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
22 SmallString<128> MessageStorage; \ 27 SmallString<128> MessageStorage; \
23 raw_svector_ostream Message(MessageStorage); \ 28 raw_svector_ostream Message(MessageStorage); \
24 Message << #x ": did not return errc::success.\n" \ 29 Message << #x ": did not return errc::success.\n" \
25 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ 30 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
26 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ 31 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
27 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ 32 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
28 } else {} 33 } else { \
34 }
29 35
30 namespace { 36 namespace {
31 37
32 TEST(is_separator, Works) { 38 TEST(is_separator, Works) {
33 EXPECT_TRUE(path::is_separator('/')); 39 EXPECT_TRUE(path::is_separator('/'));
83 paths.push_back("c:foo\\"); 89 paths.push_back("c:foo\\");
84 paths.push_back("c:\\foo\\"); 90 paths.push_back("c:\\foo\\");
85 paths.push_back("c:\\foo/"); 91 paths.push_back("c:\\foo/");
86 paths.push_back("c:/foo\\bar"); 92 paths.push_back("c:/foo\\bar");
87 93
94 SmallVector<StringRef, 5> ComponentStack;
88 for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(), 95 for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(),
89 e = paths.end(); 96 e = paths.end();
90 i != e; 97 i != e;
91 ++i) { 98 ++i) {
92 for (sys::path::const_iterator ci = sys::path::begin(*i), 99 for (sys::path::const_iterator ci = sys::path::begin(*i),
93 ce = sys::path::end(*i); 100 ce = sys::path::end(*i);
94 ci != ce; 101 ci != ce;
95 ++ci) { 102 ++ci) {
96 ASSERT_FALSE(ci->empty()); 103 ASSERT_FALSE(ci->empty());
104 ComponentStack.push_back(*ci);
97 } 105 }
98 106
99 #if 0 // Valgrind is whining about this.
100 outs() << " Reverse Iteration: [";
101 for (sys::path::reverse_iterator ci = sys::path::rbegin(*i), 107 for (sys::path::reverse_iterator ci = sys::path::rbegin(*i),
102 ce = sys::path::rend(*i); 108 ce = sys::path::rend(*i);
103 ci != ce; 109 ci != ce;
104 ++ci) { 110 ++ci) {
105 outs() << *ci << ','; 111 ASSERT_TRUE(*ci == ComponentStack.back());
112 ComponentStack.pop_back();
106 } 113 }
107 outs() << "]\n"; 114 ASSERT_TRUE(ComponentStack.empty());
108 #endif
109 115
110 path::has_root_path(*i); 116 path::has_root_path(*i);
111 path::root_path(*i); 117 path::root_path(*i);
112 path::has_root_name(*i); 118 path::has_root_name(*i);
113 path::root_name(*i); 119 path::root_name(*i);
133 temp_store = *i; 139 temp_store = *i;
134 path::replace_extension(temp_store, "ext"); 140 path::replace_extension(temp_store, "ext");
135 StringRef filename(temp_store.begin(), temp_store.size()), stem, ext; 141 StringRef filename(temp_store.begin(), temp_store.size()), stem, ext;
136 stem = path::stem(filename); 142 stem = path::stem(filename);
137 ext = path::extension(filename); 143 ext = path::extension(filename);
138 EXPECT_EQ(*(--sys::path::end(filename)), (stem + ext).str()); 144 EXPECT_EQ(*sys::path::rbegin(filename), (stem + ext).str());
139 145
140 path::native(*i, temp_store); 146 path::native(*i, temp_store);
141 } 147 }
142 } 148 }
143 149
208 EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str()); 214 EXPECT_EQ(ExpectedPathComponents[i].str(), ActualPathComponents[i].str());
209 } 215 }
210 } 216 }
211 #endif // LLVM_ON_WIN32 217 #endif // LLVM_ON_WIN32
212 218
219 TEST(Support, AbsolutePathIteratorEnd) {
220 // Trailing slashes are converted to '.' unless they are part of the root path.
221 SmallVector<StringRef, 4> Paths;
222 Paths.push_back("/foo/");
223 Paths.push_back("/foo//");
224 Paths.push_back("//net//");
225 #ifdef LLVM_ON_WIN32
226 Paths.push_back("c:\\\\");
227 #endif
228
229 for (StringRef Path : Paths) {
230 StringRef LastComponent = *path::rbegin(Path);
231 EXPECT_EQ(".", LastComponent);
232 }
233
234 SmallVector<StringRef, 3> RootPaths;
235 RootPaths.push_back("/");
236 RootPaths.push_back("//net/");
237 #ifdef LLVM_ON_WIN32
238 RootPaths.push_back("c:\\");
239 #endif
240
241 for (StringRef Path : RootPaths) {
242 StringRef LastComponent = *path::rbegin(Path);
243 EXPECT_EQ(1u, LastComponent.size());
244 EXPECT_TRUE(path::is_separator(LastComponent[0]));
245 }
246 }
247
248 TEST(Support, HomeDirectory) {
249 #ifdef LLVM_ON_UNIX
250 // This test only makes sense on Unix if $HOME is set.
251 if (::getenv("HOME")) {
252 #endif
253 SmallString<128> HomeDir;
254 EXPECT_TRUE(path::home_directory(HomeDir));
255 EXPECT_FALSE(HomeDir.empty());
256 #ifdef LLVM_ON_UNIX
257 }
258 #endif
259 }
260
213 class FileSystemTest : public testing::Test { 261 class FileSystemTest : public testing::Test {
214 protected: 262 protected:
215 /// Unique temporary directory in which all created filesystem entities must 263 /// Unique temporary directory in which all created filesystem entities must
216 /// be placed. It is recursively removed at the end of each test. 264 /// be placed. It is recursively removed at the end of each test.
217 SmallString<128> TestDirectory; 265 SmallString<128> TestDirectory;
223 errs() << "Test Directory: " << TestDirectory << '\n'; 271 errs() << "Test Directory: " << TestDirectory << '\n';
224 errs().flush(); 272 errs().flush();
225 } 273 }
226 274
227 virtual void TearDown() { 275 virtual void TearDown() {
228 uint32_t removed; 276 ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
229 ASSERT_NO_ERROR(fs::remove_all(TestDirectory.str(), removed));
230 } 277 }
231 }; 278 };
232 279
233 TEST_F(FileSystemTest, Unique) { 280 TEST_F(FileSystemTest, Unique) {
234 // Create a temp file. 281 // Create a temp file.
256 303
257 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2))); 304 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
258 305
259 // Two paths representing the same file on disk should still provide the 306 // Two paths representing the same file on disk should still provide the
260 // same unique id. We can test this by making a hard link. 307 // same unique id. We can test this by making a hard link.
261 ASSERT_NO_ERROR(fs::create_hard_link(Twine(TempPath), Twine(TempPath2))); 308 ASSERT_NO_ERROR(fs::create_link(Twine(TempPath), Twine(TempPath2)));
262 fs::UniqueID D2; 309 fs::UniqueID D2;
263 ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath2), D2)); 310 ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath2), D2));
264 ASSERT_EQ(D2, F1); 311 ASSERT_EQ(D2, F1);
265 312
266 ::close(FileDescriptor); 313 ::close(FileDescriptor);
304 EXPECT_FALSE(fs::equivalent(A, B)); 351 EXPECT_FALSE(fs::equivalent(A, B));
305 352
306 ::close(FD2); 353 ::close(FD2);
307 354
308 // Remove Temp2. 355 // Remove Temp2.
309 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists)); 356 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
310 EXPECT_TRUE(TempFileExists); 357 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
311 358 ASSERT_EQ(fs::remove(Twine(TempPath2), false),
312 error_code EC = fs::status(TempPath2.c_str(), B); 359 errc::no_such_file_or_directory);
360
361 std::error_code EC = fs::status(TempPath2.c_str(), B);
313 EXPECT_EQ(EC, errc::no_such_file_or_directory); 362 EXPECT_EQ(EC, errc::no_such_file_or_directory);
314 EXPECT_EQ(B.type(), fs::file_type::file_not_found); 363 EXPECT_EQ(B.type(), fs::file_type::file_not_found);
315 364
316 // Make sure Temp2 doesn't exist. 365 // Make sure Temp2 doesn't exist.
317 ASSERT_NO_ERROR(fs::exists(Twine(TempPath2), TempFileExists)); 366 ASSERT_NO_ERROR(fs::exists(Twine(TempPath2), TempFileExists));
320 SmallString<64> TempPath3; 369 SmallString<64> TempPath3;
321 ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "", TempPath3)); 370 ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "", TempPath3));
322 ASSERT_FALSE(TempPath3.endswith(".")); 371 ASSERT_FALSE(TempPath3.endswith("."));
323 372
324 // Create a hard link to Temp1. 373 // Create a hard link to Temp1.
325 ASSERT_NO_ERROR(fs::create_hard_link(Twine(TempPath), Twine(TempPath2))); 374 ASSERT_NO_ERROR(fs::create_link(Twine(TempPath), Twine(TempPath2)));
326 bool equal; 375 bool equal;
327 ASSERT_NO_ERROR(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal)); 376 ASSERT_NO_ERROR(fs::equivalent(Twine(TempPath), Twine(TempPath2), equal));
328 EXPECT_TRUE(equal); 377 EXPECT_TRUE(equal);
329 ASSERT_NO_ERROR(fs::status(Twine(TempPath), A)); 378 ASSERT_NO_ERROR(fs::status(Twine(TempPath), A));
330 ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B)); 379 ASSERT_NO_ERROR(fs::status(Twine(TempPath2), B));
331 EXPECT_TRUE(fs::equivalent(A, B)); 380 EXPECT_TRUE(fs::equivalent(A, B));
332 381
333 // Remove Temp1. 382 // Remove Temp1.
334 ::close(FileDescriptor); 383 ::close(FileDescriptor);
335 ASSERT_NO_ERROR(fs::remove(Twine(TempPath), TempFileExists)); 384 ASSERT_NO_ERROR(fs::remove(Twine(TempPath)));
336 EXPECT_TRUE(TempFileExists);
337 385
338 // Remove the hard link. 386 // Remove the hard link.
339 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists)); 387 ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
340 EXPECT_TRUE(TempFileExists);
341 388
342 // Make sure Temp1 doesn't exist. 389 // Make sure Temp1 doesn't exist.
343 ASSERT_NO_ERROR(fs::exists(Twine(TempPath), TempFileExists)); 390 ASSERT_NO_ERROR(fs::exists(Twine(TempPath), TempFileExists));
344 EXPECT_FALSE(TempFileExists); 391 EXPECT_FALSE(TempFileExists);
345 392
350 "abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz6" 397 "abcdefghijklmnopqrstuvwxyz7abcdefghijklmnopqrstuvwxyz6"
351 "abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz4" 398 "abcdefghijklmnopqrstuvwxyz5abcdefghijklmnopqrstuvwxyz4"
352 "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2" 399 "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2"
353 "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0"; 400 "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0";
354 EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath), 401 EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath),
355 windows_error::path_not_found); 402 errc::no_such_file_or_directory);
356 #endif 403 #endif
404 }
405
406 TEST_F(FileSystemTest, CreateDir) {
407 ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
408 ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
409 ASSERT_EQ(fs::create_directory(Twine(TestDirectory) + "foo", false),
410 errc::file_exists);
411 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo"));
357 } 412 }
358 413
359 TEST_F(FileSystemTest, DirectoryIteration) { 414 TEST_F(FileSystemTest, DirectoryIteration) {
360 error_code ec; 415 std::error_code ec;
361 for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec)) 416 for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec))
362 ASSERT_NO_ERROR(ec); 417 ASSERT_NO_ERROR(ec);
363 418
364 // Create a known hierarchy to recurse over. 419 // Create a known hierarchy to recurse over.
365 bool existed; 420 ASSERT_NO_ERROR(
366 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) 421 fs::create_directories(Twine(TestDirectory) + "/recursive/a0/aa1"));
367 + "/recursive/a0/aa1", existed)); 422 ASSERT_NO_ERROR(
368 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) 423 fs::create_directories(Twine(TestDirectory) + "/recursive/a0/ab1"));
369 + "/recursive/a0/ab1", existed)); 424 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) +
370 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) 425 "/recursive/dontlookhere/da1"));
371 + "/recursive/dontlookhere/da1", existed)); 426 ASSERT_NO_ERROR(
372 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) 427 fs::create_directories(Twine(TestDirectory) + "/recursive/z0/za1"));
373 + "/recursive/z0/za1", existed)); 428 ASSERT_NO_ERROR(
374 ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) 429 fs::create_directories(Twine(TestDirectory) + "/recursive/pop/p1"));
375 + "/recursive/pop/p1", existed));
376 typedef std::vector<std::string> v_t; 430 typedef std::vector<std::string> v_t;
377 v_t visited; 431 v_t visited;
378 for (fs::recursive_directory_iterator i(Twine(TestDirectory) 432 for (fs::recursive_directory_iterator i(Twine(TestDirectory)
379 + "/recursive", ec), e; i != e; i.increment(ec)){ 433 + "/recursive", ec), e; i != e; i.increment(ec)){
380 ASSERT_NO_ERROR(ec); 434 ASSERT_NO_ERROR(ec);
412 // Make sure that parents were visited before children. No other ordering 466 // Make sure that parents were visited before children. No other ordering
413 // guarantees can be made across siblings. 467 // guarantees can be made across siblings.
414 ASSERT_LT(a0, aa1); 468 ASSERT_LT(a0, aa1);
415 ASSERT_LT(a0, ab1); 469 ASSERT_LT(a0, ab1);
416 ASSERT_LT(z0, za1); 470 ASSERT_LT(z0, za1);
471
472 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/aa1"));
473 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0/ab1"));
474 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/a0"));
475 ASSERT_NO_ERROR(
476 fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere/da1"));
477 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/dontlookhere"));
478 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop/p1"));
479 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/pop"));
480 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0/za1"));
481 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive/z0"));
482 ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/recursive"));
417 } 483 }
418 484
419 const char archive[] = "!<arch>\x0A"; 485 const char archive[] = "!<arch>\x0A";
420 const char bitcode[] = "\xde\xc0\x17\x0b"; 486 const char bitcode[] = "\xde\xc0\x17\x0b";
421 const char coff_object[] = "\x00\x00......"; 487 const char coff_object[] = "\x00\x00......";
467 // Create some files filled with magic. 533 // Create some files filled with magic.
468 for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; 534 for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e;
469 ++i) { 535 ++i) {
470 SmallString<128> file_pathname(TestDirectory); 536 SmallString<128> file_pathname(TestDirectory);
471 path::append(file_pathname, i->filename); 537 path::append(file_pathname, i->filename);
472 std::string ErrMsg; 538 std::error_code EC;
473 raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_Binary); 539 raw_fd_ostream file(file_pathname, EC, sys::fs::F_None);
474 ASSERT_FALSE(file.has_error()); 540 ASSERT_FALSE(file.has_error());
475 StringRef magic(i->magic_str, i->magic_str_len); 541 StringRef magic(i->magic_str, i->magic_str_len);
476 file << magic; 542 file << magic;
477 file.close(); 543 file.close();
478 bool res = false;
479 ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res));
480 EXPECT_TRUE(res);
481 EXPECT_EQ(i->magic, fs::identify_magic(magic)); 544 EXPECT_EQ(i->magic, fs::identify_magic(magic));
545 ASSERT_NO_ERROR(fs::remove(Twine(file_pathname)));
482 } 546 }
483 } 547 }
484 548
485 #ifdef LLVM_ON_WIN32 549 #ifdef LLVM_ON_WIN32
486 TEST_F(FileSystemTest, CarriageReturn) { 550 TEST_F(FileSystemTest, CarriageReturn) {
487 SmallString<128> FilePathname(TestDirectory); 551 SmallString<128> FilePathname(TestDirectory);
488 std::string ErrMsg; 552 std::error_code EC;
489 path::append(FilePathname, "test"); 553 path::append(FilePathname, "test");
490 554
491 { 555 {
492 raw_fd_ostream File(FilePathname.c_str(), ErrMsg); 556 raw_fd_ostream File(FilePathname, EC, sys::fs::F_Text);
493 EXPECT_EQ(ErrMsg, ""); 557 ASSERT_NO_ERROR(EC);
494 File << '\n'; 558 File << '\n';
495 } 559 }
496 { 560 {
497 OwningPtr<MemoryBuffer> Buf; 561 auto Buf = MemoryBuffer::getFile(FilePathname.str());
498 MemoryBuffer::getFile(FilePathname.c_str(), Buf); 562 EXPECT_TRUE((bool)Buf);
499 EXPECT_EQ(Buf->getBuffer(), "\r\n"); 563 EXPECT_EQ(Buf.get()->getBuffer(), "\r\n");
500 } 564 }
501 565
502 { 566 {
503 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Binary); 567 raw_fd_ostream File(FilePathname, EC, sys::fs::F_None);
504 EXPECT_EQ(ErrMsg, ""); 568 ASSERT_NO_ERROR(EC);
505 File << '\n'; 569 File << '\n';
506 } 570 }
507 { 571 {
508 OwningPtr<MemoryBuffer> Buf; 572 auto Buf = MemoryBuffer::getFile(FilePathname.str());
509 MemoryBuffer::getFile(FilePathname.c_str(), Buf); 573 EXPECT_TRUE((bool)Buf);
510 EXPECT_EQ(Buf->getBuffer(), "\n"); 574 EXPECT_EQ(Buf.get()->getBuffer(), "\n");
511 } 575 }
576 ASSERT_NO_ERROR(fs::remove(Twine(FilePathname)));
512 } 577 }
513 #endif 578 #endif
514 579
515 TEST_F(FileSystemTest, FileMapping) { 580 TEST_F(FileSystemTest, FileMapping) {
516 // Create a temp file. 581 // Create a temp file.
517 int FileDescriptor; 582 int FileDescriptor;
518 SmallString<64> TempPath; 583 SmallString<64> TempPath;
519 ASSERT_NO_ERROR( 584 ASSERT_NO_ERROR(
520 fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); 585 fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
521 // Map in temp file and add some content 586 // Map in temp file and add some content
522 error_code EC; 587 std::error_code EC;
523 StringRef Val("hello there"); 588 StringRef Val("hello there");
524 { 589 {
525 fs::mapped_file_region mfr(FileDescriptor, 590 fs::mapped_file_region mfr(FileDescriptor,
526 true, 591 true,
527 fs::mapped_file_region::readwrite, 592 fs::mapped_file_region::readwrite,
546 // Verify content 611 // Verify content
547 EXPECT_EQ(StringRef(mfr.const_data()), Val); 612 EXPECT_EQ(StringRef(mfr.const_data()), Val);
548 613
549 // Unmap temp file 614 // Unmap temp file
550 615
551 #if LLVM_HAS_RVALUE_REFERENCES
552 fs::mapped_file_region m(Twine(TempPath), 616 fs::mapped_file_region m(Twine(TempPath),
553 fs::mapped_file_region::readonly, 617 fs::mapped_file_region::readonly,
554 0, 618 0,
555 0, 619 0,
556 EC); 620 EC);
557 ASSERT_NO_ERROR(EC); 621 ASSERT_NO_ERROR(EC);
558 const char *Data = m.const_data(); 622 const char *Data = m.const_data();
559 fs::mapped_file_region mfrrv(llvm_move(m)); 623 fs::mapped_file_region mfrrv(std::move(m));
560 EXPECT_EQ(mfrrv.const_data(), Data); 624 EXPECT_EQ(mfrrv.const_data(), Data);
561 #endif 625 }
626
627 TEST(Support, NormalizePath) {
628 #if defined(LLVM_ON_WIN32)
629 #define EXPECT_PATH_IS(path__, windows__, not_windows__) \
630 EXPECT_EQ(path__, windows__);
631 #else
632 #define EXPECT_PATH_IS(path__, windows__, not_windows__) \
633 EXPECT_EQ(path__, not_windows__);
634 #endif
635
636 SmallString<64> Path1("a");
637 SmallString<64> Path2("a/b");
638 SmallString<64> Path3("a\\b");
639 SmallString<64> Path4("a\\\\b");
640 SmallString<64> Path5("\\a");
641 SmallString<64> Path6("a\\");
642
643 path::native(Path1);
644 EXPECT_PATH_IS(Path1, "a", "a");
645
646 path::native(Path2);
647 EXPECT_PATH_IS(Path2, "a\\b", "a/b");
648
649 path::native(Path3);
650 EXPECT_PATH_IS(Path3, "a\\b", "a/b");
651
652 path::native(Path4);
653 EXPECT_PATH_IS(Path4, "a\\\\b", "a\\\\b");
654
655 path::native(Path5);
656 EXPECT_PATH_IS(Path5, "\\a", "/a");
657
658 path::native(Path6);
659 EXPECT_PATH_IS(Path6, "a\\", "a/");
660
661 #undef EXPECT_PATH_IS
562 } 662 }
563 } // anonymous namespace 663 } // anonymous namespace