[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / stdio / remove_test.cpp
blob4295046b0df26b682a7b14e3cf8d36d1edc32f9f
1 //===-- Unittests for remove ----------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "src/fcntl/open.h"
10 #include "src/stdio/remove.h"
11 #include "src/sys/stat/mkdirat.h"
12 #include "src/unistd/access.h"
13 #include "src/unistd/close.h"
14 #include "test/ErrnoSetterMatcher.h"
15 #include "test/UnitTest/Test.h"
16 #include "utils/testutils/FDReader.h"
18 #include <errno.h>
19 #include <unistd.h>
21 TEST(LlvmLibcRemoveTest, CreateAndRemoveFile) {
22 // The test strategy is to create a file and remove it, and also verify that
23 // it was removed.
24 errno = 0;
25 using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
26 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
27 constexpr const char *TEST_FILE = "testdata/remove.test.file";
28 int fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
29 ASSERT_EQ(errno, 0);
30 ASSERT_GT(fd, 0);
31 ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
33 ASSERT_THAT(__llvm_libc::access(TEST_FILE, F_OK), Succeeds(0));
34 ASSERT_THAT(__llvm_libc::remove(TEST_FILE), Succeeds(0));
35 ASSERT_THAT(__llvm_libc::access(TEST_FILE, F_OK), Fails(ENOENT));
38 TEST(LlvmLibcRemoveTest, CreateAndRemoveDir) {
39 // The test strategy is to create a dir and remove it, and also verify that
40 // it was removed.
41 errno = 0;
42 using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
43 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
44 constexpr const char *TEST_DIR = "testdata/remove.test.dir";
45 ASSERT_THAT(__llvm_libc::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU), Succeeds(0));
47 ASSERT_THAT(__llvm_libc::access(TEST_DIR, F_OK), Succeeds(0));
48 ASSERT_THAT(__llvm_libc::remove(TEST_DIR), Succeeds(0));
49 ASSERT_THAT(__llvm_libc::access(TEST_DIR, F_OK), Fails(ENOENT));
52 TEST(LlvmLibcRemoveTest, RemoveNonExistent) {
53 using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
54 ASSERT_THAT(__llvm_libc::remove("testdata/non-existent"), Fails(ENOENT));