[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
This commit is contained in:
Nathan Sidwell 2022-01-24 11:07:29 -08:00
parent b58174d624
commit 52c7faeae8
1 changed files with 18 additions and 26 deletions

View File

@ -29946,51 +29946,43 @@ void test()
for (unsigned i = 0; i < N; ++i)
{
int status;
char* demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
if (demang == 0 || std::strcmp(demang, cases[i][1]) != 0)
char* demang =
__cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
if (!demang || std::strcmp(demang, cases[i][1]) != 0)
{
std::printf("ERROR demangling %s\nexpected: %s\n", cases[i][0], cases[i][1]);
if (demang)
{
std::printf(" reality: %s\n", demang);
buf = demang;
failed = true;
}
else
{
std::printf("Got instead: NULL, %d\n", status);
failed = true;
}
}
else
{
buf = demang;
std::printf("ERROR demangling %s\nexpected: %s\n",
cases[i][0], cases[i][1]);
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
failed = true;
}
if (demang)
buf = demang;
}
assert(!failed);
free(buf);
assert(!failed && "demangle failed");
}
void test_invalid_cases()
{
std::size_t len = 0;
char* buf = nullptr;
bool passed = false;
for (unsigned i = 0; i < NI; ++i)
{
int status;
char* demang = __cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
char* demang =
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
if (status != -2)
{
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
std::printf("Got status %d\n", status);
assert(status == -2);
}
else
{
buf = demang;
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
passed = true;
}
if (demang)
buf = demang;
}
free(buf);
assert(!passed && "demangle did not fail");
}
const char *xfail_cases[] = {