New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unit_tests: fix strtoul unit test #9214
Conversation
That's exactly why the test sets errno. C functions which interact with errno change it when an error occurs (per the man page), and otherwise leave it alone; it would be ridiculous to expect functions to document what they don't do. |
EXPECT_EQ(0, ul); | ||
EXPECT_EQ(p + 1, endp); | ||
|
||
p = " \t 0"; | ||
endp = nullptr; | ||
ul = std::strtoul(p, const_cast<char**>(&endp), 10); | ||
EXPECT_EQ(0, errno); | ||
EXPECT_EQ(0, ul); | ||
EXPECT_EQ(p + 9, endp); | ||
|
||
p = "q"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the test would be the most likely to break across systems: Per the man page, some systems report EINVAL here: "EINVAL (not in C99) The given base contains an unsupported value." The c++ function makes no mention of EINVAL, so perhaps whoever wrote this test suite wanted a way to determine the actual behavior in a given build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant to put this comment on the test immediately below this one, yeah? According to the C standard, strtoul
should skip over whitespace. But yes, I agree with the general point, so I updated the commit to just remove the EXPECT_EQ(0)
from the invalid character test.
155c924
to
399b884
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes this test failing on macOS
errno
not guaranteed to be anything according to C standard, except on range error