Last active
December 14, 2015 06:38
-
-
Save hoodja/5043784 to your computer and use it in GitHub Desktop.
"bash" me all you want, but this is sweet. It turns the verbose output of Unity xUnit framework for C (yes, straight eff'n C) into JUnit results that Jenkins CI can eat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
my $fname = shift or die 'filename!'; | |
open my $fh, $fname or die "Could not open $fname: $!"; | |
print "<testsuite>\n"; | |
foreach(grep /^ *(IGNORE_)?TEST/, <$fh>) { | |
my ($status, $group, $test, $detail); | |
$status = $group = $test = $detail = ""; | |
($status, $group, $test) = ($_ =~ m/(IGNORE)_TEST\(([^,]*), ([^)]*)\).*$/) or | |
($group, $test, $status) = ($_ =~ m/TEST\(([^,]*), ([^)]*)\) *(PASS).*$/) or | |
($group, $test, $status, $detail) = ($_ =~ m/TEST\(([^,]*), ([^)]*)\)[^:]*:[^:]*:[^:]*:[^:]*:(FAIL):(.*$)/); | |
print " <testcase classname=\"$group\" name=\"$test\">\n"; | |
print " <skipped></skipped>\n" if $status eq "IGNORE"; | |
print " <failure>\n <![CDATA[$detail]]>\n </failure>\n" if $status eq "FAIL"; | |
print " </testcase>\n"; | |
} | |
print "</testsuite>\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#TODO: assert argument exists and is a file, etc. | |
cat << END_OF_RESULTS | |
<testsuite> | |
$( | |
cat $1 | grep -Ee "^ *(IGNORE_)?TEST" | while read line; do | |
command=$(echo $line | \ | |
sed \ | |
-e 's/IGNORE_TEST(\([^,]*\), \([^)]*\)).*$/group="\1"; test="\2"; status="IGNORE";/' \ | |
-e 's/TEST(\([^,]*\), \([^)]*\)) \(PASS\).*$/group="\1"; test="\2"; status="\3";/' \ | |
-e 's/TEST(\([^,]*\), \([^)]*\))[^:]*:\([^:]*\):\([^:]*\):\([^:]*\):\(FAIL\):\(.*$\)/group="\1"; test="\2"; status="\6"; detail="\7"/') | |
eval "$command" | |
echo " <testcase classname=\"$group\" name=\"$test\">" | |
[[ "$status" == "IGNORE" ]] && echo " <skipped></skipped>" | |
[[ "$status" == "FAIL" ]] && echo " <failure> | |
<![CDATA[ | |
$detail | |
]]> | |
</failure>" | |
echo " </testcase>" | |
done | |
) | |
</testsuite> | |
END_OF_RESULTS |
I added your file test in my fork
I added a perl implementation; surprisingly readable!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input
Output