libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

create_hard_link.pass.cpp (2053B)


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