Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).
We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.
I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.
Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.
I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.
Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 38957e2..50db4fb 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -29,6 +29,7 @@
#include <vector>
#include "buffer_tests.h"
+#include "utils.h"
#if defined(NOFORTIFY)
#define STRING_TEST string_nofortify
@@ -123,7 +124,7 @@
ASSERT_EQ(buf, strerror_r(4567, buf, 2));
ASSERT_STREQ("U", buf);
// The GNU strerror_r doesn't set errno (the POSIX one sets it to ERANGE).
- ASSERT_EQ(0, errno);
+ ASSERT_ERRNO(0);
#else
GTEST_SKIP() << "musl doesn't have GNU strerror_r";
#endif
@@ -1483,7 +1484,7 @@
errno = 0;
const char* out = basename(in);
ASSERT_STREQ(expected_out, out) << in;
- ASSERT_EQ(0, errno) << in;
+ ASSERT_ERRNO(0) << in;
}
#endif