Browse Source

Tests: PityUnit - Add termCol support

master
heck 4 years ago
parent
commit
023f6e8858
  1. 12
      src/PityUnit.hh
  2. 79
      src/PityUnit.hxx

12
src/PityUnit.hh

@ -7,6 +7,7 @@
#include <string>
#include <map>
#include "../../../src/pEpLog.hh"
#include "../../../src/std_utils.hh"
// Yes, the mem mgmt is purely static on purpose (so far)
@ -45,7 +46,7 @@ namespace pEp {
std::string processDir() const; // own process dir
// Read-Write
void setExecutionMode(ExecutionMode mode);
// void setExecutionMode(ExecutionMode mode);
static void setGlobalRootDir(const std::string& dir);
static std::string getGlobalRootDir();
@ -59,6 +60,9 @@ namespace pEp {
// logging service
void log(const std::string& msg) const;
void logRaw(const std::string& msg) const;
void logH1(const std::string& msg) const;
void logH2(const std::string& msg) const;
void logH3(const std::string& msg) const;
// internal logging
static bool debug_log_enabled;
@ -88,6 +92,8 @@ namespace pEp {
// Util
std::string _normalizeName(std::string name) const;
std::string _status_string(const std::string& msg) const;
Utils::Color colForProcNodeNr(int procNodeNr) const;
Utils::Color termColor() const;
// Dirs
void _ensureDir(const std::string& path) const;
@ -100,8 +106,10 @@ namespace pEp {
const NodeFunc _test_func;
ExecutionMode _exec_mode;
static std::string _global_root_dir;
std::map<const std::string, PityUnit&> _children; // map to guarantee uniqueness of sibling-names
int procNodeNr;
static int procNodesCount; // will be increased in everuy constructor
// internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;

79
src/PityUnit.hxx

@ -15,7 +15,7 @@
#include <sstream>
#include <exception>
using namespace pEp::Adapter::pEpLog;
//using namespace pEp::Adapter::pEpLog;
namespace pEp {
namespace PityTest11 {
@ -23,6 +23,8 @@ namespace pEp {
std::string PityUnit<T>::_global_root_dir = "./pitytest_data/";
template<class T>
bool PityUnit<T>::debug_log_enabled = false;
template<class T>
int PityUnit<T>::procNodesCount = 0;
// CONCSTRUCTORS
template<class T>
@ -38,6 +40,15 @@ namespace pEp {
logger_debug.set_instancename(getNodePath());
if (!_isRootNode()) {
parent->_addChildNode(*this);
// Inherit
procNodeNr = _parent->procNodeNr;
//Or update if procNode
if (_isProcessNode()) {
procNodesCount++;
procNodeNr = procNodesCount;
}
} else {
procNodeNr = procNodesCount;
}
}
@ -125,11 +136,11 @@ namespace pEp {
}
}
template<class T>
void PityUnit<T>::setExecutionMode(ExecutionMode mode)
{
_exec_mode = mode;
}
// template<class T>
// void PityUnit<T>::setExecutionMode(ExecutionMode mode)
// {
// _exec_mode = mode;
// }
// static
template<>
@ -254,14 +265,32 @@ namespace pEp {
builder << getNodePathShort();
builder << "] - ";
builder << msg;
builder << std::endl;
logRaw(builder.str());
}
template<class T>
void PityUnit<T>::logRaw(const std::string& msg) const
{
std::cerr << msg << std::endl;
Adapter::pEpLog::log(msg, termColor());
}
template<class T>
void PityUnit<T>::logH1(const std::string& msg) const
{
Adapter::pEpLog::logH1(msg, termColor());
}
template<class T>
void PityUnit<T>::logH2(const std::string& msg) const
{
Adapter::pEpLog::logH2(msg, termColor());
}
template<class T>
void PityUnit<T>::logH3(const std::string& msg) const
{
Adapter::pEpLog::logH3(msg, termColor());
}
@ -282,11 +311,11 @@ namespace pEp {
_test_func(*this);
logH3(_status_string("SUCCESS"));
} catch (const std::exception& e) {
log("reason: " + std::string(e.what()));
logRaw("reason: " + std::string(e.what()));
logH3(_status_string("FAILED"));
}
} else {
log("No function to execute");
logRaw("No function to execute");
}
}
@ -402,6 +431,36 @@ namespace pEp {
return ret;
}
template<class T>
Utils::Color PityUnit<T>::colForProcNodeNr(int procNodeNr) const
{
switch (procNodeNr) {
case 0:
return Utils::Color::WHITE;
case 1:
return Utils::Color::CYAN;
case 2:
return Utils::Color::MAGENTA;
case 3:
return Utils::Color::BLUE;
case 4:
return Utils::Color::GREEN;
case 5:
return Utils::Color::YELLOW;
case 6:
return Utils::Color::RED;
default:
return Utils::Color::WHITE;
}
}
template<class T>
Utils::Color PityUnit<T>::termColor() const
{
return colForProcNodeNr(procNodeNr);
}
template<class T>
void PityUnit<T>::_ensureDir(const std::string& path) const
{

Loading…
Cancel
Save