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/ErrnoSetterMatcher.h"
12 #include "utils/UnitTest/Test.h"
13 #include "utils/testutils/FDReader.h"
14 
15 #include <errno.h>
16 #include <fcntl.h>
17 
TEST(LlvmLibcRmdirTest,CreateAndRemove)18 TEST(LlvmLibcRmdirTest, CreateAndRemove) {
19   using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
20   constexpr const char *TEST_DIR = "testdata/rmdir.testdir";
21   ASSERT_THAT(__llvm_libc::mkdir(TEST_DIR, S_IRWXU), Succeeds(0));
22   ASSERT_THAT(__llvm_libc::rmdir(TEST_DIR), Succeeds(0));
23 }
24 
TEST(LlvmLibcRmdirTest,RemoveNonExistentDir)25 TEST(LlvmLibcRmdirTest, RemoveNonExistentDir) {
26   using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
27   ASSERT_THAT(__llvm_libc::rmdir("testdata/non-existent-dir"), Fails(ENOENT));
28 }
29