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

source code of libc/test/src/sys/stat/mkdirat_test.cpp