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 // class directory_entry 14 15 // directory_entry(const directory_entry&) = default; 16 17 #include "filesystem_include.h" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "rapid-cxx-test.h" 23 #include "filesystem_test_helper.h" 24 #include "test_convertible.h" 25 26 TEST_SUITE(directory_entry_path_ctor_suite) 27 TEST_CASE(copy_ctor)28TEST_CASE(copy_ctor) { 29 using namespace fs; 30 // Copy 31 { 32 static_assert(std::is_copy_constructible<directory_entry>::value, 33 "directory_entry must be copy constructible"); 34 static_assert(!std::is_nothrow_copy_constructible<directory_entry>::value, 35 "directory_entry's copy constructor cannot be noexcept"); 36 const path p("foo/bar/baz"); 37 const directory_entry e(p); 38 assert(e.path() == p); 39 directory_entry e2(e); 40 assert(e.path() == p); 41 assert(e2.path() == p); 42 } 43 } 44 TEST_CASE(copy_ctor_copies_cache)45TEST_CASE(copy_ctor_copies_cache) { 46 using namespace fs; 47 scoped_test_env env; 48 const path dir = env.create_dir("dir"); 49 const path file = env.create_file("dir/file", 42); 50 const path sym = env.create_symlink("dir/file", "sym"); 51 52 { 53 directory_entry ent(sym); 54 55 fs::remove(sym); 56 57 directory_entry ent_cp(ent); 58 TEST_CHECK(ent_cp.path() == sym); 59 TEST_CHECK(ent_cp.is_symlink()); 60 } 61 62 { 63 directory_entry ent(file); 64 65 fs::remove(file); 66 67 directory_entry ent_cp(ent); 68 TEST_CHECK(ent_cp.path() == file); 69 TEST_CHECK(ent_cp.is_regular_file()); 70 } 71 } 72 73 TEST_SUITE_END() 74