Fixed the output of unit tests

* XML format wasn't correct because of trailing info output
* Error messages did not get printed
This commit is contained in:
Matthias Koefferlein 2017-08-28 22:22:01 +02:00
parent 6d823c46f3
commit 749382b1a4
5 changed files with 90 additions and 73 deletions

View File

@ -302,6 +302,8 @@ main_cont (int argc, char **argv)
{ {
int result = 0; int result = 0;
ut::TestConsole console (stdout);
try { try {
pya::PythonInterpreter::initialize (); pya::PythonInterpreter::initialize ();
@ -353,6 +355,10 @@ main_cont (int argc, char **argv)
static char av3[] = "-rx"; // No mplicit macros static char av3[] = "-rx"; // No mplicit macros
char *av[] = { av0, av1, av2, av3, 0 }; char *av[] = { av0, av1, av2, av3, 0 };
lay::Application app (ac, av, false); lay::Application app (ac, av, false);
app.ruby_interpreter ().push_console (&console);
app.python_interpreter ().push_console (&console);
app.autorun (); app.autorun ();
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
@ -418,55 +424,54 @@ main_cont (int argc, char **argv)
} }
ut::set_verbose (verbose); ut::set_verbose (verbose);
ut::set_xml_format (xml_format);
ut::set_continue_flag (continue_flag); ut::set_continue_flag (continue_flag);
ut::set_debug_mode (debug_mode); ut::set_debug_mode (debug_mode);
ut::TestConsole console (stdout, xml_format);
ut::noctrl << tl::replicate ("=", console.real_columns ());
ut::noctrl << "Entering KLayout test suite";
tl::info << "TESTSRC=" << ut::testsrc ();
tl::info << "TESTTMP=" << tl::to_string (QDir (tl::to_qstring (ut::testtmp ())).absolutePath ());
const std::vector<ut::TestBase *> *selected_tests = 0;
std::vector<ut::TestBase *> subset;
if (! test_list.empty ()) {
selected_tests = &subset;
tl::info << "Selected tests:";
for (std::vector<ut::TestBase *>::const_iterator i = ut::Registrar::instance()->tests ().begin (); i != ut::Registrar::instance()->tests ().end (); ++i) {
bool exclude = false;
for (std::vector<std::string>::const_iterator m = exclude_test_list.begin (); m != exclude_test_list.end () && !exclude; ++m) {
QRegExp re (tl::to_qstring (*m), Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.indexIn (tl::to_qstring ((*i)->name ())) == 0) {
exclude = true;
}
}
for (std::vector<std::string>::const_iterator m = test_list.begin (); !exclude && m != test_list.end (); ++m) {
QRegExp re (tl::to_qstring (*m), Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.indexIn (tl::to_qstring ((*i)->name ())) == 0) {
tl::info << " " << (*i)->name ();
subset.push_back (*i);
break;
}
}
}
} else {
selected_tests = &ut::Registrar::instance()->tests ();
}
try { try {
ut::ctrl << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; ut::ctrl << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
ut::ctrl << "<testsuites>"; ut::ctrl << "<testsuites>";
ut::noctrl << tl::replicate ("=", console.real_columns ());
ut::noctrl << "Entering KLayout test suite";
ut::noctrl << "TESTSRC=" << ut::testsrc ();
ut::noctrl << "TESTTMP=" << tl::to_string (QDir (tl::to_qstring (ut::testtmp ())).absolutePath ());
const std::vector<ut::TestBase *> *selected_tests = 0;
std::vector<ut::TestBase *> subset;
if (! test_list.empty ()) {
selected_tests = &subset;
ut::noctrl << "Selected tests:";
for (std::vector<ut::TestBase *>::const_iterator i = ut::Registrar::instance()->tests ().begin (); i != ut::Registrar::instance()->tests ().end (); ++i) {
bool exclude = false;
for (std::vector<std::string>::const_iterator m = exclude_test_list.begin (); m != exclude_test_list.end () && !exclude; ++m) {
QRegExp re (tl::to_qstring (*m), Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.indexIn (tl::to_qstring ((*i)->name ())) == 0) {
exclude = true;
}
}
for (std::vector<std::string>::const_iterator m = test_list.begin (); !exclude && m != test_list.end (); ++m) {
QRegExp re (tl::to_qstring (*m), Qt::CaseInsensitive, QRegExp::Wildcard);
if (re.indexIn (tl::to_qstring ((*i)->name ())) == 0) {
ut::noctrl << " " << (*i)->name ();
subset.push_back (*i);
break;
}
}
}
} else {
selected_tests = &ut::Registrar::instance()->tests ();
}
result = run_tests (*selected_tests, editable, non_editable, slow, app, gsi_coverage, class_names); result = run_tests (*selected_tests, editable, non_editable, slow, app, gsi_coverage, class_names);
ut::ctrl << "</testsuites>"; ut::ctrl << "</testsuites>";

View File

@ -45,6 +45,7 @@ namespace ut
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
static bool s_verbose_flag = false; static bool s_verbose_flag = false;
static bool s_xml_format = false;
static bool s_debug_mode = false; static bool s_debug_mode = false;
static bool s_continue_flag = false; static bool s_continue_flag = false;
@ -58,6 +59,16 @@ void set_verbose (bool f)
s_verbose_flag = f; s_verbose_flag = f;
} }
bool xml_format ()
{
return s_xml_format;
}
void set_xml_format (bool f)
{
s_xml_format = f;
}
void set_continue_flag (bool f) void set_continue_flag (bool f)
{ {
s_continue_flag = f; s_continue_flag = f;

View File

@ -64,6 +64,16 @@ UT_PUBLIC bool verbose ();
*/ */
UT_PUBLIC void set_verbose (bool v); UT_PUBLIC void set_verbose (bool v);
/**
* @brief Returns true if XML output is enabled (JUnit format)
*/
UT_PUBLIC bool xml_format ();
/**
* @brief Sets XML format
*/
UT_PUBLIC void set_xml_format (bool x);
/** /**
* @brief Enables or disables "continue" mode * @brief Enables or disables "continue" mode
* In continue mode, the execution will proceed even in case of an error. * In continue mode, the execution will proceed even in case of an error.

View File

@ -184,21 +184,21 @@ public:
protected: protected:
virtual void puts (const char *s) virtual void puts (const char *s)
{ {
if (m_with_xml == TestConsole::instance ()->xml_format ()) { if (m_with_xml == ut::xml_format ()) {
TestConsole::instance ()->raw_write (s); TestConsole::instance ()->raw_write (s);
} }
} }
virtual void endl () virtual void endl ()
{ {
if (m_with_xml == TestConsole::instance ()->xml_format ()) { if (m_with_xml == ut::xml_format ()) {
TestConsole::instance ()->raw_write ("\n"); TestConsole::instance ()->raw_write ("\n");
} }
} }
virtual void end () virtual void end ()
{ {
if (m_with_xml == TestConsole::instance ()->xml_format ()) { if (m_with_xml == ut::xml_format ()) {
TestConsole::instance ()->end (); TestConsole::instance ()->end ();
TestConsole::instance ()->flush (); TestConsole::instance ()->flush ();
} }
@ -206,7 +206,7 @@ protected:
virtual void begin () virtual void begin ()
{ {
if (m_with_xml == TestConsole::instance ()->xml_format ()) { if (m_with_xml == ut::xml_format ()) {
TestConsole::instance ()->begin_info (); TestConsole::instance ()->begin_info ();
} }
} }
@ -223,16 +223,16 @@ const char *ANSI_BLUE = "\033[34m";
const char *ANSI_GREEN = "\033[32m"; const char *ANSI_GREEN = "\033[32m";
const char *ANSI_RESET = "\033[0m"; const char *ANSI_RESET = "\033[0m";
TestConsole::TestConsole (FILE *file, bool xml_format) TestConsole::TestConsole (FILE *file)
: m_file (file), m_xml_format (xml_format), m_col (0), m_max_col (250), m_columns (50), m_rows (0), m_is_tty (false) : m_file (file), m_col (0), m_max_col (250), m_columns (50), m_rows (0), m_file_is_tty (false)
{ {
ms_instance = this; ms_instance = this;
m_indent = 4; m_indent = 4;
m_is_tty = isatty (fileno (file)) && ! xml_format; m_file_is_tty = isatty (fileno (file));
#if !defined(_WIN32) #if !defined(_WIN32)
if (m_is_tty) { if (m_file_is_tty) {
struct winsize ws; struct winsize ws;
ioctl (fileno (stdout), TIOCGWINSZ, &ws); ioctl (fileno (stdout), TIOCGWINSZ, &ws);
m_columns = std::max (0, (int) ws.ws_col); m_columns = std::max (0, (int) ws.ws_col);
@ -276,10 +276,17 @@ TestConsole::flush ()
fflush (m_file); fflush (m_file);
} }
bool
TestConsole::is_tty ()
{
// NOTE: this assumes we are delivering to stdout
return m_file_is_tty && ! ut::xml_format ();
}
void void
TestConsole::begin_error () TestConsole::begin_error ()
{ {
if (m_is_tty) { if (is_tty ()) {
fputs (ANSI_RED, m_file); fputs (ANSI_RED, m_file);
} }
} }
@ -287,7 +294,7 @@ TestConsole::begin_error ()
void void
TestConsole::begin_info () TestConsole::begin_info ()
{ {
if (m_is_tty) { if (is_tty ()) {
fputs (ANSI_GREEN, m_file); fputs (ANSI_GREEN, m_file);
} }
} }
@ -295,7 +302,7 @@ TestConsole::begin_info ()
void void
TestConsole::begin_warn () TestConsole::begin_warn ()
{ {
if (m_is_tty) { if (is_tty ()) {
fputs (ANSI_BLUE, m_file); fputs (ANSI_BLUE, m_file);
} }
} }
@ -303,7 +310,7 @@ TestConsole::begin_warn ()
void void
TestConsole::end () TestConsole::end ()
{ {
if (m_is_tty) { if (is_tty ()) {
fputs (ANSI_RESET, m_file); fputs (ANSI_RESET, m_file);
} }
} }
@ -311,7 +318,7 @@ TestConsole::end ()
void void
TestConsole::basic_write (const char *s) TestConsole::basic_write (const char *s)
{ {
if (m_xml_format) { if (ut::xml_format ()) {
for (const char *cp = s; *cp; ++cp) { for (const char *cp = s; *cp; ++cp) {
if (*cp == '&') { if (*cp == '&') {
@ -384,9 +391,6 @@ TestConsole::redirect ()
tl::log.add (new ut::InfoChannel (10), true); tl::log.add (new ut::InfoChannel (10), true);
tl::error.clear (); tl::error.clear ();
tl::error.add (new ut::ErrorChannel (), true); tl::error.add (new ut::ErrorChannel (), true);
ut::ruby_interpreter ()->push_console (this);
ut::python_interpreter ()->push_console (this);
} }
void void
@ -397,9 +401,6 @@ TestConsole::restore ()
tl::info.clear (); tl::info.clear ();
tl::log.clear (); tl::log.clear ();
tl::error.clear (); tl::error.clear ();
ut::ruby_interpreter ()->remove_console (this);
ut::python_interpreter ()->remove_console (this);
} }
TestConsole *TestConsole::ms_instance = 0; TestConsole *TestConsole::ms_instance = 0;

View File

@ -78,7 +78,7 @@ public:
return ms_instance; return ms_instance;
} }
TestConsole (FILE *file, bool xml_format); TestConsole (FILE *file);
~TestConsole (); ~TestConsole ();
int indent () const int indent () const
@ -86,20 +86,11 @@ public:
return m_indent; return m_indent;
} }
bool xml_format () const
{
return m_xml_format;
}
void write_str (const char *text, output_stream os); void write_str (const char *text, output_stream os);
void raw_write (const char *text); void raw_write (const char *text);
virtual void flush (); virtual void flush ();
virtual bool is_tty () virtual bool is_tty ();
{
// NOTE: this assumes we are delivering to stdout
return m_is_tty;
}
virtual int columns () virtual int columns ()
{ {
@ -124,11 +115,10 @@ public:
private: private:
FILE *m_file; FILE *m_file;
bool m_xml_format;
int m_col; int m_col;
int m_max_col; int m_max_col;
int m_columns, m_rows; int m_columns, m_rows;
bool m_is_tty; bool m_file_is_tty;
int m_indent; int m_indent;
static TestConsole *ms_instance; static TestConsole *ms_instance;