Is there a way to control boost output_test_stream "record vs. check" behavior without recompile?

194 views Asked by At

I am using Boost.Test class output_test_stream to verify that my app provides the expected output. This class provides an easy method to compare the output data vs. known-good recorded data in a file, by invoking the match_pattern() method. Here is how I use it:

#if defined( CREATE_TEST_PATTERNS )
    bool pattern_test = false;
#else
    bool pattern_test = true;
#endif
boost::test_tools::output_test_stream ostrg("test_output_ref.txt", pattern_test);
my_class_under_test cl(arg1, arg2, ostrg);
...
BOOST_CHECK( ostrg.match_pattern() );

The desired output is in the file test_output_ref.txt. The call to match_pattern() compares the data in ostrg to the data in the file. If the varaible pattern_test is false, the call to match_pattern() will instead save the data from ostrg to the ref data file test_output_ref.txt.

The way I use it is, I first build with the macro CREATE_TEST_PATTERNS defined, and run the test program (the tests run as a post build step), to collect the output into a file, visually inspect the output file to make sure the output was correct, and then I re-build the test program with CREATE_TEST_PATTERNS not defined. In this mode, the test compares the previously recorded expected result to the result generated by the test run. So far so good.

My question is this: Is there a way to achieve control over the record/check behavior of match_pattern() without having to recompile the test program?

0

There are 0 answers