1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03 10 11 // XFAIL: LIBCXX-AIX-FIXME 12 13 // <filesystem> 14 15 // path current_path(); 16 // path current_path(error_code& ec); 17 // void current_path(path const&); 18 // void current_path(path const&, std::error_code& ec) noexcept; 19 20 #include "filesystem_include.h" 21 #include <type_traits> 22 #include <cassert> 23 24 #include "test_macros.h" 25 #include "rapid-cxx-test.h" 26 #include "filesystem_test_helper.h" 27 28 using namespace fs; 29 30 TEST_SUITE(filesystem_current_path_path_test_suite) 31 32 TEST_CASE(current_path_signature_test) 33 { 34 const path p; ((void)p); 35 std::error_code ec; ((void)ec); 36 ASSERT_NOT_NOEXCEPT(current_path()); 37 ASSERT_NOT_NOEXCEPT(current_path(ec)); 38 ASSERT_NOT_NOEXCEPT(current_path(p)); 39 ASSERT_NOEXCEPT(current_path(p, ec)); 40 } 41 42 TEST_CASE(current_path_test) 43 { 44 std::error_code ec; 45 const path p = current_path(ec); 46 TEST_REQUIRE(!ec); 47 TEST_CHECK(p.is_absolute()); 48 TEST_CHECK(is_directory(p)); 49 50 const path p2 = current_path(); 51 TEST_CHECK(p2 == p); 52 } 53 54 TEST_CASE(current_path_after_change_test) 55 { 56 static_test_env static_env; 57 CWDGuard guard; 58 const path new_path = static_env.Dir; 59 current_path(new_path); 60 TEST_CHECK(current_path() == new_path); 61 } 62 63 TEST_CASE(current_path_is_file_test) 64 { 65 static_test_env static_env; 66 CWDGuard guard; 67 const path p = static_env.File; 68 std::error_code ec; 69 const path old_p = current_path(); 70 current_path(p, ec); 71 TEST_CHECK(ec); 72 TEST_CHECK(old_p == current_path()); 73 } 74 75 TEST_CASE(set_to_non_absolute_path) 76 { 77 static_test_env static_env; 78 CWDGuard guard; 79 const path base = static_env.Dir; 80 current_path(base); 81 const path p = static_env.Dir2.filename(); 82 std::error_code ec; 83 current_path(p, ec); 84 TEST_CHECK(!ec); 85 const path new_cwd = current_path(); 86 TEST_CHECK(new_cwd == static_env.Dir2); 87 TEST_CHECK(new_cwd.is_absolute()); 88 } 89 90 TEST_CASE(set_to_empty) 91 { 92 const path p = ""; 93 std::error_code ec; 94 const path old_p = current_path(); 95 current_path(p, ec); 96 TEST_CHECK(ec); 97 TEST_CHECK(old_p == current_path()); 98 } 99 100 TEST_SUITE_END() 101