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 //===----------------------------------------------------------------------===// 8 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 "utils/UnitTest/Test.h" 14 #include "utils/testutils/FDReader.h" 15 16 #include <errno.h> 17 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)); 26 } 27 28 TEST(LlvmLibcUnlinkTest, UnlinkNonExistentFile) { 29 using __llvm_libc::testing::ErrnoSetterMatcher::Fails; 30 ASSERT_THAT(__llvm_libc::unlink("testdata/non-existent-file"), Fails(ENOENT)); 31 } 32