[test] Output log file name

Hi, I'm using the Boost.Test (unit test framework) from cvs, trying to get xml output redirected into files. The xml format itself is not a problem, but I can't find any options to get the output into files. Is this possible to do using either command-line arguments or environment variables? It's possible, but awkard, to use unit_test_log::set_stream, but I figured I'd check if there were any options before implementing that. / Johan

"Johan Nilsson"
Hi,
I'm using the Boost.Test (unit test framework) from cvs, trying to get xml output redirected into files. The xml format itself is not a problem, but I can't find any options to get the output into files.
What wrong with plain redirection: my_test --output_format xml 1> log.xml 2>report.xml Gennadiy

Gennadiy Rozental wrote:
"Johan Nilsson"
wrote in message news:e6b89a$td$1@sea.gmane.org... Hi,
I'm using the Boost.Test (unit test framework) from cvs, trying to get xml output redirected into files. The xml format itself is not a problem, but I can't find any options to get the output into files.
What wrong with plain redirection:
my_test --output_format xml 1> log.xml 2>report.xml
Basically the fact that I was using Boost.Build and the unit-test rule. // Johan

"Johan Nilsson"
Gennadiy Rozental wrote:
"Johan Nilsson"
wrote in message news:e6b89a$td$1@sea.gmane.org... Hi,
I'm using the Boost.Test (unit test framework) from cvs, trying to get xml output redirected into files. The xml format itself is not a problem, but I can't find any options to get the output into files.
What wrong with plain redirection:
my_test --output_format xml 1> log.xml 2>report.xml
Basically the fact that I was using Boost.Build and the unit-test rule.
And it doesn't allow to redirect test output? Oh, well - I will have to consider adding parameters for the framework. Gennadiy

Hi Johan,
The command line options I know of are:
char * argv[] = { // defaults:
"--build_info=yes", // no
// "--catch_system_errors=no", // yes
// "--detect_memory_leaks=0", // 1
// "--log_format=XML", // HRF
"--log_level=messages", // all_errors
// "--no_result_code=no", // yes
"--output_format=XML", // HRF (overrides log_format &
report_format)
"--random=1", // 0
// "--report_format=XML", // HRF
"--report_level=detailed", // confirm
// "--show_progress=yes" }; // no
To output to files, I use set_stream. I found it made things easier to have
my own version of Boost.Test's "main" function, like this:
// based on: "main" in

Hi Johan,
The command line options I know of are:
char * argv[] = { // defaults: "--build_info=yes", // no // "--catch_system_errors=no", // yes // "--detect_memory_leaks=0", // 1 // "--log_format=XML", // HRF "--log_level=messages", // all_errors // "--no_result_code=no", // yes "--output_format=XML", // HRF (overrides log_format & report_format) "--random=1", // 0 // "--report_format=XML", // HRF "--report_level=detailed", // confirm // "--show_progress=yes" }; // no
To output to files, I use set_stream. I found it made things easier to have my own version of Boost.Test's "main" function, like this:
// based on: "main" in
int my_unit_test_entrypoint() { using namespace ::boost::unit_test; int ret = boost::exit_exception_failure; try { char * argv[] = { /*add cmdline options here*/ }; // see above int argc = sizeof( argv ) / sizeof( char * ); framework::init( argc, argv );
std::ofstream logStream( "c:\\log.xml" ); unit_test_log.set_stream( logStream );
framework::run();
std::ofstream reportStream( "c:\\report.xml" ); results_reporter::set_stream( reportStream );
results_reporter::make_report();
if ( runtime_config::no_result_code() ) { ret = boost::exit_success; } else { test_unit_id id = framework::master_test_suite().p_id; ret = results_collector.results( id ).result_code(); } } catch( std::logic_error const & ex ) { /*add error reporting here*/ } catch( ... ) { /*add error reporting here*/ } return ret; }
Hope this helps!
John Fearnside
-----Original Message----- From: Johan Nilsson [mailto:r.johan.nilsson@gmail.com]
Hi,
I'm using the Boost.Test (unit test framework) from cvs, trying to get xml output redirected into files. The xml format itself is not a problem, but I can't find any options to get the output into files.
Is this possible to do using either command-line arguments or environment variables? It's possible, but awkard, to use unit_test_log::set_stream, but I figured I'd check if there were any options before implementing that.
/ Johan

To output to files, I use set_stream. I found it made things easier to have my own version of Boost.Test's "main" function, like this:
// based on: "main" in
int my_unit_test_entrypoint() { using namespace ::boost::unit_test; int ret = boost::exit_exception_failure; try { char * argv[] = { /*add cmdline options here*/ }; // see above int argc = sizeof( argv ) / sizeof( char * ); framework::init( argc, argv );
std::ofstream logStream( "c:\\log.xml" ); unit_test_log.set_stream( logStream );
framework::run();
std::ofstream reportStream( "c:\\report.xml" ); results_reporter::set_stream( reportStream );
results_reporter::make_report();
if ( runtime_config::no_result_code() ) { ret = boost::exit_success; } else { test_unit_id id = framework::master_test_suite().p_id; ret = results_collector.results( id ).result_code(); } } catch( std::logic_error const & ex ) { /*add error reporting here*/ } catch( ... ) { /*add error reporting here*/ } return ret; }
You don't really need to rewrite main to implement redirection. There are several ways to do this. One of simplest id to use global fixture: std::ofstream logStream; std::ofstream reportStream; struct output_setup { output_setup() { logStream.open( "c:\\log.xml" ); unit_test_log.set_stream( logStream ); reportStream.open( "c:\\report.xml" ); results_reporter::set_stream( reportStream ); } }; BOOST_GLOBAL_FIXTURE( output_setup ); Gennadiy

Gennadiy Rozental wrote:
wrote in message news:000501c68bea$0018c7f0$6501a8c0@Furst...
[snip]
You don't really need to rewrite main to implement redirection. There are several ways to do this. One of simplest id to use global fixture:
std::ofstream logStream; std::ofstream reportStream;
struct output_setup { output_setup() { logStream.open( "c:\\log.xml" ); unit_test_log.set_stream( logStream );
reportStream.open( "c:\\report.xml" ); results_reporter::set_stream( reportStream ); } };
BOOST_GLOBAL_FIXTURE( output_setup );
I originally did something similar:
---
#define BOOST_TEST_MODULE foo
#include

"Johan Nilsson"
Gennadiy Rozental wrote:
wrote in message news:000501c68bea$0018c7f0$6501a8c0@Furst... You don't really need to rewrite main to implement redirection. There are several ways to do this. One of simplest id to use global fixture:
std::ofstream logStream; std::ofstream reportStream;
struct output_setup { output_setup() { logStream.open( "c:\\log.xml" ); unit_test_log.set_stream( logStream );
reportStream.open( "c:\\report.xml" ); results_reporter::set_stream( reportStream ); } };
BOOST_GLOBAL_FIXTURE( output_setup );
I originally did something similar:
--- #define BOOST_TEST_MODULE foo #include
#include <fstream> #include <iostream> using namespace boost::unit_test;
struct output_setup { output_setup() { logStream_.open( "c:\\temp\\log.xml" ); if (logStream_.is_open()) unit_test_log.set_stream( logStream_ ); }
~output_setup() { if (logStream_.is_open()) unit_test_log.set_stream( std::cout ); }
std::ofstream logStream_; };
BOOST_GLOBAL_FIXTURE( output_setup ); ---
The above kind-of works, but the final "</TestLog>" goes to stdout (which was unexpected, at least for me). I understand what happens, but wouldn't it be more intuitive to have the above working?
I am afraid I may not be able to enforce different test observers order for different test events. But I will see what could be done.
OTOH, defining the output_setup instance as a static instance:
output_setup g_outputSetup;
seems to work just fine though, and does not require 1.34 either.
This is less preferred than my solution since it's relies on global variables initialization order and will fire in your face soon enough. Gennadiy
participants (3)
-
Gennadiy Rozental
-
hfye-wila@spamex.com
-
Johan Nilsson