
"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