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 // <filesystem> 12 13 // path current_path(); 14 // path current_path(error_code& ec); 15 // void current_path(path const&); 16 // void current_path(path const&, std::error_code& ec) noexcept; 17 18 #include "filesystem_include.h" 19 #include <type_traits> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "rapid-cxx-test.h" 24 #include "filesystem_test_helper.h" 25 26 using namespace fs; 27 28 TEST_SUITE(filesystem_current_path_path_test_suite) 29 TEST_CASE(current_path_signature_test)30TEST_CASE(current_path_signature_test) 31 { 32 const path p; ((void)p); 33 std::error_code ec; ((void)ec); 34 ASSERT_NOT_NOEXCEPT(current_path()); 35 ASSERT_NOT_NOEXCEPT(current_path(ec)); 36 ASSERT_NOT_NOEXCEPT(current_path(p)); 37 ASSERT_NOEXCEPT(current_path(p, ec)); 38 } 39 TEST_CASE(current_path_test)40TEST_CASE(current_path_test) 41 { 42 std::error_code ec; 43 const path p = current_path(ec); 44 TEST_REQUIRE(!ec); 45 TEST_CHECK(p.is_absolute()); 46 TEST_CHECK(is_directory(p)); 47 48 const path p2 = current_path(); 49 TEST_CHECK(p2 == p); 50 } 51 TEST_CASE(current_path_after_change_test)52TEST_CASE(current_path_after_change_test) 53 { 54 static_test_env static_env; 55 CWDGuard guard; 56 const path new_path = static_env.Dir; 57 current_path(new_path); 58 TEST_CHECK(current_path() == new_path); 59 } 60 TEST_CASE(current_path_is_file_test)61TEST_CASE(current_path_is_file_test) 62 { 63 static_test_env static_env; 64 CWDGuard guard; 65 const path p = static_env.File; 66 std::error_code ec; 67 const path old_p = current_path(); 68 current_path(p, ec); 69 TEST_CHECK(ec); 70 TEST_CHECK(old_p == current_path()); 71 } 72 TEST_CASE(set_to_non_absolute_path)73TEST_CASE(set_to_non_absolute_path) 74 { 75 static_test_env static_env; 76 CWDGuard guard; 77 const path base = static_env.Dir; 78 current_path(base); 79 const path p = static_env.Dir2.filename(); 80 std::error_code ec; 81 current_path(p, ec); 82 TEST_CHECK(!ec); 83 const path new_cwd = current_path(); 84 TEST_CHECK(new_cwd == static_env.Dir2); 85 TEST_CHECK(new_cwd.is_absolute()); 86 } 87 TEST_CASE(set_to_empty)88TEST_CASE(set_to_empty) 89 { 90 const path p = ""; 91 std::error_code ec; 92 const path old_p = current_path(); 93 current_path(p, ec); 94 TEST_CHECK(ec); 95 TEST_CHECK(old_p == current_path()); 96 } 97 98 TEST_SUITE_END() 99