Skip to content

Commit b61fb18

Browse files
authored
[libc++] Fix tests on musl (#85085)
One or two of the tests need slight tweaks to make them pass when building with musl. rdar://118885724
1 parent 66dd38e commit b61fb18

File tree

3 files changed

+52
-37
lines changed

3 files changed

+52
-37
lines changed

libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ int main(int, char**)
4444
errno = E2BIG; // something that message will never generate
4545
const std::error_category& e_cat1 = std::generic_category();
4646
const std::string msg = e_cat1.message(-1);
47-
// Exact message format varies by platform.
48-
#if defined(_AIX)
49-
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
50-
#elif defined(_NEWLIB_VERSION)
51-
LIBCPP_ASSERT(msg.empty());
52-
#else
53-
LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
47+
// Exact message format varies by platform. We can't detect
48+
// some of these (Musl in particular) using the preprocessor,
49+
// so accept a few sensible messages. Newlib unfortunately
50+
// responds with an empty message, which we probably want to
51+
// treat as a failure code otherwise, but we can detect that
52+
// with the preprocessor.
53+
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
54+
|| msg.rfind("No error information", 0) == 0 // Musl
55+
|| msg.rfind("Unknown error", 0) == 0 // Glibc
56+
#if defined(_NEWLIB_VERSION)
57+
|| msg.empty()
5458
#endif
59+
);
5560
assert(errno == E2BIG);
5661
}
5762

libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ int main(int, char**) {
5050
errno = E2BIG; // something that message will never generate
5151
const std::error_category& e_cat1 = std::system_category();
5252
const std::string msg = e_cat1.message(-1);
53-
// Exact message format varies by platform.
54-
#if defined(_AIX)
55-
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
56-
#elif defined(_NEWLIB_VERSION)
57-
LIBCPP_ASSERT(msg.empty());
58-
#else
59-
LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
53+
// Exact message format varies by platform. We can't detect
54+
// some of these (Musl in particular) using the preprocessor,
55+
// so accept a few sensible messages. Newlib unfortunately
56+
// responds with an empty message, which we probably want to
57+
// treat as a failure code otherwise, but we can detect that
58+
// with the preprocessor.
59+
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
60+
|| msg.rfind("No error information", 0) == 0 // Musl
61+
|| msg.rfind("Unknown error", 0) == 0 // Glibc
62+
#if defined(_NEWLIB_VERSION)
63+
|| msg.empty()
6064
#endif
65+
);
6166
assert(errno == E2BIG);
6267
}
6368

libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <locale>
2323
#include <ios>
2424
#include <cassert>
25+
#include <cstdio>
2526
#include <streambuf>
2627
#include <cmath>
2728
#include "test_macros.h"
@@ -8934,11 +8935,12 @@ void test4()
89348935
char str[200];
89358936
std::locale lc = std::locale::classic();
89368937
std::locale lg(lc, new my_numpunct);
8937-
#ifdef _AIX
8938-
std::string inf = "INF";
8939-
#else
8940-
std::string inf = "inf";
8941-
#endif
8938+
8939+
std::string inf;
8940+
8941+
// This should match the underlying C library
8942+
std::sprintf(str, "%f", INFINITY);
8943+
inf = str;
89428944

89438945
const my_facet f(1);
89448946
{
@@ -10727,24 +10729,27 @@ void test5()
1072710729
std::locale lc = std::locale::classic();
1072810730
std::locale lg(lc, new my_numpunct);
1072910731
const my_facet f(1);
10730-
#if defined(_AIX)
10731-
std::string nan= "NaNQ";
10732-
std::string NaN = "NaNQ";
10733-
std::string nan_padding25 = "*********************";
10734-
std::string pnan_sign = "+";
10735-
std::string pnan_padding25 = "********************";
10736-
#else
10737-
std::string nan= "nan";
10738-
std::string NaN = "NAN";
10739-
std::string nan_padding25 = "**********************";
10740-
#if defined(TEST_HAS_GLIBC) || defined(_WIN32)
10741-
std::string pnan_sign = "+";
10742-
std::string pnan_padding25 = "*********************";
10743-
#else
10744-
std::string pnan_sign = "";
10745-
std::string pnan_padding25 = "**********************";
10746-
#endif
10747-
#endif
10732+
10733+
std::string nan;
10734+
std::string NaN;
10735+
std::string pnan_sign;
10736+
10737+
// The output here depends on the underlying C library, so work out what
10738+
// that does.
10739+
std::sprintf(str, "%f", std::nan(""));
10740+
nan = str;
10741+
10742+
std::sprintf(str, "%F", std::nan(""));
10743+
NaN = str;
10744+
10745+
std::sprintf(str, "%+f", std::nan(""));
10746+
if (str[0] == '+') {
10747+
pnan_sign = "+";
10748+
}
10749+
10750+
std::string nan_padding25 = std::string(25 - nan.length(), '*');
10751+
std::string pnan_padding25 = std::string(25 - nan.length() - pnan_sign.length(), '*');
10752+
1074810753
{
1074910754
long double v = std::nan("");
1075010755
std::ios ios(0);

0 commit comments

Comments
 (0)