mirror of https://github.com/KLayout/klayout.git
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:
parent
6d823c46f3
commit
749382b1a4
|
|
@ -302,6 +302,8 @@ main_cont (int argc, char **argv)
|
|||
{
|
||||
int result = 0;
|
||||
|
||||
ut::TestConsole console (stdout);
|
||||
|
||||
try {
|
||||
|
||||
pya::PythonInterpreter::initialize ();
|
||||
|
|
@ -353,6 +355,10 @@ main_cont (int argc, char **argv)
|
|||
static char av3[] = "-rx"; // No mplicit macros
|
||||
char *av[] = { av0, av1, av2, av3, 0 };
|
||||
lay::Application app (ac, av, false);
|
||||
|
||||
app.ruby_interpreter ().push_console (&console);
|
||||
app.python_interpreter ().push_console (&console);
|
||||
|
||||
app.autorun ();
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
|
|
@ -418,55 +424,54 @@ main_cont (int argc, char **argv)
|
|||
}
|
||||
|
||||
ut::set_verbose (verbose);
|
||||
ut::set_xml_format (xml_format);
|
||||
ut::set_continue_flag (continue_flag);
|
||||
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 = ⊂
|
||||
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 {
|
||||
|
||||
ut::ctrl << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
|
||||
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 = ⊂
|
||||
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);
|
||||
|
||||
ut::ctrl << "</testsuites>";
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace ut
|
|||
// --------------------------------------------------------------------------------------
|
||||
|
||||
static bool s_verbose_flag = false;
|
||||
static bool s_xml_format = false;
|
||||
static bool s_debug_mode = false;
|
||||
static bool s_continue_flag = false;
|
||||
|
||||
|
|
@ -58,6 +59,16 @@ void set_verbose (bool 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)
|
||||
{
|
||||
s_continue_flag = f;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ UT_PUBLIC bool verbose ();
|
|||
*/
|
||||
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
|
||||
* In continue mode, the execution will proceed even in case of an error.
|
||||
|
|
|
|||
|
|
@ -184,21 +184,21 @@ public:
|
|||
protected:
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void endl ()
|
||||
{
|
||||
if (m_with_xml == TestConsole::instance ()->xml_format ()) {
|
||||
if (m_with_xml == ut::xml_format ()) {
|
||||
TestConsole::instance ()->raw_write ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
virtual void end ()
|
||||
{
|
||||
if (m_with_xml == TestConsole::instance ()->xml_format ()) {
|
||||
if (m_with_xml == ut::xml_format ()) {
|
||||
TestConsole::instance ()->end ();
|
||||
TestConsole::instance ()->flush ();
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ protected:
|
|||
|
||||
virtual void begin ()
|
||||
{
|
||||
if (m_with_xml == TestConsole::instance ()->xml_format ()) {
|
||||
if (m_with_xml == ut::xml_format ()) {
|
||||
TestConsole::instance ()->begin_info ();
|
||||
}
|
||||
}
|
||||
|
|
@ -223,16 +223,16 @@ const char *ANSI_BLUE = "\033[34m";
|
|||
const char *ANSI_GREEN = "\033[32m";
|
||||
const char *ANSI_RESET = "\033[0m";
|
||||
|
||||
TestConsole::TestConsole (FILE *file, bool xml_format)
|
||||
: 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)
|
||||
TestConsole::TestConsole (FILE *file)
|
||||
: m_file (file), m_col (0), m_max_col (250), m_columns (50), m_rows (0), m_file_is_tty (false)
|
||||
{
|
||||
ms_instance = this;
|
||||
m_indent = 4;
|
||||
|
||||
m_is_tty = isatty (fileno (file)) && ! xml_format;
|
||||
m_file_is_tty = isatty (fileno (file));
|
||||
|
||||
#if !defined(_WIN32)
|
||||
if (m_is_tty) {
|
||||
if (m_file_is_tty) {
|
||||
struct winsize ws;
|
||||
ioctl (fileno (stdout), TIOCGWINSZ, &ws);
|
||||
m_columns = std::max (0, (int) ws.ws_col);
|
||||
|
|
@ -276,10 +276,17 @@ TestConsole::flush ()
|
|||
fflush (m_file);
|
||||
}
|
||||
|
||||
bool
|
||||
TestConsole::is_tty ()
|
||||
{
|
||||
// NOTE: this assumes we are delivering to stdout
|
||||
return m_file_is_tty && ! ut::xml_format ();
|
||||
}
|
||||
|
||||
void
|
||||
TestConsole::begin_error ()
|
||||
{
|
||||
if (m_is_tty) {
|
||||
if (is_tty ()) {
|
||||
fputs (ANSI_RED, m_file);
|
||||
}
|
||||
}
|
||||
|
|
@ -287,7 +294,7 @@ TestConsole::begin_error ()
|
|||
void
|
||||
TestConsole::begin_info ()
|
||||
{
|
||||
if (m_is_tty) {
|
||||
if (is_tty ()) {
|
||||
fputs (ANSI_GREEN, m_file);
|
||||
}
|
||||
}
|
||||
|
|
@ -295,7 +302,7 @@ TestConsole::begin_info ()
|
|||
void
|
||||
TestConsole::begin_warn ()
|
||||
{
|
||||
if (m_is_tty) {
|
||||
if (is_tty ()) {
|
||||
fputs (ANSI_BLUE, m_file);
|
||||
}
|
||||
}
|
||||
|
|
@ -303,7 +310,7 @@ TestConsole::begin_warn ()
|
|||
void
|
||||
TestConsole::end ()
|
||||
{
|
||||
if (m_is_tty) {
|
||||
if (is_tty ()) {
|
||||
fputs (ANSI_RESET, m_file);
|
||||
}
|
||||
}
|
||||
|
|
@ -311,7 +318,7 @@ TestConsole::end ()
|
|||
void
|
||||
TestConsole::basic_write (const char *s)
|
||||
{
|
||||
if (m_xml_format) {
|
||||
if (ut::xml_format ()) {
|
||||
|
||||
for (const char *cp = s; *cp; ++cp) {
|
||||
if (*cp == '&') {
|
||||
|
|
@ -384,9 +391,6 @@ TestConsole::redirect ()
|
|||
tl::log.add (new ut::InfoChannel (10), true);
|
||||
tl::error.clear ();
|
||||
tl::error.add (new ut::ErrorChannel (), true);
|
||||
|
||||
ut::ruby_interpreter ()->push_console (this);
|
||||
ut::python_interpreter ()->push_console (this);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -397,9 +401,6 @@ TestConsole::restore ()
|
|||
tl::info.clear ();
|
||||
tl::log.clear ();
|
||||
tl::error.clear ();
|
||||
|
||||
ut::ruby_interpreter ()->remove_console (this);
|
||||
ut::python_interpreter ()->remove_console (this);
|
||||
}
|
||||
|
||||
TestConsole *TestConsole::ms_instance = 0;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
return ms_instance;
|
||||
}
|
||||
|
||||
TestConsole (FILE *file, bool xml_format);
|
||||
TestConsole (FILE *file);
|
||||
~TestConsole ();
|
||||
|
||||
int indent () const
|
||||
|
|
@ -86,20 +86,11 @@ public:
|
|||
return m_indent;
|
||||
}
|
||||
|
||||
bool xml_format () const
|
||||
{
|
||||
return m_xml_format;
|
||||
}
|
||||
|
||||
void write_str (const char *text, output_stream os);
|
||||
void raw_write (const char *text);
|
||||
virtual void flush ();
|
||||
|
||||
virtual bool is_tty ()
|
||||
{
|
||||
// NOTE: this assumes we are delivering to stdout
|
||||
return m_is_tty;
|
||||
}
|
||||
virtual bool is_tty ();
|
||||
|
||||
virtual int columns ()
|
||||
{
|
||||
|
|
@ -124,11 +115,10 @@ public:
|
|||
|
||||
private:
|
||||
FILE *m_file;
|
||||
bool m_xml_format;
|
||||
int m_col;
|
||||
int m_max_col;
|
||||
int m_columns, m_rows;
|
||||
bool m_is_tty;
|
||||
bool m_file_is_tty;
|
||||
int m_indent;
|
||||
static TestConsole *ms_instance;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue