]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
b3063564ab4379f7bda4c2dddc0ebeecaa7df8ae
1 // Copyright (C) 2015-2022 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-do run { target c++17 } }
19 // { dg-require-filesystem-ts "" }
22 #include <testsuite_hooks.h>
23 #include <testsuite_fs.h>
25 using std::filesystem::path
;
30 const std::error_code bad_ec
= make_error_code(std::errc::invalid_argument
);
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::filesystem::current_path()) );
41 VERIFY( exists(root
, ec
) );
44 VERIFY( exists(root
/".", ec
) );
47 VERIFY( exists(path
{"."}, ec
) );
50 VERIFY( exists(path
{".."}, ec
) );
53 VERIFY( exists(std::filesystem::current_path(), ec
) );
60 path rel
= __gnu_test::nonexistent_path();
61 VERIFY( !exists(rel
) );
63 std::error_code ec
= std::make_error_code(std::errc::invalid_argument
);
64 VERIFY( !exists(rel
, ec
) );
65 VERIFY( !ec
); // DR 2725
71 path abs
= absolute(__gnu_test::nonexistent_path());
72 VERIFY( !exists(abs
) );
74 std::error_code ec
= std::make_error_code(std::errc::invalid_argument
);
75 VERIFY( !exists(abs
, ec
) );
76 VERIFY( !ec
); // DR 2725
82 if (!__gnu_test::permissions_are_testable())
85 using std::filesystem::perms
;
86 using std::filesystem::perm_options
;
87 path p
= __gnu_test::nonexistent_path();
89 permissions(p
, perms::all
, perm_options::remove
);
91 auto unr
= p
/ "unreachable";
93 VERIFY( !exists(unr
, ec
) );
94 VERIFY( ec
== std::errc::permission_denied
);
100 catch(const std::filesystem::filesystem_error
& ex
)
103 VERIFY( ex
.path1() == unr
);
105 VERIFY( ec
== std::errc::permission_denied
);
107 permissions(p
, perms::owner_all
);