mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-22 16:02:29 +02:00
CppUnit: demangle class names
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include "CppUnit/CppUnit.h"
|
#include "CppUnit/CppUnit.h"
|
||||||
#include "CppUnit/Guards.h"
|
#include "CppUnit/Guards.h"
|
||||||
#include "CppUnit/Test.h"
|
#include "CppUnit/Test.h"
|
||||||
|
#include "CppUnit/TestResult.h"
|
||||||
#include "CppUnit/CppUnitException.h"
|
#include "CppUnit/CppUnitException.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -243,7 +244,7 @@ inline void TestCase::tearDown()
|
|||||||
inline std::string TestCase::toString() const
|
inline std::string TestCase::toString() const
|
||||||
{
|
{
|
||||||
const std::type_info& thisClass = typeid(*this);
|
const std::type_info& thisClass = typeid(*this);
|
||||||
return std::string(thisClass.name()) + "." + name();
|
return TestResult::demangle(thisClass.name()) + "." + name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -97,6 +97,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static std::string demangle(const char* name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setSynchronizationObject(SynchronizationObject* syncObject);
|
virtual void setSynchronizationObject(SynchronizationObject* syncObject);
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ void TestCase::run(TestResult *result, const Test::Callback& callback)
|
|||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
std::string msg(typeid(e).name());
|
std::string msg(TestResult::demangle(typeid(e).name()));
|
||||||
msg.append(":\n").append(callback(e));
|
msg.append(":\n").append(callback(e));
|
||||||
result->addError(this, new CppUnitException(msg));
|
result->addError(this, new CppUnitException(msg));
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "CppUnit/TestResult.h"
|
#include "CppUnit/TestResult.h"
|
||||||
|
#ifdef POCO_HAVE_CXXABI_H
|
||||||
|
#include <cxxabi.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace CppUnit {
|
namespace CppUnit {
|
||||||
@@ -24,4 +28,26 @@ TestResult::~TestResult()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string TestResult::demangle(const char* typeName)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
#ifdef POCO_HAVE_CXXABI_H
|
||||||
|
int status;
|
||||||
|
char* demangled = abi::__cxa_demangle(typeName, nullptr, nullptr, &status);
|
||||||
|
if (demangled)
|
||||||
|
{
|
||||||
|
result = demangled;
|
||||||
|
std::free(demangled);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = typeName;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
result = typeName;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace CppUnit
|
} // namespace CppUnit
|
||||||
|
@@ -243,10 +243,12 @@
|
|||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#define POCO_COMPILER_CLANG
|
#define POCO_COMPILER_CLANG
|
||||||
|
#define POCO_HAVE_CXXABI_H
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define POCO_COMPILER_MSVC
|
#define POCO_COMPILER_MSVC
|
||||||
#elif defined (__GNUC__)
|
#elif defined (__GNUC__)
|
||||||
#define POCO_COMPILER_GCC
|
#define POCO_COMPILER_GCC
|
||||||
|
#define POCO_HAVE_CXXABI_H
|
||||||
#if defined (__MINGW32__) || defined (__MINGW64__)
|
#if defined (__MINGW32__) || defined (__MINGW64__)
|
||||||
#define POCO_COMPILER_MINGW
|
#define POCO_COMPILER_MINGW
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user