Skip to content

Commit 92a116c

Browse files
authored
Revert "Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest."" (#144129)
Reverts #143972 - matcher seems to be pedantic for fgets tests, reverting to verify and fix.
1 parent 9d49b82 commit 92a116c

13 files changed

+77
-84
lines changed

libc/test/src/stdio/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ add_libc_test(
2020
libc.src.stdio.fread
2121
libc.src.stdio.fseek
2222
libc.src.stdio.fwrite
23-
libc.test.UnitTest.ErrnoCheckingTest
2423
)
2524

2625
add_libc_test(
@@ -69,7 +68,6 @@ add_libc_test(
6968
libc.src.stdio.fread
7069
libc.src.stdio.fwrite
7170
libc.src.stdio.setvbuf
72-
libc.test.UnitTest.ErrnoCheckingTest
7371
)
7472

7573
add_libc_test(
@@ -90,7 +88,6 @@ add_libc_test(
9088
libc.src.stdio.fread_unlocked
9189
libc.src.stdio.funlockfile
9290
libc.src.stdio.fwrite_unlocked
93-
libc.test.UnitTest.ErrnoCheckingTest
9491
)
9592

9693
add_libc_test(
@@ -112,7 +109,6 @@ add_libc_test(
112109
libc.src.stdio.fread
113110
libc.src.stdio.fseek
114111
libc.src.stdio.fwrite
115-
libc.test.UnitTest.ErrnoCheckingTest
116112
LINK_LIBRARIES
117113
LibcMemoryHelpers
118114
)
@@ -442,7 +438,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
442438
libc.src.sys.stat.mkdirat
443439
libc.src.unistd.access
444440
libc.src.unistd.close
445-
libc.test.UnitTest.ErrnoCheckingTest
446441
)
447442

448443
add_libc_test(
@@ -457,7 +452,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
457452
libc.src.stdio.rename
458453
libc.src.unistd.access
459454
libc.src.unistd.close
460-
libc.test.UnitTest.ErrnoCheckingTest
461455
libc.test.UnitTest.ErrnoSetterMatcher
462456
)
463457

@@ -474,7 +468,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
474468
libc.src.stdio.fgets
475469
libc.src.stdio.fputs
476470
libc.src.unistd.close
477-
libc.test.UnitTest.ErrnoCheckingTest
478471
libc.test.UnitTest.ErrnoSetterMatcher
479472
)
480473
endif()
@@ -495,8 +488,6 @@ add_libc_test(
495488
libc.src.stdio.fopen
496489
libc.src.stdio.fwrite
497490
libc.src.stdio.getc
498-
libc.test.UnitTest.ErrnoCheckingTest
499-
libc.test.UnitTest.ErrnoSetterMatcher
500491
)
501492

502493
add_libc_test(
@@ -519,8 +510,6 @@ add_libc_test(
519510
libc.src.stdio.funlockfile
520511
libc.src.stdio.fwrite
521512
libc.src.stdio.getc_unlocked
522-
libc.test.UnitTest.ErrnoCheckingTest
523-
libc.test.UnitTest.ErrnoSetterMatcher
524513
)
525514

526515
add_libc_test(
@@ -538,8 +527,6 @@ add_libc_test(
538527
libc.src.stdio.fgets
539528
libc.src.stdio.fopen
540529
libc.src.stdio.fwrite
541-
libc.test.UnitTest.ErrnoCheckingTest
542-
libc.test.UnitTest.ErrnoSetterMatcher
543530
)
544531

545532
add_libc_test(

libc/test/src/stdio/fdopen_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
#include "src/stdio/fdopen.h"
1010

1111
#include "hdr/fcntl_macros.h"
12+
#include "src/__support/libc_errno.h"
1213
#include "src/fcntl/open.h"
1314
#include "src/stdio/fclose.h"
1415
#include "src/stdio/fgets.h"
1516
#include "src/stdio/fputs.h"
1617
#include "src/unistd/close.h"
17-
#include "test/UnitTest/ErrnoCheckingTest.h"
1818
#include "test/UnitTest/ErrnoSetterMatcher.h"
1919
#include "test/UnitTest/Test.h"
2020

2121
#include <sys/stat.h> // For S_IRWXU
2222

23-
using LlvmLibcStdioFdopenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
24-
25-
TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
23+
TEST(LlvmLibcStdioFdopenTest, WriteAppendRead) {
2624
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
25+
libc_errno = 0;
2726
constexpr const char *TEST_FILE_NAME = "testdata/write_read_append.test";
2827
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
2928
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
@@ -53,7 +52,8 @@ TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
5352
ASSERT_ERRNO_SUCCESS();
5453
}
5554

56-
TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
55+
TEST(LlvmLibcStdioFdopenTest, InvalidFd) {
56+
libc_errno = 0;
5757
constexpr const char *TEST_FILE_NAME = "testdata/invalid_fd.test";
5858
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
5959
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC);
@@ -64,7 +64,8 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
6464
ASSERT_TRUE(nullptr == fp);
6565
}
6666

67-
TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
67+
TEST(LlvmLibcStdioFdopenTest, InvalidMode) {
68+
libc_errno = 0;
6869
constexpr const char *TEST_FILE_NAME = "testdata/invalid_mode.test";
6970
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
7071
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_RDONLY, S_IRWXU);
@@ -82,6 +83,7 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
8283
auto *fp2 = LIBC_NAMESPACE::fdopen(fd, "w");
8384
ASSERT_ERRNO_EQ(EINVAL);
8485
ASSERT_TRUE(nullptr == fp2);
86+
libc_errno = 0;
8587
LIBC_NAMESPACE::close(fd);
8688
ASSERT_ERRNO_SUCCESS();
8789
}

libc/test/src/stdio/fgetc_test.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,42 @@
1414
#include "src/stdio/fopen.h"
1515
#include "src/stdio/fwrite.h"
1616
#include "src/stdio/getc.h"
17-
#include "test/UnitTest/ErrnoCheckingTest.h"
18-
#include "test/UnitTest/ErrnoSetterMatcher.h"
1917
#include "test/UnitTest/Test.h"
2018

2119
#include "hdr/stdio_macros.h"
20+
#include "src/__support/libc_errno.h"
2221

23-
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
24-
25-
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
22+
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
2623
public:
2724
using GetcFunc = int(FILE *);
2825
void test_with_func(GetcFunc *func, const char *filename) {
2926
::FILE *file = LIBC_NAMESPACE::fopen(filename, "w");
3027
ASSERT_FALSE(file == nullptr);
3128
constexpr char CONTENT[] = "123456789";
3229
constexpr size_t WRITE_SIZE = sizeof(CONTENT) - 1;
33-
ASSERT_THAT(LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file),
34-
Succeeds(WRITE_SIZE));
30+
ASSERT_EQ(WRITE_SIZE, LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file));
3531
// This is a write-only file so reads should fail.
36-
ASSERT_THAT(func(file), Fails(EBADF, EOF));
32+
ASSERT_EQ(func(file), EOF);
3733
// This is an error and not a real EOF.
3834
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
3935
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
36+
libc_errno = 0;
4037

41-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
38+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
4239

4340
file = LIBC_NAMESPACE::fopen(filename, "r");
4441
ASSERT_FALSE(file == nullptr);
4542

4643
for (size_t i = 0; i < WRITE_SIZE; ++i) {
47-
ASSERT_THAT(func(file), Succeeds(int('1' + i)));
44+
int c = func(file);
45+
ASSERT_EQ(c, int('1' + i));
4846
}
4947
// Reading more should return EOF but not set error.
50-
ASSERT_THAT(func(file), Succeeds(EOF));
48+
ASSERT_EQ(func(file), EOF);
5149
ASSERT_NE(LIBC_NAMESPACE::feof(file), 0);
5250
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
5351

54-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
52+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
5553
}
5654
};
5755

libc/test/src/stdio/fgetc_unlocked_test.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,44 @@
1717
#include "src/stdio/funlockfile.h"
1818
#include "src/stdio/fwrite.h"
1919
#include "src/stdio/getc_unlocked.h"
20-
#include "test/UnitTest/ErrnoCheckingTest.h"
21-
#include "test/UnitTest/ErrnoSetterMatcher.h"
2220
#include "test/UnitTest/Test.h"
2321

2422
#include "hdr/stdio_macros.h"
23+
#include "src/__support/libc_errno.h"
2524

26-
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
27-
28-
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
25+
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
2926
public:
3027
using GetcFunc = int(FILE *);
3128
void test_with_func(GetcFunc *func, const char *filename) {
3229
::FILE *file = LIBC_NAMESPACE::fopen(filename, "w");
3330
ASSERT_FALSE(file == nullptr);
3431
constexpr char CONTENT[] = "123456789";
3532
constexpr size_t WRITE_SIZE = sizeof(CONTENT) - 1;
36-
ASSERT_THAT(LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file),
37-
Succeeds(WRITE_SIZE));
33+
ASSERT_EQ(WRITE_SIZE, LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file));
3834
// This is a write-only file so reads should fail.
39-
ASSERT_THAT(func(file), Fails(EBADF, EOF));
35+
ASSERT_EQ(func(file), EOF);
4036
// This is an error and not a real EOF.
4137
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
4238
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
39+
libc_errno = 0;
4340

44-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
41+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
4542

4643
file = LIBC_NAMESPACE::fopen(filename, "r");
4744
ASSERT_FALSE(file == nullptr);
4845

4946
LIBC_NAMESPACE::flockfile(file);
5047
for (size_t i = 0; i < WRITE_SIZE; ++i) {
51-
ASSERT_THAT(func(file), Succeeds(int('1' + i)));
48+
int c = func(file);
49+
ASSERT_EQ(c, int('1' + i));
5250
}
5351
// Reading more should return EOF but not set error.
54-
ASSERT_THAT(func(file), Succeeds(EOF));
52+
ASSERT_EQ(func(file), EOF);
5553
ASSERT_NE(LIBC_NAMESPACE::feof_unlocked(file), 0);
5654
ASSERT_EQ(LIBC_NAMESPACE::ferror_unlocked(file), 0);
5755

5856
LIBC_NAMESPACE::funlockfile(file);
59-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
57+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
6058
}
6159
};
6260

libc/test/src/stdio/fgets_test.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
#include "src/stdio/fgets.h"
1313
#include "src/stdio/fopen.h"
1414
#include "src/stdio/fwrite.h"
15-
#include "test/UnitTest/ErrnoCheckingTest.h"
16-
#include "test/UnitTest/ErrnoSetterMatcher.h"
1715
#include "test/UnitTest/Test.h"
1816

19-
using LlvmLibcFgetsTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
20-
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
17+
#include "src/__support/libc_errno.h"
2118

22-
TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
19+
TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
2320
constexpr char FILENAME[] = "testdata/fgets.test";
2421
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
2522
ASSERT_FALSE(file == nullptr);
@@ -32,15 +29,15 @@ TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
3229
char buff[8];
3330
char *output;
3431

35-
ASSERT_THAT(LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file),
36-
Succeeds(WRITE_SIZE));
32+
ASSERT_EQ(WRITE_SIZE, LIBC_NAMESPACE::fwrite(CONTENT, 1, WRITE_SIZE, file));
3733
// This is a write-only file so reads should fail.
38-
ASSERT_THAT(LIBC_NAMESPACE::fgets(buff, 8, file), Fails(EBADF, nullptr));
34+
ASSERT_TRUE(LIBC_NAMESPACE::fgets(buff, 8, file) == nullptr);
3935
// This is an error and not a real EOF.
4036
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
4137
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
38+
libc_errno = 0;
4239

43-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
40+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
4441

4542
file = LIBC_NAMESPACE::fopen(FILENAME, "r");
4643
ASSERT_FALSE(file == nullptr);
@@ -58,7 +55,6 @@ TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
5855
// This is also implementation defined.
5956
output = LIBC_NAMESPACE::fgets(buff, 0, file);
6057
ASSERT_TRUE(output == nullptr);
61-
ASSERT_ERRNO_SUCCESS();
6258
#endif
6359

6460
const char *output_arr[] = {
@@ -90,5 +86,5 @@ TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
9086
ASSERT_NE(LIBC_NAMESPACE::feof(file), 0);
9187
ASSERT_ERRNO_SUCCESS();
9288

93-
ASSERT_THAT(LIBC_NAMESPACE::fclose(file), Succeeds());
89+
ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
9490
}

0 commit comments

Comments
 (0)