Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2006-06-14 01:34:25


"Johan Nilsson" <r.johan.nilsson_at_[hidden]> wrote in message
news:e6j8nb$795$1_at_sea.gmane.org...
> Gennadiy Rozental wrote:
>> <hfye-wila_at_[hidden]> wrote in message
>> news:000501c68bea$0018c7f0$6501a8c0_at_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 <boost/test/auto_unit_test.hpp>
> #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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net