forked from Alepha/Alepha
Move the colours stuff out of Testing and into console.
This commit is contained in:
@ -8,6 +8,9 @@ static_assert( __cplusplus > 201700, "C++17 Required" );
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include <boost/core/demangle.hpp>
|
||||||
|
|
||||||
#include <Alepha/Meta/is_vector.h>
|
#include <Alepha/Meta/is_vector.h>
|
||||||
#include <Alepha/Meta/product_type_decay.h>
|
#include <Alepha/Meta/product_type_decay.h>
|
||||||
@ -25,6 +28,15 @@ namespace Alepha::Hydrogen::Testing
|
|||||||
template< auto > struct TableTest;
|
template< auto > struct TableTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void breakpoint() {}
|
||||||
|
|
||||||
|
namespace C
|
||||||
|
{
|
||||||
|
const bool debug= false;
|
||||||
|
const bool debugCaseTypes= false or C::debug;
|
||||||
|
using namespace Alepha::exports::console::C;
|
||||||
|
}
|
||||||
|
|
||||||
using namespace Utility::exports::evaluation;
|
using namespace Utility::exports::evaluation;
|
||||||
|
|
||||||
template< typename RetVal, typename ... Args, RetVal (*function)( Args... ) >
|
template< typename RetVal, typename ... Args, RetVal (*function)( Args... ) >
|
||||||
@ -48,6 +60,8 @@ namespace Alepha::Hydrogen::Testing
|
|||||||
int failureCount= 0;
|
int failureCount= 0;
|
||||||
for( const auto &[ comment, params, expected ]: tests )
|
for( const auto &[ comment, params, expected ]: tests )
|
||||||
{
|
{
|
||||||
|
if( C::debugCaseTypes ) std::cerr << boost::core::demangle( typeid( params ).name() ) << std::endl;
|
||||||
|
breakpoint();
|
||||||
if( std::apply( function, params ) != expected )
|
if( std::apply( function, params ) != expected )
|
||||||
{
|
{
|
||||||
std::cout << C::red << " FAILURE" << C::normal << ": " << comment << std::endl;
|
std::cout << C::red << " FAILURE" << C::normal << ": " << comment << std::endl;
|
||||||
@ -60,9 +74,10 @@ namespace Alepha::Hydrogen::Testing
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VectorCases;
|
//struct VectorCases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef DISABLED
|
||||||
template< typename RetVal, typename ... Args, RetVal (*function)( Args... ) >
|
template< typename RetVal, typename ... Args, RetVal (*function)( Args... ) >
|
||||||
struct TableTest< function >::VectorCases
|
struct TableTest< function >::VectorCases
|
||||||
{
|
{
|
||||||
@ -112,6 +127,7 @@ namespace Alepha::Hydrogen::Testing
|
|||||||
return failureCount;
|
return failureCount;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace exports::table_test
|
namespace exports::table_test
|
||||||
|
|||||||
@ -14,6 +14,7 @@ static_assert( __cplusplus > 201700, "C++17 Required" );
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <Alepha/console.h>
|
#include <Alepha/console.h>
|
||||||
|
#include <Alepha/types.h>
|
||||||
|
|
||||||
namespace Alepha::Hydrogen::Testing
|
namespace Alepha::Hydrogen::Testing
|
||||||
{
|
{
|
||||||
@ -200,7 +201,7 @@ namespace Alepha::Hydrogen::Testing
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline int
|
[[nodiscard]] inline int
|
||||||
runAllTests( const unsigned argcnt, const char *const *const argvec )
|
runAllTests( const argcnt_t argcnt, const argvec_t argvec )
|
||||||
{
|
{
|
||||||
return runAllTests( { argvec + 1, argvec + argcnt } );
|
return runAllTests( { argvec + 1, argvec + argcnt } );
|
||||||
}
|
}
|
||||||
|
|||||||
45
Testing/test2.cc
Normal file
45
Testing/test2.cc
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
static_assert( __cplusplus > 201700, "C++17 Required" );
|
||||||
|
|
||||||
|
#include <Alepha/Testing/TableTest.h>
|
||||||
|
#include <Alepha/Testing/test.h>
|
||||||
|
#include <Alepha/Utility/evaluation.h>
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main( const int argcnt, const char *const *const argvec )
|
||||||
|
{
|
||||||
|
return Alepha::Testing::runAllTests( argcnt, argvec );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using namespace Alepha::Testing::exports;
|
||||||
|
using namespace Alepha::Utility::exports::evaluation;
|
||||||
|
|
||||||
|
int
|
||||||
|
add( int a, int b )
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto basic_test= "basic_test"_test <=[]
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto test= "addition.two.test"_test <=TableTest< add >::Cases
|
||||||
|
{
|
||||||
|
{ "Basic Smoke Test", { 2, 2 }, 4 },
|
||||||
|
{ "Lefthand identity", { 0, 25 }, 25 },
|
||||||
|
{ "Righthand identity", { 25, 0 }, 25 },
|
||||||
|
};
|
||||||
|
|
||||||
|
auto alltests= enroll <=[]
|
||||||
|
{
|
||||||
|
"addition.two.local"_test <=TableTest< add >::Cases
|
||||||
|
{
|
||||||
|
{ "Negative case", { -10, -20 }, -30 },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
62
console.h
62
console.h
@ -17,9 +17,65 @@ namespace Alepha::Hydrogen
|
|||||||
namespace C
|
namespace C
|
||||||
{
|
{
|
||||||
const std::string csi= "\e[";
|
const std::string csi= "\e[";
|
||||||
const std::string green= C::csi + "32m";
|
const std::string color_code= "m";
|
||||||
const std::string red= C::csi + "31m";
|
|
||||||
const std::string normal= C::csi + "0m";
|
enum Layer
|
||||||
|
{
|
||||||
|
fg_code= '3',
|
||||||
|
bg_code= '4',
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Color : char
|
||||||
|
{
|
||||||
|
black= '0',
|
||||||
|
red= '1',
|
||||||
|
green= '2',
|
||||||
|
brown= '3',
|
||||||
|
blue= '4',
|
||||||
|
magenta= '5',
|
||||||
|
cyan= '6',
|
||||||
|
white= '7',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
using C::Layer;
|
||||||
|
using C::Color;
|
||||||
|
|
||||||
|
inline std::string
|
||||||
|
make_color( const Layer layer, const Color color )
|
||||||
|
{
|
||||||
|
return C::csi + char(layer) + char(color) + C::color_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace C
|
||||||
|
{
|
||||||
|
inline namespace exports
|
||||||
|
{
|
||||||
|
const std::string normal= C::csi + '0' + color_code;
|
||||||
|
|
||||||
|
inline namespace fg
|
||||||
|
{
|
||||||
|
const std::string black= make_color( C::fg_code, C::Color::black );
|
||||||
|
const std::string red= make_color( C::fg_code, C::Color::red );
|
||||||
|
const std::string green= make_color( C::fg_code, C::Color::green );
|
||||||
|
const std::string brown= make_color( C::fg_code, C::Color::brown );
|
||||||
|
const std::string blue= make_color( C::fg_code, C::Color::blue );
|
||||||
|
const std::string magenta= make_color( C::fg_code, C::Color::magenta );
|
||||||
|
const std::string cyan= make_color( C::fg_code, C::Color::cyan );
|
||||||
|
const std::string white= make_color( C::fg_code, C::Color::white );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace bg
|
||||||
|
{
|
||||||
|
const std::string black= make_color( C::bg_code, C::Color::black );
|
||||||
|
const std::string red= make_color( C::bg_code, C::Color::red );
|
||||||
|
const std::string green= make_color( C::bg_code, C::Color::green );
|
||||||
|
const std::string brown= make_color( C::bg_code, C::Color::brown );
|
||||||
|
const std::string blue= make_color( C::bg_code, C::Color::blue );
|
||||||
|
const std::string magenta= make_color( C::bg_code, C::Color::magenta );
|
||||||
|
const std::string cyan= make_color( C::bg_code, C::Color::cyan );
|
||||||
|
const std::string white= make_color( C::bg_code, C::Color::white );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace exports
|
namespace exports
|
||||||
|
|||||||
Reference in New Issue
Block a user