Eric Fiselier | 1e34c76 | 2018-04-02 23:03:41 +0000 | [diff] [blame^] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
| 12 | // <experimental/filesystem> |
| 13 | |
| 14 | // path proximate(const path& p, error_code &ec) |
| 15 | // path proximate(const path& p, const path& base = current_path()) |
| 16 | // path proximate(const path& p, const path& base, error_code& ec); |
| 17 | |
| 18 | #include "filesystem_include.hpp" |
| 19 | #include <type_traits> |
| 20 | #include <vector> |
| 21 | #include <iostream> |
| 22 | #include <cassert> |
| 23 | |
| 24 | #include "test_macros.h" |
| 25 | #include "test_iterators.h" |
| 26 | #include "count_new.hpp" |
| 27 | #include "rapid-cxx-test.hpp" |
| 28 | #include "filesystem_test_helper.hpp" |
| 29 | |
| 30 | |
| 31 | TEST_SUITE(filesystem_proximate_path_test_suite) |
| 32 | |
| 33 | TEST_CASE(test_signature) { |
| 34 | |
| 35 | } |
| 36 | int main() { |
| 37 | // clang-format off |
| 38 | struct { |
| 39 | std::string input; |
| 40 | std::string expect; |
| 41 | } TestCases[] = { |
| 42 | {"", fs::current_path()}, |
| 43 | {".", fs::current_path()}, |
| 44 | {StaticEnv::File, StaticEnv::File}, |
| 45 | {StaticEnv::Dir, StaticEnv::Dir}, |
| 46 | {StaticEnv::SymlinkToDir, StaticEnv::Dir}, |
| 47 | {StaticEnv::SymlinkToDir / "dir2/.", StaticEnv::Dir / "dir2"}, |
| 48 | // FIXME? If the trailing separator occurs in a part of the path that exists, |
| 49 | // it is ommitted. Otherwise it is added to the end of the result. |
| 50 | {StaticEnv::SymlinkToDir / "dir2/./", StaticEnv::Dir / "dir2"}, |
| 51 | {StaticEnv::SymlinkToDir / "dir2/DNE/./", StaticEnv::Dir / "dir2/DNE/"}, |
| 52 | {StaticEnv::SymlinkToDir / "dir2", StaticEnv::Dir2}, |
| 53 | {StaticEnv::SymlinkToDir / "dir2/../dir2/DNE/..", StaticEnv::Dir2 / ""}, |
| 54 | {StaticEnv::SymlinkToDir / "dir2/dir3/../DNE/DNE2", StaticEnv::Dir2 / "DNE/DNE2"}, |
| 55 | {StaticEnv::Dir / "../dir1", StaticEnv::Dir}, |
| 56 | {StaticEnv::Dir / "./.", StaticEnv::Dir}, |
| 57 | {StaticEnv::Dir / "DNE/../foo", StaticEnv::Dir / "foo"} |
| 58 | }; |
| 59 | // clang-format on |
| 60 | int ID = 0; |
| 61 | bool Failed = false; |
| 62 | for (auto& TC : TestCases) { |
| 63 | ++ID; |
| 64 | fs::path p(TC.input); |
| 65 | const fs::path output = fs::weakly_canonical(p); |
| 66 | if (output != TC.expect) { |
| 67 | Failed = true; |
| 68 | std::cerr << "TEST CASE #" << ID << " FAILED: \n"; |
| 69 | std::cerr << " Input: '" << TC.input << "'\n"; |
| 70 | std::cerr << " Expected: '" << TC.expect << "'\n"; |
| 71 | std::cerr << " Output: '" << output.native() << "'"; |
| 72 | std::cerr << std::endl; |
| 73 | } |
| 74 | } |
| 75 | return Failed; |
| 76 | } |
| 77 | |
| 78 | TEST_SUITE_END() |