Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-09-04 17:42:50


I have struggled a little to set loglevel, output stream, etc using MSVC 7.1
whose IDE is hostile to using commandline or environment methods.

The FAQ hints, but the following may be helpful:

#include <boost/test/test_tools.hpp> // for test_tools

using std::ofstream;
using boost::unit_test_framework::unit_test_log;
using boost::unit_test_framework::log_level;

int test_main(int, char*[])
{

        // Change log level to all warnings & errors.
        unit_test_log::instance().set_log_threshold_level_by_name("all");

        // Prepare to log to a file instead of the default cout.
        ofstream flog("demo_test_tools.log"); // for log.
        if (!flog.is_open())
        { // Log file problem, so quit.
                return boost::exit_failure;
        }
        unit_test_log::instance().set_log_stream(flog); // Switch to log file.

        // Examples of using test tools.
        BOOST_MESSAGE("Example of BOOST_MESSAGE");
// which now appears in the log file, rather than the default failures only.

... real BOOST_CHECK()s ...

        unit_test_log::instance().set_log_stream(cout); // Switch back to cout.
// Unhappy ending if don't do this :-((
        flog.close()
} // int test_main(int, char*[])

The file containing test_main is linking to a static library test_tools.lib

consisting of the execution_monitor.cpp - compiled with MS language extensions
/Za,

and test_main.cpp, unit_test_log.cpp
unit_test_monitor.cpp, unit_test_parameters.cpp, unit_test_result.cpp,
unit_test_suite.cpp compiled withOUT MS language extensions ie 'strict' mode but
with a few warnings.

This allows testing of my code in 'strict' mode: MS language extensions disabled
and warning level 4, my original aim. It seems impossible with
'minimal_testing', despite its simplicity and convenience (unless anyone can
advise how to switch compile options for just execution_monitor.cpp).

Excellent Gennadiy!

Paul

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk