[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / unistd / unlink_test.cpp
blobd8588a5a7d744945bda4dd794cd04bf0a5bf17f0
1 //===-- Unittests for unlink ----------------------------------------------===//
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/unistd/close.h"
11 #include "src/unistd/unlink.h"
12 #include "test/ErrnoSetterMatcher.h"
13 #include "test/UnitTest/Test.h"
14 #include "utils/testutils/FDReader.h"
16 #include <errno.h>
18 TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {
19 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
20 constexpr const char *TEST_FILE = "testdata/unlink.test";
21 int write_fd = __llvm_libc::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
22 ASSERT_EQ(errno, 0);
23 ASSERT_GT(write_fd, 0);
24 ASSERT_THAT(__llvm_libc::close(write_fd), Succeeds(0));
25 ASSERT_THAT(__llvm_libc::unlink(TEST_FILE), Succeeds(0));
28 TEST(LlvmLibcUnlinkTest, UnlinkNonExistentFile) {
29 using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
30 ASSERT_THAT(__llvm_libc::unlink("testdata/non-existent-file"), Fails(ENOENT));