Add NOTE function to C++ unit test API
[dejagnu.git] / contrib / sum2junit.sh
blobe08f09e586ca915c400d1f090a15f325224ae5b8
1 #!/bin/bash
3 # sum2junit.sh -- convert a .sum file into Junit-compatible XML.
5 # Copyright (C) 2016 Free Software Foundation, Inc.
7 # This file is part of DejaGnu.
9 # DejaGnu is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 if test x"$1" = x; then
15 outfile="/tmp/testrun.xml"
16 infile="/tmp/testrun.sum"
17 else
18 outfile=${1//\.sum.*/.xml}
19 infile=$1
22 # Where to put the output file
23 if test x"$2" = x; then
24 outfile=${outfile}
25 else
26 outfile="/tmp/${outfile}"
29 if test ! -e "$infile"; then
30 echo "ERROR: no input file specified"
31 exit
34 tool=$(grep "tests ===" "$infile" | tr -s ' ' | cut -d ' ' -f 2)
36 # Get the counts for tests that didn't work properly
37 skipped=$(grep -E -c '^UNRESOLVED|^UNTESTED|^UNSUPPORTED' "$infile")
38 if test x"${skipped}" = x; then
39 skipped=0
42 # The total of successful results are PASS and XFAIL
43 passes=$(grep -E -c '^PASS|XFAIL' "$infile")
44 if test x"${passes}" = x; then
45 passes=0
48 # The total of failed results are FAIL and XPASS
49 failures=$(grep -E -c '^FAIL|XPASS' "$infile")
50 if test x"${failures}" = x; then
51 failures=0
54 # Calculate the total number of test cases
55 total=$((passes + failures))
56 total=$((total + skipped))
58 cat <<EOF > "$outfile"
59 <?xml version="1.0"?>
61 <testsuites>
62 <testsuite name="DejaGnu" tests="${total}" failures="${failures}" skipped="${skipped}">
64 EOF
66 # Reduce the size of the file to be parsed to improve performance. Junit
67 # ignores sucessful test results, so we only grab the failures and test
68 # case problem results.
69 tmpfile="${infile}.tmp"
70 rm -f "$tmpfile"
71 grep -E 'XPASS|FAIL|UNTESTED|UNSUPPORTED|UNRESOLVED' "$infile" > "$tmpfile"
73 while read -r line
75 echo -n "."
76 result=$(echo "$line" | cut -d ' ' -f 1 | tr -d ':')
77 name=$(echo "$line" | cut -d ' ' -f 2)
78 message=$(echo "$line" | cut -d ' ' -f 3-50 | tr -d '\"><;:\[\]^\\&?@')
80 echo " <testcase name=\"${name}\" classname=\"${tool}-${result}\">" >> "$outfile"
81 case "${result}" in
82 UNSUPPORTED|UNTESTED|UNRESOLVED)
83 if test x"${message}" != x; then
84 echo -n " <skipped message=\"${message}" >> "$outfile"
85 else
86 echo -n " <skipped type=\"$result" >> "$outfile"
89 XPASS|XFAIL)
90 echo -n " <failure message=\"$message" >> "$outfile"
93 echo -n " <failure message=\"$message" >> "$outfile"
94 esac
95 echo "\"/>" >> "$outfile"
97 echo " </testcase>" >> "$outfile"
98 done < "$tmpfile"
99 rm -f "$tmpfile"
101 # Write the closing tag for the test results
102 echo "</testsuite>" >> "$outfile"
103 echo "</testsuites>" >> "$outfile"