Previously the tests were copy/pasted into several files, this changes
them to be instead templated and sharing one file.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Look like you'll need to update the bazel layout for the tests. It complains about missing files.
| libc/test/src/stdlib/StrtolTest.h | ||
|---|---|---|
| 165–169 | This pattern is repeated a lot in this test. Maybe you can factor it to another method or macro then? | |
address comment and update bazel
| libc/test/src/stdlib/StrtolTest.h | ||
|---|---|---|
| 165–169 | I think for clarity having this pattern repeated is okay. There are three separate asserts and being able to see them individually instead of needing to translate a macro is better when debugging. While I could change these to be #define STRTOL_TEST(str, base, return_val, expected_errno, expected_strlen) \ errno = 0; \ ASSERT_EQ(func(str, &str_end, base), ReturnT(return_val)); \ ASSERT_EQ(errno, expected_errno); \ EXPECT_EQ(str_end - str, ptrdiff_t(expected_strlen)); STRTOL_TEST(signafter, 10, 2, 0, 1) I think that last line so short as to be unreadable. If there was a test failure I'd have to go back and read through the macro every time to remember which number is which. | |
| libc/test/src/stdlib/StrtolTest.h | ||
|---|---|---|
| 165–169 | I think you could add the following method to StrtoTest class: void Check(FunctionT func, const char *str, int base ReturnT return_val, int expected_errno, int expected_strlen) {
char *str_end = nullptr;
errno = 0;
ASSERT_EQ(func(str, &str_end, base), return_val);
ASSERT_EQ(errno, expected_errno);
EXPECT_EQ(str_end - str, ptrdiff_t(expected_strlen));
}and then the stack trace should show you the exact failed statement, especially if the call sites are notated with parameter names: Check("2+2=4", /*base*/ 10, /*return_val*/ ReturnT(2), /*expected_errno*/ 0, /*expected_strlen*/ 1);This is a lot of changes for the current tests, so maybe you can create a clean up task/issue/TODO to be done later. | |
add a comment and rebase
| libc/test/src/stdlib/StrtolTest.h | ||
|---|---|---|
| 165–169 | I've added a comment at the top to look into it. | |
This pattern is repeated a lot in this test. Maybe you can factor it to another method or macro then?