mirror of
https://github.com/davidalbertonogueira/MLP.git
synced 2025-12-17 04:14:41 +03:00
Update deps (fix microunit bug).
This commit is contained in:
136
deps/microunit.h
vendored
136
deps/microunit.h
vendored
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file microunit.h
|
* @file microunit.h
|
||||||
* @version 0.1
|
* @version 0.2
|
||||||
* @author Sebastiao Salvador de Miranda (ssm)
|
* @author Sebastiao Salvador de Miranda (ssm)
|
||||||
* @brief Tiny library for cpp unit testing. Should work on any c++11 compiler.
|
* @brief Tiny library for cpp unit testing. Should work on any c++11 compiler.
|
||||||
*
|
*
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2016, Sebastiao Salvador de Miranda.
|
* @copyright Copyright (c) 2016-2017, Sebastiao Salvador de Miranda.
|
||||||
* All rights reserved. See licence below.
|
* All rights reserved. See licence below.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -82,30 +82,30 @@ strrchr(__FILE__, '/') + 1 : __FILE__)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace microunit {
|
namespace microunit {
|
||||||
const static int COLORCODE_GREY{ 7 };
|
const static int COLORCODE_GREY{ 7 };
|
||||||
const static int COLORCODE_GREEN{ 10 };
|
const static int COLORCODE_GREEN{ 10 };
|
||||||
const static int COLORCODE_RED{ 12 };
|
const static int COLORCODE_RED{ 12 };
|
||||||
const static int COLORCODE_YELLOW{ 14 };
|
const static int COLORCODE_YELLOW{ 14 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper class to convert from color codes to ansi escape codes
|
* @brief Helper class to convert from color codes to ansi escape codes
|
||||||
* Used to print color in non-win32 systems.
|
* Used to print color in non-win32 systems.
|
||||||
*/
|
*/
|
||||||
std::string ColorCodeToANSI(const int color_code) {
|
std::string ColorCodeToANSI(const int color_code) {
|
||||||
switch (color_code) {
|
switch (color_code) {
|
||||||
case COLORCODE_GREY: return "\033[22;37m";
|
case COLORCODE_GREY: return "\033[22;37m";
|
||||||
case COLORCODE_GREEN: return "\033[01;31m";
|
case COLORCODE_GREEN: return "\033[01;32m";
|
||||||
case COLORCODE_RED: return "\033[01;32m";
|
case COLORCODE_RED: return "\033[01;31m";
|
||||||
case COLORCODE_YELLOW: return "\033[01;33m";
|
case COLORCODE_YELLOW: return "\033[01;33m";
|
||||||
default: return "";
|
default: return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper function to change the current terminal color.
|
* @brief Helper function to change the current terminal color.
|
||||||
* @param [in] color_code Input color code.
|
* @param [in] color_code Input color code.
|
||||||
*/
|
*/
|
||||||
void SetTerminalColor(int color_code) {
|
void SetTerminalColor(int color_code) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
|
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
|
||||||
@@ -115,49 +115,49 @@ void SetTerminalColor(int color_code) {
|
|||||||
#else
|
#else
|
||||||
std::cout << ColorCodeToANSI(color_code);
|
std::cout << ColorCodeToANSI(color_code);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper class to be used as a iostream manipulator and change the
|
* @brief Helper class to be used as a iostream manipulator and change the
|
||||||
* terminal color.
|
* terminal color.
|
||||||
*/
|
*/
|
||||||
class Color {
|
class Color {
|
||||||
public:
|
public:
|
||||||
Color(int code) : code_(code) {}
|
Color(int code) : code_(code) {}
|
||||||
void Set() const {
|
void Set() const {
|
||||||
SetTerminalColor(code_);
|
SetTerminalColor(code_);
|
||||||
}
|
}
|
||||||
int code() const { return code_; }
|
int code() const { return code_; }
|
||||||
private:
|
private:
|
||||||
int code_;
|
int code_;
|
||||||
};
|
};
|
||||||
|
|
||||||
const static Color Grey{ COLORCODE_GREY };
|
const static Color Grey{ COLORCODE_GREY };
|
||||||
const static Color Green{ COLORCODE_GREEN };
|
const static Color Green{ COLORCODE_GREEN };
|
||||||
const static Color Red{ COLORCODE_RED };
|
const static Color Red{ COLORCODE_RED };
|
||||||
const static Color Yellow{ COLORCODE_YELLOW };
|
const static Color Yellow{ COLORCODE_YELLOW };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper class to be used in a cout streaming statement. Resets to
|
* @brief Helper class to be used in a cout streaming statement. Resets to
|
||||||
* the default terminal color upon statement completion.
|
* the default terminal color upon statement completion.
|
||||||
*/
|
*/
|
||||||
class SaveColor {
|
class SaveColor {
|
||||||
public:
|
public:
|
||||||
~SaveColor() {
|
~SaveColor() {
|
||||||
SetTerminalColor(Grey.code());
|
SetTerminalColor(Grey.code());
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper class to be used in a cout streaming statement. Puts a line
|
* @brief Helper class to be used in a cout streaming statement. Puts a line
|
||||||
* break upon statement completion.
|
* break upon statement completion.
|
||||||
*/
|
*/
|
||||||
class EndingLineBreak {
|
class EndingLineBreak {
|
||||||
public:
|
public:
|
||||||
~EndingLineBreak() {
|
~EndingLineBreak() {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Operator to allow using SaveColor class with an ostream */
|
/** @brief Operator to allow using SaveColor class with an ostream */
|
||||||
@@ -201,24 +201,24 @@ microunit::EndingLineBreak{} << microunit::Green << "[ ] "
|
|||||||
#define LOG_GOOD TERMINAL_GOOD << __FILENAME__ << ":" << __LINE__ << ": "
|
#define LOG_GOOD TERMINAL_GOOD << __FILENAME__ << ":" << __LINE__ << ": "
|
||||||
|
|
||||||
namespace microunit {
|
namespace microunit {
|
||||||
/**
|
/**
|
||||||
* @brief Result of a unit test.
|
* @brief Result of a unit test.
|
||||||
*/
|
*/
|
||||||
struct UnitFunctionResult {
|
struct UnitFunctionResult {
|
||||||
bool success{ true };
|
bool success{ true };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unit test function type.
|
* @brief Unit test function type.
|
||||||
*/
|
*/
|
||||||
typedef void(*UnitFunction)(UnitFunctionResult*);
|
typedef void(*UnitFunction)(UnitFunctionResult*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Main class for unit test management. This class is a singleton
|
* @brief Main class for unit test management. This class is a singleton
|
||||||
* and maintains a list of all registered unit test cases.
|
* and maintains a list of all registered unit test cases.
|
||||||
*/
|
*/
|
||||||
class UnitTester {
|
class UnitTester {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Run all the registered unit test cases.
|
* @brief Run all the registered unit test cases.
|
||||||
* @returns True if all tests pass, false otherwise.
|
* @returns True if all tests pass, false otherwise.
|
||||||
@@ -226,6 +226,10 @@ public:
|
|||||||
static bool Run() {
|
static bool Run() {
|
||||||
std::vector<std::string> failures, sucesses;
|
std::vector<std::string> failures, sucesses;
|
||||||
|
|
||||||
|
TERMINAL_INFO
|
||||||
|
<< "Will run " << Instance().unitfunction_map_.size()
|
||||||
|
<< " test cases";
|
||||||
|
|
||||||
// Iterate all registered unit tests
|
// Iterate all registered unit tests
|
||||||
for (auto& unit : Instance().unitfunction_map_) {
|
for (auto& unit : Instance().unitfunction_map_) {
|
||||||
std::cout << MICROUNIT_SEPARATOR << std::endl;
|
std::cout << MICROUNIT_SEPARATOR << std::endl;
|
||||||
@@ -238,7 +242,8 @@ public:
|
|||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
TERMINAL_BAD << "Failed test";
|
TERMINAL_BAD << "Failed test";
|
||||||
failures.push_back(unit.first);
|
failures.push_back(unit.first);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
TERMINAL_GOOD << "Passed test";
|
TERMINAL_GOOD << "Passed test";
|
||||||
sucesses.push_back(unit.first);
|
sucesses.push_back(unit.first);
|
||||||
}
|
}
|
||||||
@@ -259,7 +264,8 @@ public:
|
|||||||
TERMINAL_GOOD << "All tests passed";
|
TERMINAL_GOOD << "All tests passed";
|
||||||
std::cout << MICROUNIT_SEPARATOR << std::endl;
|
std::cout << MICROUNIT_SEPARATOR << std::endl;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
TERMINAL_BAD << "Failed " << failures.size()
|
TERMINAL_BAD << "Failed " << failures.size()
|
||||||
<< " test cases:";
|
<< " test cases:";
|
||||||
for (const auto& failure : failures) {
|
for (const auto& failure : failures) {
|
||||||
@@ -305,14 +311,14 @@ public:
|
|||||||
UnitTester(const UnitTester&) = delete;
|
UnitTester(const UnitTester&) = delete;
|
||||||
UnitTester(UnitTester&&) = delete;
|
UnitTester(UnitTester&&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnitTester() {};
|
UnitTester() {};
|
||||||
static UnitTester& Instance() {
|
static UnitTester& Instance() {
|
||||||
static UnitTester instance;
|
static UnitTester instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
std::map<std::string, UnitFunction> unitfunction_map_;
|
std::map<std::string, UnitFunction> unitfunction_map_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MACROCAT_NEXP(A, B) A ## B
|
#define MACROCAT_NEXP(A, B) A ## B
|
||||||
|
|||||||
Reference in New Issue
Block a user