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 // void create_hard_link(const path& existing_symlink, const path& new_symlink); 15 // void create_hard_link(const path& existing_symlink, const path& new_symlink, 16 // error_code& ec) noexcept; 17 18 #include <experimental/filesystem> 19 20 #include "test_macros.h" 21 #include "rapid-cxx-test.hpp" 22 #include "filesystem_test_helper.hpp" 23 24 using namespace std::experimental::filesystem; 25 namespace fs = std::experimental::filesystem; 26 27 TEST_SUITE(filesystem_create_hard_link_test_suite) 28 29 TEST_CASE(test_signatures) 30 { 31 const path p; ((void)p); 32 std::error_code ec; ((void)ec); 33 ASSERT_NOT_NOEXCEPT(fs::create_hard_link(p, p)); 34 ASSERT_NOEXCEPT(fs::create_hard_link(p, p, ec)); 35 } 36 37 TEST_CASE(test_error_reporting) 38 { 39 scoped_test_env env; 40 const path file = env.create_file("file1", 42); 41 const path file2 = env.create_file("file2", 55); 42 const path sym = env.create_symlink(file, "sym"); 43 { // destination exists 44 std::error_code ec; 45 fs::create_hard_link(sym, file2, ec); 46 TEST_REQUIRE(ec); 47 } 48 } 49 50 TEST_CASE(create_file_hard_link) 51 { 52 scoped_test_env env; 53 const path file = env.create_file("file"); 54 const path dest = env.make_env_path("dest1"); 55 std::error_code ec; 56 TEST_CHECK(hard_link_count(file) == 1); 57 fs::create_hard_link(file, dest, ec); 58 TEST_REQUIRE(!ec); 59 TEST_CHECK(exists(dest)); 60 TEST_CHECK(equivalent(dest, file)); 61 TEST_CHECK(hard_link_count(file) == 2); 62 } 63 64 TEST_CASE(create_directory_hard_link_fails) 65 { 66 scoped_test_env env; 67 const path dir = env.create_dir("dir"); 68 const path dest = env.make_env_path("dest2"); 69 std::error_code ec; 70 71 fs::create_hard_link(dir, dest, ec); 72 TEST_REQUIRE(ec); 73 } 74 75 TEST_SUITE_END() 76