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 'add(..) result: 4' 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 | | }}} |
| 70 | By 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. |
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 :) |
| 89 | struct 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 | |
| 106 | static ReportRedirector foo; |
| 107 | }}} |
| 108 | |
| 109 | There might be other, prettier ways to do this - please contribute if you have a better solution. |
| 110 | |
| 111 | Once 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 | }}} |