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