From 5d2125c50197de2b32727bdaf26fb23f72ac3fb6 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Fri, 1 Jun 2018 13:29:34 +0100 Subject: [PATCH] Add new Boost Test results XML parser --- aggregate/boost_test_parser.rb | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/aggregate/boost_test_parser.rb b/aggregate/boost_test_parser.rb index 608541ffc..456001e39 100644 --- a/aggregate/boost_test_parser.rb +++ b/aggregate/boost_test_parser.rb @@ -10,6 +10,14 @@ def initialize(fn) end def each_test + # Boost actually uses two slightly different formats: old and + # new. Instead of trying to detect which one we have, we actually + # just try both. + each_from_old_boost_format { |tr| yield tr } + each_from_new_boost_format { |tr| yield tr } + end + + def each_from_old_boost_format @doc.root.elements.each('TestSuite') { |ts| ts.elements.each('TestCase') { |tc| name = tc.attribute('name').value @@ -48,4 +56,43 @@ def each_test } } end + + def each_from_new_boost_format + @doc.root.elements.each('testcase') { |tc| + name = tc.attribute('name').value + + raise "Unable to parse name: \"#{name}\"" unless name =~ /^test_(.*?)$/ + name = underscore_to_ucamelcase($1) + + failures = [] + tc.elements.each('failure') { |err| + failures << TestResult::Failure.new( + nil, # filename + nil, # line + err.text, + nil + ) + } + + tc.elements.each('error') { |err| + failures << TestResult::Failure.new( + nil, # filename + nil, # line + err.text, + nil + ) + } + + if failures.empty? + status = :passed + failure = nil + else + status = :failed + failure = failures[0] + end + + tr = TestResult.new(name, status, tc.attribute('time').value.to_f, failure) + yield tr + } + end end