Michael J. Spencer | 013d15a | 2010-11-29 22:29:04 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/Path.cpp - Path tests ------------------------===// |
Michael J. Spencer | f2ca4cb | 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 | |
Michael J. Spencer | 3cb84ef | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 10 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 11 | #include "llvm/Support/PathV2.h" |
Michael J. Spencer | 861ef4b | 2010-11-24 19:20:28 +0000 | [diff] [blame] | 12 | |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 13 | #include "gtest/gtest.h" |
| 14 | |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 15 | using namespace llvm; |
Michael J. Spencer | 3cb84ef | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 16 | using namespace llvm::sys; |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 17 | |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 18 | namespace { |
| 19 | |
Michael J. Spencer | 013d15a | 2010-11-29 22:29:04 +0000 | [diff] [blame] | 20 | TEST(Support, Path) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 21 | SmallVector<StringRef, 40> paths; |
| 22 | paths.push_back(""); |
| 23 | paths.push_back("."); |
| 24 | paths.push_back(".."); |
| 25 | paths.push_back("foo"); |
| 26 | paths.push_back("/"); |
| 27 | paths.push_back("/foo"); |
| 28 | paths.push_back("foo/"); |
| 29 | paths.push_back("/foo/"); |
| 30 | paths.push_back("foo/bar"); |
| 31 | paths.push_back("/foo/bar"); |
| 32 | paths.push_back("//net"); |
| 33 | paths.push_back("//net/foo"); |
| 34 | paths.push_back("///foo///"); |
| 35 | paths.push_back("///foo///bar"); |
| 36 | paths.push_back("/."); |
| 37 | paths.push_back("./"); |
| 38 | paths.push_back("/.."); |
| 39 | paths.push_back("../"); |
| 40 | paths.push_back("foo/."); |
| 41 | paths.push_back("foo/.."); |
| 42 | paths.push_back("foo/./"); |
| 43 | paths.push_back("foo/./bar"); |
| 44 | paths.push_back("foo/.."); |
| 45 | paths.push_back("foo/../"); |
| 46 | paths.push_back("foo/../bar"); |
| 47 | paths.push_back("c:"); |
| 48 | paths.push_back("c:/"); |
| 49 | paths.push_back("c:foo"); |
| 50 | paths.push_back("c:/foo"); |
| 51 | paths.push_back("c:foo/"); |
| 52 | paths.push_back("c:/foo/"); |
| 53 | paths.push_back("c:/foo/bar"); |
| 54 | paths.push_back("prn:"); |
| 55 | paths.push_back("c:\\"); |
| 56 | paths.push_back("c:foo"); |
| 57 | paths.push_back("c:\\foo"); |
| 58 | paths.push_back("c:foo\\"); |
| 59 | paths.push_back("c:\\foo\\"); |
| 60 | paths.push_back("c:\\foo/"); |
| 61 | paths.push_back("c:/foo\\bar"); |
| 62 | |
| 63 | for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(), |
| 64 | e = paths.end(); |
| 65 | i != e; |
| 66 | ++i) { |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 67 | for (sys::path::const_iterator ci = sys::path::begin(*i), |
| 68 | ce = sys::path::end(*i); |
| 69 | ci != ce; |
| 70 | ++ci) { |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 71 | ASSERT_FALSE(ci->empty()); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 72 | } |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 73 | |
Michael J. Spencer | 506e579 | 2010-12-01 22:28:42 +0000 | [diff] [blame] | 74 | #if 0 // Valgrind is whining about this. |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 75 | outs() << " Reverse Iteration: ["; |
| 76 | for (sys::path::reverse_iterator ci = sys::path::rbegin(*i), |
| 77 | ce = sys::path::rend(*i); |
| 78 | ci != ce; |
| 79 | ++ci) { |
| 80 | outs() << *ci << ','; |
| 81 | } |
| 82 | outs() << "]\n"; |
Michael J. Spencer | 506e579 | 2010-12-01 22:28:42 +0000 | [diff] [blame] | 83 | #endif |
Michael J. Spencer | a42cf73 | 2010-11-30 23:28:07 +0000 | [diff] [blame] | 84 | |
Michael J. Spencer | ae18008 | 2010-12-01 06:03:50 +0000 | [diff] [blame] | 85 | bool bres; |
Michael J. Spencer | 1d38962 | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 86 | StringRef sfres; |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 87 | ASSERT_FALSE(path::has_root_path(*i, bres)); |
| 88 | ASSERT_FALSE(path::root_path(*i, sfres)); |
| 89 | ASSERT_FALSE(path::has_root_name(*i, bres)); |
| 90 | ASSERT_FALSE(path::root_name(*i, sfres)); |
| 91 | ASSERT_FALSE(path::has_root_directory(*i, bres)); |
| 92 | ASSERT_FALSE(path::root_directory(*i, sfres)); |
| 93 | ASSERT_FALSE(path::has_parent_path(*i, bres)); |
| 94 | ASSERT_FALSE(path::parent_path(*i, sfres)); |
| 95 | ASSERT_FALSE(path::has_filename(*i, bres)); |
| 96 | ASSERT_FALSE(path::filename(*i, sfres)); |
| 97 | ASSERT_FALSE(path::has_stem(*i, bres)); |
| 98 | ASSERT_FALSE(path::stem(*i, sfres)); |
| 99 | ASSERT_FALSE(path::has_extension(*i, bres)); |
| 100 | ASSERT_FALSE(path::extension(*i, sfres)); |
| 101 | ASSERT_FALSE(path::is_absolute(*i, bres)); |
| 102 | ASSERT_FALSE(path::is_relative(*i, bres)); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 103 | |
Michael J. Spencer | 1d38962 | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 104 | SmallString<16> temp_store; |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 105 | temp_store = *i; |
| 106 | ASSERT_FALSE(path::make_absolute(temp_store)); |
| 107 | temp_store = *i; |
| 108 | ASSERT_FALSE(path::remove_filename(temp_store)); |
Michael J. Spencer | 1d38962 | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 109 | |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 110 | temp_store = *i; |
| 111 | ASSERT_FALSE(path::replace_extension(temp_store, "ext")); |
Michael J. Spencer | 1d38962 | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 112 | StringRef filename(temp_store.begin(), temp_store.size()), stem, ext; |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 113 | ASSERT_FALSE(path::stem(filename, stem)); |
| 114 | ASSERT_FALSE(path::extension(filename, ext)); |
Michael J. Spencer | 1d38962 | 2010-12-01 06:03:33 +0000 | [diff] [blame] | 115 | EXPECT_EQ(*(--sys::path::end(filename)), (stem + ext).str()); |
| 116 | |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 117 | ASSERT_FALSE(path::native(*i, temp_store)); |
Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 118 | |
| 119 | outs().flush(); |
| 120 | } |
Michael J. Spencer | 3cb84ef | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 121 | |
| 122 | int FileDescriptor; |
| 123 | SmallString<64> TempPath; |
Michael J. Spencer | 371716c | 2010-12-03 02:22:34 +0000 | [diff] [blame] | 124 | ASSERT_FALSE(fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); |
Michael J. Spencer | 3cb84ef | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 125 | |
| 126 | bool TempFileExists; |
| 127 | ASSERT_FALSE(sys::fs::exists(Twine(TempPath), TempFileExists)); |
| 128 | EXPECT_TRUE(TempFileExists); |
| 129 | |
| 130 | ::close(FileDescriptor); |
Benjamin Kramer | 6d6d16a | 2010-12-03 12:33:32 +0000 | [diff] [blame^] | 131 | ::remove(TempPath.c_str()); |
Michael J. Spencer | 3cb84ef | 2010-12-03 01:21:28 +0000 | [diff] [blame] | 132 | |
| 133 | ASSERT_FALSE(fs::exists(Twine(TempPath), TempFileExists)); |
Benjamin Kramer | 6d6d16a | 2010-12-03 12:33:32 +0000 | [diff] [blame^] | 134 | EXPECT_FALSE(TempFileExists); |
Michael J. Spencer | f2ca4cb | 2010-11-24 19:20:05 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | } // anonymous namespace |