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