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// REQUIRES: can-create-symlinks
10// UNSUPPORTED: c++03, c++11, c++14
11
12// <filesystem>
13
14// class directory_entry
15
16// directory_entry& operator=(directory_entry const&) = default;
17// directory_entry& operator=(directory_entry&&) noexcept = default;
18// void assign(path const&);
19// void replace_filename(path const&);
20
21#include <filesystem>
22#include <type_traits>
23#include <cassert>
24
25#include "test_macros.h"
26#include "filesystem_test_helper.h"
27namespace fs = std::filesystem;
28
29static void test_move_assign_operator() {
30 using namespace fs;
31 // Copy
32 {
33 static_assert(std::is_nothrow_move_assignable<directory_entry>::value,
34 "directory_entry is noexcept move assignable");
35 const path p("foo/bar/baz");
36 const path p2("abc");
37 directory_entry e(p);
38 directory_entry e2(p2);
39 assert(e.path() == p && e2.path() == p2);
40 e2 = std::move(e);
41 assert(e2.path() == p);
42 assert(e.path() != p); // testing moved from state
43 }
44}
45
46static void move_assign_copies_cache() {
47 using namespace fs;
48 scoped_test_env env;
49 const path dir = env.create_dir("dir");
50 const path file = env.create_file("dir/file", 42);
51 const path sym = env.create_symlink("dir/file", "sym");
52
53 {
54 directory_entry ent(sym);
55
56 fs::remove(p: sym);
57
58 directory_entry ent_cp;
59 ent_cp = std::move(ent);
60 assert(ent_cp.path() == sym);
61 assert(ent_cp.is_symlink());
62 }
63
64 {
65 directory_entry ent(file);
66
67 fs::remove(p: file);
68
69 directory_entry ent_cp;
70 ent_cp = std::move(ent);
71 assert(ent_cp.path() == file);
72 assert(ent_cp.is_regular_file());
73 }
74}
75
76int main(int, char**) {
77 test_move_assign_operator();
78 move_assign_copies_cache();
79
80 return 0;
81}
82

source code of libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.cons/move_assign.pass.cpp