This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 517
Add a JUnit output formatter compatible with Jenkins #161
Open
calj
wants to merge
10
commits into
sstephenson:master
Choose a base branch
from
calj:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4583a18
Add a JUnit output formatter compatible with Jenkins
f684ed4
Color passing tests in green
00b8786
Merge remote-tracking branch 'jucor/green_success'
calj b220401
Add the time in seconds elapsed by each test in extended format and i…
calj 2527d22
Add the ability to provide bats pathes from environment
calj fdbc7d8
Add the total execution time to the testsuite
calj 118b5f0
Output each testcase report into a specific XML file
calj 2377aac
Add execution time in case of error
calj 45ec816
bugfix: use echo instead of printf for user input, this avoid printf …
calj c575354
Fix tests
calj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
IFS= read -r header | ||
|
||
index=0 | ||
|
||
init_suite() { | ||
count=0 | ||
failures=0 | ||
skipped=0 | ||
suitetest_exec_time=0 | ||
name="" | ||
_buffer="" | ||
} | ||
|
||
header() { | ||
printf "\ | ||
<?xml version=\"1.0\" encoding=\"UTF-8\"?> | ||
<testsuite name=\"${class}\" tests=\"${count}\" failures=\"${failures}\" skip=\"${skipped}\" time=\"${suitetest_exec_time}\">\n" | ||
} | ||
|
||
footer() { | ||
printf "</testsuite>\n" | ||
} | ||
|
||
|
||
pass() { | ||
echo " <testcase classname=\"${class}\" name=\"${name}\" time=\"${test_exec_time}\"/>\n" | ||
} | ||
|
||
fail() { | ||
printf "\ | ||
<testcase classname=\"${class}\" name=\"${name}\" time=\"${test_exec_time}\"> | ||
<failure><![CDATA[" | ||
|
||
echo -n "${1}" | ||
|
||
printf "]]></failure> | ||
</testcase>\n" | ||
} | ||
|
||
skip() { | ||
echo "\ | ||
<testcase classname=\"${class}\" name=\"${name}\" time=\"${test_exec_time}\"> | ||
<skipped>$1</skipped> | ||
</testcase>\n" | ||
} | ||
|
||
buffer() { | ||
_buffer="${_buffer}$("$@")" | ||
} | ||
|
||
flush() { | ||
echo "${_buffer}" | ||
_buffer="" | ||
} | ||
|
||
_buffer_log="" | ||
log() { | ||
_buffer_log="${_buffer_log} | ||
$1" | ||
} | ||
|
||
flush_log() { | ||
if [[ -n "${_buffer_log}" ]]; then | ||
buffer fail "${_buffer_log}" | ||
_buffer_log="" | ||
fi | ||
} | ||
|
||
finish_suite() { | ||
[[ ${count} -gt 0 ]] && { | ||
( | ||
flush_log | ||
header | ||
flush | ||
footer | ||
) > "TestReport-${class-case}.xml" | ||
} | ||
init_suite | ||
} | ||
|
||
trap finish_suite EXIT | ||
|
||
while IFS= read -r line; do | ||
case "$line" in | ||
"suite "*) | ||
flush_log | ||
finish_suite | ||
suite_expr="suite (.*)" | ||
if [[ "$line" =~ $suite_expr ]]; then | ||
class="${BASH_REMATCH[1]}" | ||
fi | ||
;; | ||
"begin "* ) | ||
flush_log | ||
let index+=1 | ||
name="${line#* $index }" | ||
;; | ||
"ok "* ) | ||
let count+=1 | ||
expr_ok="ok $index .* in ([0-9]+)sec" | ||
expr_skip="ok $index # skip (.*)" | ||
if [[ "$line" =~ $expr_skip ]]; then | ||
let skipped+=1 | ||
test_exec_time=0 | ||
buffer skip "${BASH_REMATCH[1]}" | ||
elif [[ "$line" =~ $expr_ok ]]; then | ||
test_exec_time="${BASH_REMATCH[1]}" | ||
suitetest_exec_time=$((suitetest_exec_time + test_exec_time)) | ||
buffer pass | ||
else | ||
log "Wrong output format: ${line}" | ||
let failures+=1 | ||
fi | ||
;; | ||
"not ok "* ) | ||
let count+=1 | ||
let failures+=1 | ||
expr_notok="not ok $index .* in ([0-9]+)sec" | ||
if [[ "$line" =~ $expr_notok ]]; then | ||
test_exec_time="${BASH_REMATCH[1]}" | ||
suitetest_exec_time=$((suitetest_exec_time + test_exec_time)) | ||
fi | ||
;; | ||
"# "* ) | ||
log "${line:2}" | ||
;; | ||
esac | ||
done | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ begin() { | |
|
||
pass() { | ||
go_to_column 0 | ||
set_color 2 | ||
printf " ✓ %s" "$name" | ||
advance | ||
} | ||
|
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more explicit and future-proof to name them
-x, --extended-tap
and-j, --junit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to say Jenkins or Jenkins/Hudson here as most people use Jenkins. Additionally it's a personal name so caps are grammatically correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove what's after the comma entirely. Whether it's for Hudson, Jenkins or whatever, it's a JUnit format, and it's all that matters :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we can do so.
I have specified Hudson here because I noticed difference with the JUnit specifications.