Skip to content

Commit 52c7fae

Browse files
committed
[demangler] improve test harness
The demangler test harness is a little unclear. The failed demangling message always causes me to think about 'reality', changing to a simple 'Found' seems clearer. The expected-to-fail tests abort as soon as one passes, rather than continue, and then abort if any passed. This changes that loop to fail at the end, in a similar manner to the expected-to-work loop. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D118130
1 parent b58174d commit 52c7fae

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29946,51 +29946,43 @@ void test()
2994629946
for (unsigned i = 0; i < N; ++i)
2994729947
{
2994829948
int status;
29949-
char* demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
29950-
if (demang == 0 || std::strcmp(demang, cases[i][1]) != 0)
29949+
char* demang =
29950+
__cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
29951+
if (!demang || std::strcmp(demang, cases[i][1]) != 0)
2995129952
{
29952-
std::printf("ERROR demangling %s\nexpected: %s\n", cases[i][0], cases[i][1]);
29953-
if (demang)
29954-
{
29955-
std::printf(" reality: %s\n", demang);
29956-
buf = demang;
29957-
failed = true;
29958-
}
29959-
else
29960-
{
29961-
std::printf("Got instead: NULL, %d\n", status);
29962-
failed = true;
29963-
}
29964-
}
29965-
else
29966-
{
29967-
buf = demang;
29953+
std::printf("ERROR demangling %s\nexpected: %s\n",
29954+
cases[i][0], cases[i][1]);
29955+
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
29956+
failed = true;
2996829957
}
29958+
if (demang)
29959+
buf = demang;
2996929960
}
29970-
assert(!failed);
2997129961
free(buf);
29962+
assert(!failed && "demangle failed");
2997229963
}
2997329964

2997429965
void test_invalid_cases()
2997529966
{
2997629967
std::size_t len = 0;
2997729968
char* buf = nullptr;
29969+
bool passed = false;
2997829970
for (unsigned i = 0; i < NI; ++i)
2997929971
{
2998029972
int status;
29981-
char* demang = __cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
29973+
char* demang =
29974+
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
2998229975
if (status != -2)
2998329976
{
2998429977
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
29985-
std::printf("Got status %d\n", status);
29986-
assert(status == -2);
29987-
}
29988-
else
29989-
{
29990-
buf = demang;
29978+
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
29979+
passed = true;
2999129980
}
29981+
if (demang)
29982+
buf = demang;
2999229983
}
2999329984
free(buf);
29985+
assert(!passed && "demangle did not fail");
2999429986
}
2999529987

2999629988
const char *xfail_cases[] = {

0 commit comments

Comments
 (0)