Update microunit test.

This commit is contained in:
davidjacnogueira
2016-11-25 13:17:45 +00:00
parent 0a636416ed
commit af9496de65

22
deps/microunit.h vendored
View File

@@ -1,5 +1,6 @@
/**
* @file microunit.h
* @version 0.1
* @author Sebastiao Salvador de Miranda (ssm)
* @brief Tiny library for cpp unit testing. Should work on any c++11 compiler.
*
@@ -59,7 +60,6 @@
#ifndef _MICROUNIT_MICROUNIT_H_
#define _MICROUNIT_MICROUNIT_H_
#include <string.h>
#include <unordered_map>
#include <map>
#include <string>
#include <vector>
@@ -111,7 +111,7 @@ void SetTerminalColor(int color_code) {
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(handler, &buffer_info);
SetConsoleTextAttribute(handler, ((buffer_info.wAttributes & 0xFFF0) |
(WORD)color_code));
(WORD)color_code));
#else
std::cout << ColorCodeToANSI(color_code);
#endif
@@ -224,7 +224,7 @@ public:
* @returns True if all tests pass, false otherwise.
*/
static bool Run() {
std::vector<std::string> failures;
std::vector<std::string> failures, sucesses;
// Iterate all registered unit tests
for (auto& unit : Instance().unitfunction_map_) {
@@ -240,12 +240,20 @@ public:
failures.push_back(unit.first);
} else {
TERMINAL_GOOD << "Passed test";
sucesses.push_back(unit.first);
}
}
std::cout
<< MICROUNIT_SEPARATOR << std::endl
<< MICROUNIT_SEPARATOR << std::endl;
TERMINAL_GOOD << "Passed " << sucesses.size()
<< " test cases:";
for (const auto& success_t : sucesses) {
TERMINAL_GOOD << success_t;
}
std::cout << MICROUNIT_SEPARATOR << std::endl;
// Output result summary
if (failures.empty()) {
TERMINAL_GOOD << "All tests passed";
@@ -303,7 +311,7 @@ private:
static UnitTester instance;
return instance;
}
std::unordered_map<std::string, UnitFunction> unitfunction_map_;
std::map<std::string, UnitFunction> unitfunction_map_;
};
}
@@ -329,7 +337,7 @@ private:
#define UNIT(FUNCTION) \
void FUNCTION(microunit::UnitFunctionResult*); \
REGISTER_UNIT(FUNCTION); \
void FUNCTION(microunit::UnitFunctionResult *__microunit_testresult)
void FUNCTION(microunit::UnitFunctionResult *__microunit_testresult)
/**
* @brief Pass the test and return from the test case.
@@ -359,11 +367,11 @@ FAIL(); \
}
/**
* @brief Check a particular test condition. If the condition holds, fail the
* @brief Check a particular test condition. If the condition holds, fail the
* test and return.
*/
#define ASSERT_FALSE(condition) if((condition)) { \
LOG_BAD << "Assert-false failed: " #condition << std::endl; \
FAIL(); \
}
#endif
#endif