Update deps (fix microunit bug).

This commit is contained in:
davidjacnogueira
2017-10-11 01:16:35 +01:00
parent 66aabc79b3
commit f924edd50a

136
deps/microunit.h vendored
View File

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