Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / fcntl / creat_test.cpp
blobca926b30e62faf72134abfaf973d372765fafe3b
1 //===-- Unittest for creat ------------------------------------------------===//
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/errno/libc_errno.h"
10 #include "src/fcntl/creat.h"
11 #include "src/fcntl/open.h"
12 #include "src/unistd/close.h"
13 #include "test/UnitTest/ErrnoSetterMatcher.h"
14 #include "test/UnitTest/Test.h"
16 TEST(LlvmLibcCreatTest, CreatAndOpen) {
17 using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
18 constexpr const char *TEST_FILE = "testdata/creat.test";
19 int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);
20 ASSERT_EQ(libc_errno, 0);
21 ASSERT_GT(fd, 0);
22 ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
24 fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
25 ASSERT_EQ(libc_errno, 0);
26 ASSERT_GT(fd, 0);
27 ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
29 // TODO: 'remove' the test file at the end.