mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Add __func__ to unit test metadata printed on failure.
This commit is contained in:
parent
49d6200413
commit
a8e25da0ab
@ -28,6 +28,21 @@
|
||||
|
||||
#include <vtkm/thirdparty/diy/diy.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#define VTKM_MATH_ASSERT(condition, message) \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
return; \
|
||||
} \
|
||||
std::stringstream ss; \
|
||||
ss << "Error at " << __FILE__ << ":" << __LINE__ << ":" << __func__ << "\n"; \
|
||||
ss << "\t" << message; \
|
||||
this->RaiseError(ss.str().c_str()); \
|
||||
}
|
||||
|
||||
|
||||
namespace opt = vtkm::cont::internal::option;
|
||||
|
||||
namespace vtkm
|
||||
@ -141,26 +156,25 @@ public:
|
||||
{
|
||||
function();
|
||||
}
|
||||
catch (vtkm::testing::Testing::TestFailure& error)
|
||||
catch (vtkm::testing::Testing::TestFailure const& error)
|
||||
{
|
||||
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
std::cerr << "Error at " << error.GetFile() << ":" << error.GetLine() << ":"
|
||||
<< error.GetFunc() << "\n\t" << error.GetMessage() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (vtkm::cont::Error& error)
|
||||
catch (vtkm::cont::Error const& error)
|
||||
{
|
||||
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
std::cerr << "Uncaught VTKm exception thrown:" << error.GetMessage() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (std::exception& error)
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
|
||||
std::cerr << "STL exception throw.\n" << error.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "***** Unidentified exception thrown." << std::endl;
|
||||
std::cerr << "Unidentified exception thrown.\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -179,24 +193,25 @@ public:
|
||||
}
|
||||
catch (vtkm::testing::Testing::TestFailure& error)
|
||||
{
|
||||
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
std::cerr << "Error at " << error.GetFile() << ":" << error.GetLine() << ":"
|
||||
<< error.GetFunc() << "\n\t";
|
||||
<< error.GetMessage() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (vtkm::cont::Error& error)
|
||||
{
|
||||
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
std::cerr << "Uncaught VTKm exception thrown.\n\t";
|
||||
<< error.GetMessage() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (std::exception& error)
|
||||
{
|
||||
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
|
||||
std::cerr << "STL exception throw.\n\t" << error.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "***** Unidentified exception thrown." << std::endl;
|
||||
std::cout << "Unidentified exception thrown.\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -66,13 +66,14 @@
|
||||
|
||||
#define VTKM_TEST_ASSERT(...) \
|
||||
::vtkm::testing::Testing::Assert( \
|
||||
VTKM_STRINGIFY_FIRST(__VA_ARGS__), __FILE__, __LINE__, __VA_ARGS__)
|
||||
VTKM_STRINGIFY_FIRST(__VA_ARGS__), __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
/// \def VTKM_TEST_FAIL(messages..)
|
||||
///
|
||||
/// Causes a test to fail with the given \a messages. At least one argument must be given.
|
||||
|
||||
#define VTKM_TEST_FAIL(...) ::vtkm::testing::Testing::TestFail(__FILE__, __LINE__, __VA_ARGS__)
|
||||
#define VTKM_TEST_FAIL(...) \
|
||||
::vtkm::testing::Testing::TestFail(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
class TestEqualResult
|
||||
{
|
||||
@ -295,9 +296,13 @@ public:
|
||||
{
|
||||
public:
|
||||
template <typename... Ts>
|
||||
VTKM_CONT TestFailure(const std::string& file, vtkm::Id line, Ts&&... messages)
|
||||
VTKM_CONT TestFailure(const std::string& file,
|
||||
vtkm::Id line,
|
||||
const char* func,
|
||||
Ts&&... messages)
|
||||
: File(file)
|
||||
, Line(line)
|
||||
, Func(func)
|
||||
{
|
||||
std::stringstream messageStream;
|
||||
this->AppendMessages(messageStream, std::forward<Ts>(messages)...);
|
||||
@ -306,6 +311,7 @@ public:
|
||||
|
||||
VTKM_CONT const std::string& GetFile() const { return this->File; }
|
||||
VTKM_CONT vtkm::Id GetLine() const { return this->Line; }
|
||||
VTKM_CONT const char* GetFunc() const { return this->Func; }
|
||||
VTKM_CONT const std::string& GetMessage() const { return this->Message; }
|
||||
|
||||
private:
|
||||
@ -347,6 +353,7 @@ public:
|
||||
|
||||
std::string File;
|
||||
vtkm::Id Line;
|
||||
const char* Func;
|
||||
std::string Message;
|
||||
};
|
||||
|
||||
@ -354,6 +361,7 @@ public:
|
||||
static VTKM_CONT void Assert(const std::string& conditionString,
|
||||
const std::string& file,
|
||||
vtkm::Id line,
|
||||
const char* func,
|
||||
bool condition,
|
||||
Ts&&... messages)
|
||||
{
|
||||
@ -363,30 +371,36 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
throw TestFailure(file, line, std::forward<Ts>(messages)..., " (", conditionString, ")");
|
||||
throw TestFailure(
|
||||
file, line, func, std::forward<Ts>(messages)..., " (", conditionString, ")");
|
||||
}
|
||||
}
|
||||
|
||||
static VTKM_CONT void Assert(const std::string& conditionString,
|
||||
const std::string& file,
|
||||
const char* func,
|
||||
vtkm::Id line,
|
||||
bool condition)
|
||||
{
|
||||
Assert(conditionString, file, line, condition, "Test assertion failed");
|
||||
Assert(conditionString, file, line, func, condition, "Test assertion failed");
|
||||
}
|
||||
|
||||
static VTKM_CONT void Assert(const std::string& conditionString,
|
||||
const std::string& file,
|
||||
const char* func,
|
||||
vtkm::Id line,
|
||||
const TestEqualResult& result)
|
||||
{
|
||||
Assert(conditionString, file, line, static_cast<bool>(result), result.GetMergedMessage());
|
||||
Assert(conditionString, file, line, func, static_cast<bool>(result), result.GetMergedMessage());
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
static VTKM_CONT void TestFail(const std::string& file, vtkm::Id line, Ts&&... messages)
|
||||
static VTKM_CONT void TestFail(const std::string& file,
|
||||
vtkm::Id line,
|
||||
const char* func,
|
||||
Ts&&... messages)
|
||||
{
|
||||
throw TestFailure(file, line, std::forward<Ts>(messages)...);
|
||||
throw TestFailure(file, line, func, std::forward<Ts>(messages)...);
|
||||
}
|
||||
|
||||
#ifndef VTKM_TESTING_IN_CONT
|
||||
@ -433,20 +447,21 @@ public:
|
||||
{
|
||||
function();
|
||||
}
|
||||
catch (TestFailure& error)
|
||||
catch (TestFailure const& error)
|
||||
{
|
||||
std::cout << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << std::endl
|
||||
<< error.GetMessage() << std::endl;
|
||||
std::cerr << "***** Test failed @ " << error.GetFile() << ":" << error.GetLine() << ":"
|
||||
<< error.GetFunc() << "\n"
|
||||
<< error.GetMessage() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (std::exception& error)
|
||||
catch (std::exception const& error)
|
||||
{
|
||||
std::cout << "***** STL exception throw." << std::endl << error.what() << std::endl;
|
||||
std::cerr << "***** STL exception throw.\n" << error.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "***** Unidentified exception thrown." << std::endl;
|
||||
std::cerr << "***** Unidentified exception thrown.\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -20,12 +20,6 @@
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#define VTKM_MATH_ASSERT(condition, message) \
|
||||
if (!(condition)) \
|
||||
{ \
|
||||
this->RaiseError(message); \
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace
|
||||
{
|
||||
|
@ -20,11 +20,6 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#define VTKM_MATH_ASSERT(condition, message) \
|
||||
if (!(condition)) \
|
||||
{ \
|
||||
this->RaiseError(message); \
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
namespace UnitTestMathNamespace
|
||||
@ -1088,7 +1083,7 @@ struct BitOpTests : public vtkm::exec::FunctorBase
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::CountSetBits(word), this->DumbCountBits(word)),
|
||||
"CountBits returned wrong value.");
|
||||
VTKM_MATH_ASSERT(test_equal(vtkm::FindFirstSetBit(word), this->DumbFindFirstSetBit(word)),
|
||||
"FindFirstSetBit returned wrong value.")
|
||||
"FindFirstSetBit returned wrong value.");
|
||||
}
|
||||
|
||||
VTKM_EXEC vtkm::Int32 DumbCountBits(T word) const
|
||||
|
Loading…
Reference in New Issue
Block a user