Skip to content

Commit d1f5850

Browse files
ldionneal45tair
andauthored
[libc++] Fix tests on musl (#85085) (#86934)
One or two of the tests need slight tweaks to make them pass when building with musl. This patch is a re-application of b61fb18 which was reverted in 0847c90 because it broke the build. rdar://118885724 Co-authored-by: Alastair Houghton <[email protected]>
1 parent ca48d4d commit d1f5850

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
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: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
// iter_type put(iter_type s, ios_base& iob, char_type fill, long double v) const;
1414

1515
// XFAIL: win32-broken-printf-g-precision
16-
// XFAIL: LIBCXX-PICOLIBC-FIXME
17-
18-
// Needs more investigation, but this is probably failing on Android M (API 23)
19-
// and up because the printf formatting of NAN changed.
20-
// XFAIL: LIBCXX-ANDROID-FIXME && !android-device-api={{21|22}}
2116

2217
#include <locale>
2318
#include <ios>
2419
#include <cassert>
20+
#include <cstdio>
2521
#include <streambuf>
2622
#include <cmath>
2723
#include "test_macros.h"
@@ -8934,11 +8930,10 @@ void test4()
89348930
char str[200];
89358931
std::locale lc = std::locale::classic();
89368932
std::locale lg(lc, new my_numpunct);
8937-
#ifdef _AIX
8938-
std::string inf = "INF";
8939-
#else
8940-
std::string inf = "inf";
8941-
#endif
8933+
8934+
// This should match the underlying C library
8935+
std::snprintf(str, sizeof(str), "%f", INFINITY);
8936+
std::string inf = str;
89428937

89438938
const my_facet f(1);
89448939
{
@@ -10727,24 +10722,24 @@ void test5()
1072710722
std::locale lc = std::locale::classic();
1072810723
std::locale lg(lc, new my_numpunct);
1072910724
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
10725+
10726+
// The output here depends on the underlying C library, so work out what
10727+
// that does.
10728+
std::snprintf(str, sizeof(str), "%f", std::nan(""));
10729+
std::string nan = str;
10730+
10731+
std::snprintf(str, sizeof(str), "%F", std::nan(""));
10732+
std::string NaN = str;
10733+
10734+
std::snprintf(str, sizeof(str), "%+f", std::nan(""));
10735+
std::string pnan_sign;
10736+
if (str[0] == '+') {
10737+
pnan_sign = "+";
10738+
}
10739+
10740+
std::string nan_padding25 = std::string(25 - nan.length(), '*');
10741+
std::string pnan_padding25 = std::string(25 - nan.length() - pnan_sign.length(), '*');
10742+
1074810743
{
1074910744
long double v = std::nan("");
1075010745
std::ios ios(0);

0 commit comments

Comments
 (0)