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 //===----------------------------------------------------------------------===// 8 9 // FILE_DEPENDENCIES: ../../Inputs/static_test_env 10 // UNSUPPORTED: c++98, c++03 11 12 // <filesystem> 13 14 // bool is_empty(path const& p); 15 // bool is_empty(path const& p, std::error_code& ec); 16 17 #include "filesystem_include.h" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "rapid-cxx-test.h" 23 #include "filesystem_test_helper.h" 24 25 using namespace fs; 26 27 TEST_SUITE(is_empty_test_suite) 28 29 TEST_CASE(signature_test) 30 { 31 const path p; ((void)p); 32 std::error_code ec; ((void)ec); 33 ASSERT_NOT_NOEXCEPT(is_empty(p, ec)); 34 ASSERT_NOT_NOEXCEPT(is_empty(p)); 35 } 36 37 TEST_CASE(test_exist_not_found) 38 { 39 const path p = StaticEnv::DNE; 40 std::error_code ec; 41 TEST_CHECK(is_empty(p, ec) == false); 42 TEST_CHECK(ec); 43 TEST_CHECK_THROW(filesystem_error, is_empty(p)); 44 } 45 46 TEST_CASE(test_is_empty_directory) 47 { 48 static_test_env static_env; 49 TEST_CHECK(!is_empty(StaticEnv::Dir)); 50 TEST_CHECK(!is_empty(StaticEnv::SymlinkToDir)); 51 } 52 53 TEST_CASE(test_is_empty_directory_dynamic) 54 { 55 scoped_test_env env; 56 TEST_CHECK(is_empty(env.test_root)); 57 env.create_file("foo", 42); 58 TEST_CHECK(!is_empty(env.test_root)); 59 } 60 61 TEST_CASE(test_is_empty_file) 62 { 63 TEST_CHECK(is_empty(StaticEnv::EmptyFile)); 64 TEST_CHECK(!is_empty(StaticEnv::NonEmptyFile)); 65 } 66 67 TEST_CASE(test_is_empty_fails) 68 { 69 scoped_test_env env; 70 const path dir = env.create_dir("dir"); 71 const path dir2 = env.create_dir("dir/dir2"); 72 permissions(dir, perms::none); 73 74 std::error_code ec; 75 TEST_CHECK(is_empty(dir2, ec) == false); 76 TEST_CHECK(ec); 77 78 TEST_CHECK_THROW(filesystem_error, is_empty(dir2)); 79 } 80 81 TEST_CASE(test_directory_access_denied) 82 { 83 scoped_test_env env; 84 const path dir = env.create_dir("dir"); 85 const path file1 = env.create_file("dir/file", 42); 86 permissions(dir, perms::none); 87 88 std::error_code ec = GetTestEC(); 89 TEST_CHECK(is_empty(dir, ec) == false); 90 TEST_CHECK(ec); 91 TEST_CHECK(ec != GetTestEC()); 92 93 TEST_CHECK_THROW(filesystem_error, is_empty(dir)); 94 } 95 96 97 TEST_CASE(test_fifo_fails) 98 { 99 scoped_test_env env; 100 const path fifo = env.create_fifo("fifo"); 101 102 std::error_code ec = GetTestEC(); 103 TEST_CHECK(is_empty(fifo, ec) == false); 104 TEST_CHECK(ec); 105 TEST_CHECK(ec != GetTestEC()); 106 107 TEST_CHECK_THROW(filesystem_error, is_empty(fifo)); 108 } 109 110 TEST_SUITE_END() 111