Skip to content

Commit 9e61605

Browse files
committed
[libc++] Fix tests on musl.
One or two of the tests need slight tweaks to make them pass when building with musl. rdar://118885724
1 parent d23d90c commit 9e61605

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ void test_message_for_bad_value() {
2727
const std::error_category& e_cat1 = std::generic_category();
2828
const std::string msg = e_cat1.message(-1);
2929
// Exact message format varies by platform.
30-
#if defined(_AIX)
31-
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
32-
#else
33-
LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
34-
#endif
30+
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0
31+
|| msg.rfind("No error information", 0) == 0
32+
|| msg.rfind("Unknown error", 0) == 0);
3533
assert(errno == E2BIG);
3634
}
3735

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ void test_message_for_bad_value() {
2727
const std::error_category& e_cat1 = std::system_category();
2828
const std::string msg = e_cat1.message(-1);
2929
// Exact message format varies by platform.
30-
#if defined(_AIX)
31-
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0);
32-
#else
33-
LIBCPP_ASSERT(msg.rfind("Unknown error", 0) == 0);
34-
#endif
30+
LIBCPP_ASSERT(
31+
msg.rfind("No error information", 0) == 0
32+
|| msg.rfind("Unknown error", 0) == 0 // Musl
33+
|| msg.rfind("Error -1 occurred", 0) == 0 // AIX
34+
);
3535
assert(errno == E2BIG);
3636
}
3737

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <locale>
1818
#include <ios>
1919
#include <cassert>
20+
#include <cstdio>
2021
#include <streambuf>
2122
#include <cmath>
2223
#include "test_macros.h"
@@ -8929,11 +8930,12 @@ void test4()
89298930
char str[200];
89308931
std::locale lc = std::locale::classic();
89318932
std::locale lg(lc, new my_numpunct);
8932-
#ifdef _AIX
8933-
std::string inf = "INF";
8934-
#else
8935-
std::string inf = "inf";
8936-
#endif
8933+
8934+
std::string inf;
8935+
8936+
// This should match the underlying C library
8937+
std::sprintf(str, "%f", INFINITY);
8938+
inf = str;
89378939

89388940
const my_facet f(1);
89398941
{
@@ -10722,24 +10724,28 @@ void test5()
1072210724
std::locale lc = std::locale::classic();
1072310725
std::locale lg(lc, new my_numpunct);
1072410726
const my_facet f(1);
10725-
#if defined(_AIX)
10726-
std::string nan= "NaNQ";
10727-
std::string NaN = "NaNQ";
10728-
std::string nan_padding25 = "*********************";
10729-
std::string pnan_sign = "+";
10730-
std::string pnan_padding25 = "********************";
10731-
#else
10732-
std::string nan= "nan";
10733-
std::string NaN = "NAN";
10734-
std::string nan_padding25 = "**********************";
10735-
#if defined(TEST_HAS_GLIBC) || defined(_WIN32)
10736-
std::string pnan_sign = "+";
10737-
std::string pnan_padding25 = "*********************";
10738-
#else
10739-
std::string pnan_sign = "";
10740-
std::string pnan_padding25 = "**********************";
10741-
#endif
10742-
#endif
10727+
10728+
std::string nan;
10729+
std::string NaN;
10730+
std::string pnan_sign;
10731+
10732+
// The output here depends on the underlying C library, so work out what
10733+
// that does.
10734+
std::sprintf(str, "%f", std::nan(""));
10735+
nan = str;
10736+
10737+
std::sprintf(str, "%F", std::nan(""));
10738+
NaN = str;
10739+
10740+
std::sprintf(str, "%+f", std::nan(""));
10741+
if (str[0] == '+') {
10742+
pnan_sign = "+";
10743+
}
10744+
10745+
std::string nan_padding25 = std::string(25 - nan.length(), '*');
10746+
std::string pnan_padding25 = std::string(25 - nan.length()
10747+
- pnan_sign.length(), '*');
10748+
1074310749
{
1074410750
long double v = std::nan("");
1074510751
std::ios ios(0);

0 commit comments

Comments
 (0)