]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/is_empty.cc
libstdc++: Skip filesystem tests that depend on permissions [PR90787]
[gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / is_empty.cc
CommitLineData
99dee823 1// Copyright (C) 2016-2021 Free Software Foundation, Inc.
ec04aad7
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
ef0e80d2 18// { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
1c433842 19// { dg-do run { target c++11 } }
ec04aad7
JW
20// { dg-require-filesystem-ts "" }
21
22#include <experimental/filesystem>
23#include <testsuite_hooks.h>
24#include <testsuite_fs.h>
25
26namespace fs = std::experimental::filesystem;
27
28void
29test01()
30{
cec047ea
JW
31 if (!__gnu_test::permissions_are_testable())
32 return;
edfe833a 33
ec04aad7
JW
34 auto p = __gnu_test::nonexistent_path();
35 create_directory(p);
36 permissions(p, fs::perms::none);
37 std::error_code ec, ec2;
38
39 bool result = fs::is_empty(p, ec);
40 VERIFY( ec == std::make_error_code(std::errc::permission_denied) );
41 VERIFY( !result );
42
43 try {
44 fs::is_empty(p);
45 } catch (const fs::filesystem_error& e) {
46 ec2 = e.code();
47 }
48 VERIFY( ec2 == ec );
49
50 result = fs::is_empty(p/"f", ec);
51 VERIFY( ec == std::make_error_code(std::errc::permission_denied) );
52 VERIFY( !result );
53
54 try {
55 fs::is_empty(p/"f");
56 } catch (const fs::filesystem_error& e) {
57 ec2 = e.code();
58 }
59 VERIFY( ec2 == ec );
60
61 permissions(p, fs::perms::owner_all, ec);
62 remove_all(p, ec);
63}
64
65void
66test02()
67{
68 auto p = __gnu_test::nonexistent_path();
69 create_directory(p);
70 std::error_code ec, bad_ec = make_error_code(std::errc::invalid_argument);
71 bool empty;
72
73 ec = bad_ec;
74 empty = is_empty(p, ec);
75 VERIFY( !ec );
76 VERIFY( empty );
77 empty = is_empty(p);
78 VERIFY( empty );
79
80 __gnu_test::scoped_file f(p/"f");
81 ec = bad_ec;
82 empty = is_empty(f.path, ec);
83 VERIFY( !ec );
84 VERIFY( empty );
85 empty = is_empty(f.path);
86 VERIFY( empty );
87
9534a5e6 88 std::ofstream{f.path.c_str()} << "data";
ec04aad7
JW
89 ec = bad_ec;
90 empty = is_empty(p, ec);
91 VERIFY( !ec );
92 VERIFY( !empty );
93 empty = is_empty(p);
94 VERIFY( !empty );
95
96 ec = bad_ec;
97 empty = is_empty(p, ec);
98 VERIFY( !ec );
99 VERIFY( !empty );
100 empty = is_empty(p);
101 VERIFY( !empty );
102
103 f.path.clear();
104 remove_all(p, ec);
105}
106
107int
108main()
109{
110 test01();
111 test02();
112}
This page took 0.597766 seconds and 5 git commands to generate.