Edgewall Software

Changes between Version 6 and Version 7 of Boost Test


Ignore:
Timestamp:
Oct 31, 2007, 11:15:11 AM (17 years ago)
Author:
staffan.spam@…
Comment:

Added info on how to redirect the report data to file

Legend:

Unmodified
Added
Removed
Modified
  • Boost Test

    v6 v7  
    6464}}}
    6565
    66 Using this approach (using `<sh:exec>` to redirect the output to a file) your test log won't be very nice looking. You probably want to tweak this template to generate the XML data by other means and instruct it to output nice log-message.
     66Using this approach (using `<sh:exec>` to redirect the output to a file) your test log won't be very nice looking. You probably want to tweak this template to generate the XML data by other means and instruct it to output nice log-messages.
    6767
    68   ''this didn't work for me.  The XSLT is not picking up the error information.  For example, the following Boost.Test XML output:''
     68== Appendix A: Redirecting the report data ==
    6969
    70   {{{
    71 #!xml
    72 <TestLog>
    73   <TestSuite name="MyTest">
    74     <TestCase name="my_test">
    75       <Error file="tests.cpp" line="13">check add( 2,2 ) == 3 failed</Error>
    76       <Error file="tests.cpp" line="14">check add( 2,3 ) == 4 failed</Error>
    77       <Error file="tests.cpp" line="15">check add( 2,4 ) == 4 failed</Error>
    78       <Info file="tests.cpp" line="17">check add( 2,2 ) == 4 passed</Info>
    79       <Info file="tests.cpp" line="28">check &apos;add(..) result: 4&apos; passed</Info>
    80       <Info file="tests.cpp" line="30">check add( 2,2 ) == 4 passed</Info>
    81       <TestingTime>0</TestingTime>
    82     </TestCase>
    83   </TestSuite>
    84 </TestLog>
    85   }}}
     70By default, Boost.Test outputs the report to stderr and the log to stdout. Ideally, we only want to redirect the report data to our "test_results.xml" file.
    8671
    87   ''gets transformed into:''
     72Exactly how you should do this depends on how you use Boost.Test - i.e. if you supply your own main() function or let Boost.Test take care of that for you. In the latter case, this is one way of doing it:
    8873
    89   {{{
    90 #!xml
    91 <?xml version="1.0"?>
    92 <unit_tests>
    93   <test>
    94     <status/>
    95     <fixture>MyTest</fixture>
    96     <type>test</type>
    97     <name>my_test</name>
    98   </test>
    99 </unit_tests>
    100   }}}
     74{{{
     75//
     76// run_tests.cc
     77//
    10178
    102   ''clearly something is missing'' -- dabrahams
     79#define BOOST_AUTO_TEST_MAIN
     80
     81#include <iostream>
     82#include <fstream>
     83#include <cassert>
     84#include <boost/test/auto_unit_test.hpp>
     85
     86
     87// Write cerr to file - fail and cry with no apparent error if we can't
     88// open the file :)
     89struct ReportRedirector
     90{
     91    std::streambuf *orig;
     92    std::ofstream out;
     93
     94    ReportRedirector() : out("test_results.xml")
     95    {
     96        assert( out.is_open() );
     97        orig = std::cerr.rdbuf(out.rdbuf());
     98    }
     99
     100    ~ReportRedirector()
     101    {
     102        std::cerr.rdbuf(orig);
     103    }
     104};
     105
     106static ReportRedirector foo;
     107}}}
     108
     109There might be other, prettier ways to do this - please contribute if you have a better solution.
     110
     111Once the report has been properly redirected, you can update your recipe to include logging output:
     112
     113{{{
     114<build xmlns:sh="http://bitten.cmlenz.net/tools/sh" xmlns:x="http://bitten.cmlenz.net/tools/xml">
     115  <step id="test" description="Test - run automated tests">
     116    <sh:exec executable="run_tests" args="--log_level=all --report_format=XML --report_level=detailed" />
     117    <x:transform src="test_results.xml" dest="test_report.xml" stylesheet="test_results.xslt" />
     118    <report category="test" file="test_report.xml"/>
     119  </step>
     120</build>
     121}}}