2
0
mirror of https://github.com/boostorg/test.git synced 2026-01-26 19:12:10 +00:00

JUnit default output stream

- string replacement function refactoring
- junit now determining the output stream based on available file
- junit does not replace existing file
This commit is contained in:
Raffi Enficiaud
2016-08-11 11:50:51 +02:00
parent e3bb5bd056
commit 48bcabbd37
2 changed files with 35 additions and 0 deletions

View File

@@ -28,6 +28,7 @@
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/algorithm.hpp>
#include <boost/test/utils/string_cast.hpp>
//#include <boost/test/results_reporter.hpp>
@@ -37,6 +38,7 @@
// STL
#include <iostream>
#include <fstream>
#include <set>
#include <boost/test/detail/suppress_warnings.hpp>
@@ -604,6 +606,34 @@ junit_log_formatter::log_entry_context( std::ostream& ostr, const_string context
//____________________________________________________________________________//
std::string
junit_log_formatter::get_default_stream_description() const {
std::string name = framework::master_test_suite().p_name.value;
static const std::string to_replace[] = { " ", "\"", "/", "\\", ":"};
static const std::string replacement[] = { "_", "_" , "_", "_" , "_"};
name = unit_test::utils::replace_all_occurrences_of(
name,
to_replace, to_replace + sizeof(to_replace)/sizeof(to_replace[0]),
replacement, replacement + sizeof(replacement)/sizeof(replacement[0]));
std::ifstream check_init((name + ".xml").c_str());
if(!check_init)
return name + ".xml";
int index = 0;
for(; index < 100; index++) {
std::string candidate = name + "_" + utils::string_cast(index) + ".xml";
std::ifstream file(candidate.c_str());
if(!file)
return candidate;
}
return name + ".xml";
}
} // namespace output
} // namespace unit_test
} // namespace boost

View File

@@ -114,6 +114,11 @@ public:
{
}
//! Instead of a regular stream, returns a file name corresponding to
//! the current master test suite. If the file already exists, adds an index
//! to it.
virtual std::string get_default_stream_description() const;
private:
typedef std::map<test_unit_id, junit_impl::junit_log_helper> map_trace_t;