//copied and modified from https://github.com/Submanifold/Aleph 's test setup (MIT)
|
|
|
|
#ifndef UNIT_TEST_BASE_H__
|
|
#define UNIT_TEST_BASE_H__
|
|
|
|
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace UnitTests
|
|
{
|
|
|
|
#define ASSERT_EQUAL( x, y ) \
|
|
{ \
|
|
if( ( x ) != ( y ) ) \
|
|
{ \
|
|
throw std::runtime_error( std::string( __FILE__ ) \
|
|
+ std::string( ":" ) \
|
|
+ std::to_string( __LINE__ ) \
|
|
+ std::string( " in " ) \
|
|
+ std::string( __PRETTY_FUNCTION__ ) \
|
|
+ std::string( ": " ) \
|
|
+ std::to_string( ( x ) ) \
|
|
+ std::string( " != " ) \
|
|
+ std::to_string( ( y ) ) \
|
|
); \
|
|
} \
|
|
}
|
|
|
|
|
|
#define ASSERT_THROW( condition ) \
|
|
{ \
|
|
if( !( condition ) ) \
|
|
{ \
|
|
throw std::runtime_error( std::string( "Assert Failed: " ) \
|
|
+ std::string( __FILE__ ) \
|
|
+ std::string( ":" ) \
|
|
+ std::to_string( __LINE__ ) \
|
|
+ std::string( " in " ) \
|
|
+ std::string( __PRETTY_FUNCTION__ ) \
|
|
); \
|
|
} \
|
|
}
|
|
|
|
#define EXPECT_EXCEPTION( expression, exception ) \
|
|
{ \
|
|
try \
|
|
{ \
|
|
( expression ); \
|
|
} \
|
|
catch( exception& e ) \
|
|
{ \
|
|
} \
|
|
catch( ... ) \
|
|
{ \
|
|
throw std::runtime_error( std::string( __FILE__ ) \
|
|
+ std::string( ":" ) \
|
|
+ std::to_string( __LINE__ ) \
|
|
+ std::string( " in " ) \
|
|
+ std::string( __PRETTY_FUNCTION__ ) \
|
|
); \
|
|
} \
|
|
}
|
|
|
|
#define TEST_BEGIN( name )\
|
|
{\
|
|
std::cerr << "-- Running test \"" << name << "\"...";\
|
|
}
|
|
|
|
#define TEST_END() \
|
|
{\
|
|
std::cerr << "finished\n";\
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#endif
|