[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
[llvm-project.git] / libcxx / test / std / input.output / filesystems / fs.op.funcs / fs.op.is_empty / is_empty.pass.cpp
blob647d2e6a255a95304476560c71ad216025302ed4
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 //===----------------------------------------------------------------------===//
9 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // UNSUPPORTED: availability-filesystem-missing
14 // Starting in Android N (API 24), SELinux policy prevents the shell user from
15 // creating a FIFO file.
16 // XFAIL: LIBCXX-ANDROID-FIXME && !android-device-api={{21|22|23}}
18 // <filesystem>
20 // bool is_empty(path const& p);
21 // bool is_empty(path const& p, std::error_code& ec);
23 #include <filesystem>
24 #include <type_traits>
25 #include <cassert>
27 #include "assert_macros.h"
28 #include "test_macros.h"
29 #include "filesystem_test_helper.h"
30 namespace fs = std::filesystem;
31 using namespace fs;
33 static void signature_test()
35 const path p; ((void)p);
36 std::error_code ec; ((void)ec);
37 ASSERT_NOT_NOEXCEPT(is_empty(p, ec));
38 ASSERT_NOT_NOEXCEPT(is_empty(p));
41 static void test_exist_not_found()
43 static_test_env static_env;
44 const path p = static_env.DNE;
45 std::error_code ec;
46 assert(is_empty(p, ec) == false);
47 assert(ec);
48 TEST_THROWS_TYPE(filesystem_error, is_empty(p));
51 static void test_is_empty_directory()
53 static_test_env static_env;
54 assert(!is_empty(static_env.Dir));
55 assert(!is_empty(static_env.SymlinkToDir));
58 static void test_is_empty_directory_dynamic()
60 scoped_test_env env;
61 assert(is_empty(env.test_root));
62 env.create_file("foo", 42);
63 assert(!is_empty(env.test_root));
66 static void test_is_empty_file()
68 static_test_env static_env;
69 assert(is_empty(static_env.EmptyFile));
70 assert(!is_empty(static_env.NonEmptyFile));
73 static void test_is_empty_fails()
75 scoped_test_env env;
76 #ifdef _WIN32
77 // Windows doesn't support setting perms::none to trigger failures
78 // reading directories; test using a special inaccessible directory
79 // instead.
80 const path p = GetWindowsInaccessibleDir();
81 if (p.empty())
82 return;
83 #else
84 const path dir = env.create_dir("dir");
85 const path p = env.create_dir("dir/dir2");
86 permissions(dir, perms::none);
87 #endif
89 std::error_code ec;
90 assert(is_empty(p, ec) == false);
91 assert(ec);
93 TEST_THROWS_TYPE(filesystem_error, is_empty(p));
96 static void test_directory_access_denied()
98 scoped_test_env env;
99 #ifdef _WIN32
100 // Windows doesn't support setting perms::none to trigger failures
101 // reading directories; test using a special inaccessible directory
102 // instead.
103 const path dir = GetWindowsInaccessibleDir();
104 if (dir.empty())
105 return;
106 #else
107 const path dir = env.create_dir("dir");
108 const path file1 = env.create_file("dir/file", 42);
109 permissions(dir, perms::none);
110 #endif
112 std::error_code ec = GetTestEC();
113 assert(is_empty(dir, ec) == false);
114 assert(ec);
115 assert(ec != GetTestEC());
117 TEST_THROWS_TYPE(filesystem_error, is_empty(dir));
121 #ifndef _WIN32
122 static void test_fifo_fails()
124 scoped_test_env env;
125 const path fifo = env.create_fifo("fifo");
127 std::error_code ec = GetTestEC();
128 assert(is_empty(fifo, ec) == false);
129 assert(ec);
130 assert(ec != GetTestEC());
132 TEST_THROWS_TYPE(filesystem_error, is_empty(fifo));
134 #endif // _WIN32
136 int main(int, char**) {
137 signature_test();
138 test_exist_not_found();
139 test_is_empty_directory();
140 test_is_empty_directory_dynamic();
141 test_is_empty_file();
142 test_is_empty_fails();
143 test_directory_access_denied();
144 #ifndef _WIN32
145 test_fifo_fails();
146 #endif
148 return 0;