| 1 | //===-- Unittests for rmdir -----------------------------------------------===// |
| 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 | #include "src/sys/stat/mkdir.h" |
| 10 | #include "src/unistd/rmdir.h" |
| 11 | #include "test/UnitTest/ErrnoCheckingTest.h" |
| 12 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
| 13 | #include "test/UnitTest/Test.h" |
| 14 | |
| 15 | #include "hdr/fcntl_macros.h" |
| 16 | |
| 17 | using LlvmLibcRmdirTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
| 18 | |
| 19 | TEST_F(LlvmLibcRmdirTest, CreateAndRemove) { |
| 20 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; |
| 21 | constexpr const char *FILENAME = "rmdir.testdir" ; |
| 22 | auto TEST_DIR = libc_make_test_file_path(FILENAME); |
| 23 | ASSERT_THAT(LIBC_NAMESPACE::mkdir(TEST_DIR, S_IRWXU), Succeeds(0)); |
| 24 | ASSERT_THAT(LIBC_NAMESPACE::rmdir(TEST_DIR), Succeeds(0)); |
| 25 | } |
| 26 | |
| 27 | TEST_F(LlvmLibcRmdirTest, RemoveNonExistentDir) { |
| 28 | using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; |
| 29 | ASSERT_THAT(LIBC_NAMESPACE::rmdir("non-existent-dir" ), Fails(ENOENT)); |
| 30 | } |
| 31 | |