Skip to content

Instantly share code, notes, and snippets.

@anthonybishopric
Created October 18, 2013 17:55
Show Gist options
  • Save anthonybishopric/7045416 to your computer and use it in GitHub Desktop.
Save anthonybishopric/7045416 to your computer and use it in GitHub Desktop.
Simple script to print errors in a junit-formatted xml file.
#! /usr/bin/env ruby
require "xmlsimple"
require "colored"
def parse_test_cases(test_cases)
test_cases.each do |test_case|
errs = test_case["failure"] || test_case["error"]
if errs
puts ("-->" + test_case["name"]).red
puts errs[0]["content"]
end
end
end
def parse_test_suite(test_suite)
test_suite.each do |suites_or_cases|
if suites_or_cases["testcase"] != nil
if (((suites_or_cases["failures"] || 0).to_i + (suites_or_cases["errors"] || 0).to_i)) > 0
puts ((suites_or_cases["name"] || suites_or_cases["file"] || "<?>") + "\t" + suites_or_cases["failures"] + "F\t" + suites_or_cases["errors"] + "E").green
parse_test_cases(suites_or_cases["testcase"])
end
end
if suites_or_cases["testsuite"] != nil
parse_test_suite(suites_or_cases["testsuite"])
end
end
end
ARGV.each do |junit_file|
junit = XmlSimple.xml_in(junit_file)
parse_test_suite(junit["testsuite"])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment