[libcxx-commits] [libcxxabi] 52c7fae - [demangler] improve test harness
Nathan Sidwell via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 26 04:59:48 PST 2022
Author: Nathan Sidwell
Date: 2022-01-26T04:59:25-08:00
New Revision: 52c7faeae8fce49cd7e3853a29bb38e3ce5be892
URL: https://github.com/llvm/llvm-project/commit/52c7faeae8fce49cd7e3853a29bb38e3ce5be892
DIFF: https://github.com/llvm/llvm-project/commit/52c7faeae8fce49cd7e3853a29bb38e3ce5be892.diff
LOG: [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
Added:
Modified:
libcxxabi/test/test_demangle.pass.cpp
Removed:
################################################################################
diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 7bbb17c581cc1..41ee1100d12d2 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -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[] = {
More information about the libcxx-commits
mailing list