strerror: incl enum name
strerror is nice, but usually I don't care about the text, I care about
the uppercase enum
Bug: N/A
Test: ./tests/run-on-host.sh glibc (existing failures -> b/201305529)
Test: atest bionic-unit-tests-static
Test: atest malloc_debug_unit_tests
Change-Id: I407bd9f4dfa918fff66a0da7df8d7239f789c7b8
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index e38dd60..cf8cb0a 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -2461,7 +2461,7 @@
ASSERT_STREQ("<Unknown error -1>", buf);
errno = EINVAL;
snprintf(buf, sizeof(buf), "<%m>");
- ASSERT_STREQ("<Invalid argument>", buf);
+ ASSERT_MATCH(buf, "<Invalid argument.*>");
}
TEST(STDIO_TEST, printf_m_does_not_clobber_strerror) {
@@ -2484,7 +2484,7 @@
ASSERT_EQ(std::wstring(L"<Unknown error -1>"), buf);
errno = EINVAL;
swprintf(buf, sizeof(buf), L"<%m>");
- ASSERT_EQ(std::wstring(L"<Invalid argument>"), buf);
+ ASSERT_MATCH(buf, L"Invalid argument.*>");
}
TEST(STDIO_TEST, wprintf_m_does_not_clobber_strerror) {
@@ -2558,9 +2558,9 @@
TEST(STDIO_TEST, perror) {
ExecTestHelper eth;
- eth.Run([&]() { errno = EINVAL; perror("a b c"); exit(0); }, 0, "a b c: Invalid argument\n");
- eth.Run([&]() { errno = EINVAL; perror(nullptr); exit(0); }, 0, "Invalid argument\n");
- eth.Run([&]() { errno = EINVAL; perror(""); exit(0); }, 0, "Invalid argument\n");
+ eth.Run([&]() { errno = EINVAL; perror("a b c"); exit(0); }, 0, "a b c: Invalid argument.*\n");
+ eth.Run([&]() { errno = EINVAL; perror(nullptr); exit(0); }, 0, "Invalid argument.*\n");
+ eth.Run([&]() { errno = EINVAL; perror(""); exit(0); }, 0, "Invalid argument.*\n");
}
TEST(STDIO_TEST, puts) {
diff --git a/tests/string_posix_strerror_r_test.cpp b/tests/string_posix_strerror_r_test.cpp
index e4becaa..808f963 100644
--- a/tests/string_posix_strerror_r_test.cpp
+++ b/tests/string_posix_strerror_r_test.cpp
@@ -15,6 +15,8 @@
*/
#include <errno.h>
+
+#include <android-base/test_utils.h>
#include <gtest/gtest.h>
// Defined in string_posix_strerror_r_wrapper.cpp as a wrapper around the posix
@@ -33,7 +35,7 @@
ASSERT_STREQ("Success", buf);
#endif
ASSERT_EQ(0, posix_strerror_r(1, buf, sizeof(buf)));
- ASSERT_STREQ("Operation not permitted", buf);
+ ASSERT_MATCH(buf, "Operation not permitted.*");
#if defined(__BIONIC__) || defined(ANDROID_HOST_MUSL)
// Invalid.
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 8d3fb68..1b0082f 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -28,6 +28,8 @@
#include <algorithm>
#include <vector>
+#include <android-base/test_utils.h>
+
#include "buffer_tests.h"
#if defined(NOFORTIFY)
@@ -58,7 +60,7 @@
TEST(STRING_TEST, strerror) {
// Valid.
ASSERT_STREQ("Success", strerror(0));
- ASSERT_STREQ("Operation not permitted", strerror(1));
+ ASSERT_MATCH(strerror(1), "Operation not permitted.*");
// Invalid.
ASSERT_STREQ("Unknown error -1", strerror(-1));
@@ -106,9 +108,9 @@
#if defined(__BIONIC__)
ASSERT_STREQ("Success", buf);
#endif
- ASSERT_STREQ("Operation not permitted", strerror_r(1, buf, sizeof(buf)));
+ ASSERT_MATCH(strerror_r(1, buf, sizeof(buf)), "Operation not permitted.*");
#if defined(__BIONIC__)
- ASSERT_STREQ("Operation not permitted", buf);
+ ASSERT_MATCH(buf, "Operation not permitted.*");
#endif
// Invalid.
diff --git a/tests/utils.h b/tests/utils.h
index 284140a..90fb1d0 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -44,6 +44,7 @@
#include <android-base/macros.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
+#include <android-base/test_utils.h>
#if defined(__LP64__)
#define PATH_TO_SYSTEM_LIB "/system/lib64/"
@@ -259,9 +260,7 @@
std::string error_msg("Test output:\n" + output_);
AssertChildExited(pid, expected_exit_status, &error_msg);
if (expected_output_regex != nullptr) {
- if (!std::regex_search(output_, std::regex(expected_output_regex))) {
- FAIL() << "regex " << expected_output_regex << " didn't match " << output_;
- }
+ ASSERT_MATCH(output_, expected_output_regex);
}
}