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