1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: no-filesystem
12 // UNSUPPORTED: availability-filesystem-missing
16 // bool is_other(file_status s) noexcept
17 // bool is_other(path const& p);
18 // bool is_other(path const& p, std::error_code& ec) noexcept;
21 #include <type_traits>
24 #include "assert_macros.h"
25 #include "test_macros.h"
26 #include "filesystem_test_helper.h"
27 namespace fs
= std::filesystem
;
30 static void signature_test()
32 file_status s
; ((void)s
);
33 const path p
; ((void)p
);
34 std::error_code ec
; ((void)ec
);
35 ASSERT_NOEXCEPT(is_other(s
));
36 ASSERT_NOEXCEPT(is_other(p
, ec
));
37 ASSERT_NOT_NOEXCEPT(is_other(p
));
40 static void is_other_status_test()
46 const TestCase testCases
[] = {
47 {file_type::none
, false},
48 {file_type::not_found
, false},
49 {file_type::regular
, false},
50 {file_type::directory
, false},
51 {file_type::symlink
, false},
52 {file_type::block
, true},
53 {file_type::character
, true},
54 {file_type::fifo
, true},
55 {file_type::socket
, true},
56 {file_type::unknown
, true}
58 for (auto& TC
: testCases
) {
59 file_status
s(TC
.type
);
60 assert(is_other(s
) == TC
.expect
);
64 static void test_exist_not_found()
66 static_test_env static_env
;
67 const path p
= static_env
.DNE
;
68 assert(is_other(p
) == false);
71 static void test_is_other_fails()
75 // Windows doesn't support setting perms::none to trigger failures
76 // reading directories; test using a special inaccessible directory
78 const path p
= GetWindowsInaccessibleDir();
82 const path dir
= env
.create_dir("dir");
83 const path p
= env
.create_file("dir/file", 42);
84 permissions(dir
, perms::none
);
88 assert(is_other(p
, ec
) == false);
91 TEST_THROWS_TYPE(filesystem_error
, is_other(p
));
94 int main(int, char**) {
96 is_other_status_test();
97 test_exist_not_found();
98 test_is_other_fails();