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

source code of libc/test/src/unistd/rmdir_test.cpp