Provide a new option -o for unit test runner which sends the log to a file. This way we don't capture qWarning in the XML JUnit logs.

This commit is contained in:
Matthias Koefferlein 2020-06-27 00:25:56 +02:00
parent 868adbceab
commit 69fe4a5edf
3 changed files with 49 additions and 8 deletions

View File

@ -544,9 +544,11 @@ main_cont (int &argc, char **argv)
bool debug_mode = false;
bool continue_flag = false;
int repeat = 1;
std::string output;
tl::CommandLineOptions cmd;
cmd << tl::arg ("-a", &xml_format, "Provide XML output format (JUnit format)")
<< tl::arg ("-o=log", &output, "Sends output to the given file")
<< tl::arg ("-l", &list_tests, "Lists tests and exits")
<< tl::arg ("-e", &editable, "Uses editable mode")
<< tl::arg ("-ne", &non_editable, "Uses non-editable mode")
@ -596,8 +598,18 @@ main_cont (int &argc, char **argv)
tl::set_continue_flag (continue_flag);
tl::set_debug_mode (debug_mode);
FILE *output_file = 0;
try {
if (! output.empty ()) {
output_file = fopen (output.c_str (), "w");
if (! output_file) {
throw tl::Exception (std::string ("Unable to open log file for writing :") + output);
}
console.send_to (output_file);
}
ut::ctrl << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
ut::ctrl << "<testsuites>";
@ -652,8 +664,20 @@ main_cont (int &argc, char **argv)
ut::ctrl << "</testsuites>";
if (output_file) {
console.send_to (stdout);
fclose (output_file);
}
} catch (...) {
ut::ctrl << "</testsuites>";
if (output_file) {
console.send_to (stdout);
fclose (output_file);
}
throw;
}

View File

@ -197,10 +197,25 @@ TestConsole::TestConsole (FILE *file)
{
ms_instance = this;
prepare_file ();
redirect ();
}
TestConsole::~TestConsole ()
{
restore ();
if (ms_instance == this) {
ms_instance = 0;
}
}
void TestConsole::prepare_file ()
{
#if defined(_MSC_VER)
m_file_is_tty = false;
#else
m_file_is_tty = isatty (fileno (file));
m_file_is_tty = isatty (fileno (m_file));
#endif
#if !defined(_WIN32)
@ -211,16 +226,15 @@ TestConsole::TestConsole (FILE *file)
m_rows = std::max (0, (int) ws.ws_row);
}
#endif
redirect ();
}
TestConsole::~TestConsole ()
void
TestConsole::send_to (FILE *file)
{
restore ();
if (ms_instance == this) {
ms_instance = 0;
if (file != m_file) {
flush ();
m_file = file;
prepare_file ();
}
}

View File

@ -52,6 +52,8 @@ public:
TestConsole (FILE *file);
~TestConsole ();
void send_to (FILE *file);
void write_str (const char *text, output_stream os);
void raw_write (const char *text);
virtual void flush ();
@ -85,6 +87,7 @@ private:
void redirect ();
void restore ();
void prepare_file ();
};
}