Skip to content

Commit

Permalink
Add time to JUnit XML
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Jul 8, 2019
1 parent 36ffe9e commit c915043
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/libexec/reporter/junit_formatter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ create_buffers junit
junit_output="results_junit.xml"

junit_begin() {
_attrs=''
xmlattrs _attrs "name=$SHELLSPEC_PROJECT_NAME"
junit '=' '<?xml version="1.0" encoding="UTF-8"?>'
junit '+=' "${LF}<testsuites name=\"\">${LF}"
junit '+=' "${LF}<testsuites $_attrs>${LF}"
junit '>>>' >> "$SHELLSPEC_TMPBASE/${junit_output}.work"
}

Expand Down Expand Up @@ -77,7 +79,7 @@ junit_end() {
}

junit_output() {
_id=0 _before='' _after='' _attrs=''
_id=0 _cid=0 _before='' _after='' _attrs='' _time=''
case $1 in (end)
while IFS= read -r _line; do
case $_line in
Expand All @@ -94,6 +96,17 @@ junit_output() {
putsn "$_before<testsuite $_attrs $_after"
inc _id
;;
*\<testcase\ *)
_before=${_line%%<testcase\ *} _after=${_line#*<testcase\ }
if [ "$SHELLSPEC_PROFILER" ]; then
eval "_time=\${profiler_time$_cid#* }"
else
_time=0
fi
xmlattrs _attrs "time=$_time"
putsn "$_before<testcase $_attrs $_after"
inc _cid
;;
*) putsn "$_line"
esac
done < "$SHELLSPEC_TMPBASE/${junit_output}.work"
Expand Down
1 change: 1 addition & 0 deletions shellspec
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Usage: shellspec [options] [files or directories]
[d]ocumentation group and example names
[t]ap TAP format
[j]unit JUnit XML
(Require --profile for time attributre)
[null] do not display anything
[debug] for developer
custom formatter name
Expand Down

0 comments on commit c915043

Please sign in to comment.