]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/filesystem/operations/exists.cc
1 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
19 // { dg-do run { target c++11 } }
20 // { dg-require-filesystem-ts "" }
22 #include <experimental/filesystem>
23 #include <testsuite_hooks.h>
24 #include <testsuite_fs.h>
26 using std::experimental::filesystem::path
;
31 const path root
= __gnu_test::root_path();
33 VERIFY( exists(root
) );
34 VERIFY( exists(root
/".") );
35 VERIFY( exists(path
{"."}) );
36 VERIFY( exists(path
{".."}) );
37 VERIFY( exists(std::experimental::filesystem::current_path()) );
39 std::error_code ec
= std::make_error_code(std::errc::invalid_argument
);
40 VERIFY( exists(root
, ec
) );
42 VERIFY( exists(root
/".", ec
) );
44 VERIFY( exists(path
{"."}, ec
) );
46 VERIFY( exists(path
{".."}, ec
) );
48 VERIFY( exists(std::experimental::filesystem::current_path(), ec
) );
55 path rel
= __gnu_test::nonexistent_path();
56 VERIFY( !exists(rel
) );
58 std::error_code ec
= std::make_error_code(std::errc::invalid_argument
);
59 VERIFY( !exists(rel
, ec
) );
60 VERIFY( !ec
); // DR 2725
66 path abs
= absolute(__gnu_test::nonexistent_path());
67 VERIFY( !exists(abs
) );
69 std::error_code ec
= std::make_error_code(std::errc::invalid_argument
);
70 VERIFY( !exists(abs
, ec
) );
71 VERIFY( !ec
); // DR 2725
77 using perms
= std::experimental::filesystem::perms
;
78 path p
= __gnu_test::nonexistent_path();
80 permissions(p
, perms::all
| perms::remove_perms
);
82 auto unr
= p
/ "unreachable";
84 VERIFY( !exists(unr
, ec
) );
85 VERIFY( ec
== std::errc::permission_denied
);
91 catch(const std::experimental::filesystem::filesystem_error
& ex
)
94 VERIFY( ex
.path1() == unr
);
96 VERIFY( ec
== std::errc::permission_denied
);
98 permissions(p
, perms::owner_all
);