1 // { dg-options "-std=gnu++11 -lstdc++fs" }
2 // { dg-require-filesystem-ts "" }
4 // Copyright (C) 2014-2016 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 15.3 Copy [fs.op.copy]
23 #include <experimental/filesystem>
25 #include <testsuite_fs.h>
26 #include <testsuite_hooks.h>
28 namespace fs
= std::experimental::filesystem
;
30 // Test error conditions.
34 bool test
__attribute__((unused
)) = false;
36 auto p
= __gnu_test::nonexistent_path();
39 VERIFY( !fs::exists(p
) );
40 fs::copy(p
, ".", fs::copy_options::none
, ec
);
44 fs::copy(".", ".", fs::copy_options::none
, ec
);
47 std::ofstream
{p
.native()};
48 VERIFY( fs::is_directory(".") );
49 VERIFY( fs::is_regular_file(p
) );
51 fs::copy(".", p
, fs::copy_options::none
, ec
);
57 // Test is_symlink(f) case.
61 bool test
__attribute__((unused
)) = false;
63 auto from
= __gnu_test::nonexistent_path();
64 auto to
= __gnu_test::nonexistent_path();
67 fs::create_symlink(".", from
, ec
);
69 VERIFY( fs::exists(from
) );
71 fs::copy(from
, to
, fs::copy_options::skip_symlinks
, ec
);
73 VERIFY( !fs::exists(to
) );
75 fs::copy(from
, to
, fs::copy_options::skip_symlinks
, ec
);
77 VERIFY( !fs::exists(to
) );
80 fs::copy_options::skip_symlinks
|fs::copy_options::copy_symlinks
,
83 VERIFY( !fs::exists(to
) );
85 fs::copy(from
, to
, fs::copy_options::copy_symlinks
, ec
);
87 VERIFY( fs::exists(to
) );
89 fs::copy(from
, to
, fs::copy_options::copy_symlinks
, ec
);
96 // Test is_regular_file(f) case.
100 bool test
__attribute__((unused
)) = false;
102 auto from
= __gnu_test::nonexistent_path();
103 auto to
= __gnu_test::nonexistent_path();
106 std::ofstream
{from
.native()};
107 VERIFY( fs::exists(from
) );
108 VERIFY( fs::file_size(from
) == 0 );
110 VERIFY( fs::exists(to
) );
111 VERIFY( fs::file_size(to
) == 0 );
114 VERIFY( !fs::exists(to
) );
115 std::ofstream
{from
.native()} << "Hello, filesystem!";
116 VERIFY( fs::file_size(from
) != 0 );
118 VERIFY( fs::exists(to
) );
119 VERIFY( fs::file_size(to
) == fs::file_size(from
) );
122 // Test is_directory(f) case.
126 bool test
__attribute__((unused
)) = false;
128 auto from
= __gnu_test::nonexistent_path();
129 auto to
= __gnu_test::nonexistent_path();
138 bool test
__attribute__((unused
)) = false;
140 auto to
= __gnu_test::nonexistent_path();
143 fs::copy("/", to
, fs::copy_options::create_symlinks
, ec
);