Skip to content

Commit

Permalink
Merge cd294c8 into 8080684
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Nov 21, 2020
2 parents 8080684 + cd294c8 commit f4478e7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
26 changes: 13 additions & 13 deletions docs/reporter.md
Expand Up @@ -6,26 +6,26 @@
| ------ | --------- | ------------------------------- |
| | meta | 1 |
| +----- | begin | 0..N (number of specfiles) |
| : +-- | example | 0..N |
| : : | statement | 0..N |
| : +-- | result | same number of times as example |
| : +-- | example | 0..N |
| : : | statement | 0..N |
| : +-- | result | same number of times as example |
| +----- | end | same number of times as begin |
| | finished | 1 |
| | | |
| | error | 0..N (can occur at any time) |

### types

| type | fields |
| --------- | ------------------------------------------------------------ |
| meta | shell, shell_type, shell_version, info |
| begin | specfile |
| example | id, block_no, example_no, focused, description, lineno_range |
| statement | tag, lineno, [statement type fields...] |
| result | [result type fields...], trace |
| end | |
| finished | |
| error | lineno, note, message, failure_message |
| type | fields |
| --------- | ---------------------------------------------------------------------------- |
| meta | shell, shell_type, shell_version, info |
| begin | specfile |
| example | id, block_no, example_no, focused, description, lineno_range, stdout, stderr |
| statement | tag, lineno, [statement type fields...] |
| result | [result type fields...], trace |
| end | |
| finished | |
| error | lineno, note, message, failure_message |

### statement type

Expand Down
3 changes: 2 additions & 1 deletion lib/core/outputs.sh
Expand Up @@ -20,7 +20,8 @@ shellspec_output_END() {
shellspec_output_EXAMPLE() {
shellspec_output_example "id:$SHELLSPEC_EXAMPLE_ID" \
"block_no:$SHELLSPEC_BLOCK_NO" "example_no:$SHELLSPEC_EXAMPLE_NO" \
"focused:$SHELLSPEC_FOCUSED" "description:$SHELLSPEC_DESCRIPTION"
"focused:$SHELLSPEC_FOCUSED" "description:$SHELLSPEC_DESCRIPTION" \
"stdout:$SHELLSPEC_STDOUT_FILE" "stderr:$SHELLSPEC_STDERR_FILE"
}

shellspec_output_EVALUATION() {
Expand Down
10 changes: 9 additions & 1 deletion lib/libexec/reporter.sh
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=lib/libexec.sh
. "${SHELLSPEC_LIB:-./lib}/libexec.sh"
use import constants sequence replace_all each padding trim wrap
use is_empty_file pluralize exists_file
use is_empty_file pluralize exists_file readfile

count_examples() {
set -- "$SHELLSPEC_LIBEXEC/shellspec-list.sh" "$@"
Expand Down Expand Up @@ -79,6 +79,14 @@ xmlattrs() {
eval "$EVAL"
}

xmlcdata() {
eval "$1=\$2"
if [ "$2" ]; then
replace_all "$1" ']]>' ']]]]><![CDATA[>'
eval "$1=\"<![CDATA[\${$1}]]>\""
fi
}

remove_escape_sequence() {
while IFS= read -r line || [ "$line" ]; do
text=''
Expand Down
15 changes: 11 additions & 4 deletions lib/libexec/reporter/junit_formatter.sh
Expand Up @@ -39,12 +39,12 @@ junit_each() {
if [ "$field_fail" ]; then
xmlattrs _attrs "message=$field_message"
_text="$field_failure_message${LF}# $field_specfile:$field_lineno"
xmlescape _text "$_text"
junit '=' "${LF} <failure $_attrs>$_text</failure>${LF} "
xmlcdata _text "$_text"
junit '=' "${LF} <failure $_attrs>$_text</failure>"
else
case $field_tag in (skip | pending)
xmlattrs _attrs "message=$field_message"
junit '=' "${LF} <skip $_attrs />${LF} "
junit '=' "${LF} <skip $_attrs />"
esac
fi
;;
Expand All @@ -55,7 +55,14 @@ junit_each() {
elif [ "$field_tag" = "todo" ] || [ "$field_tag" = "skipped" ]; then
inc _skipped
fi
junit '=' "</testcase>${LF}"
_stdout='' _stderr=''
[ -r "$field_stdout" ] && readfile _stdout "$field_stdout"
[ -r "$field_stderr" ] && readfile _stderr "$field_stderr"
xmlcdata _stdout "$_stdout"
xmlcdata _stderr "$_stderr"
junit '=' "${LF} <system-out>$_stdout></system-out>"
junit '+=' "${LF} <system-err>$_stderr</system-err>"
junit '+=' "${LF} </testcase>${LF}"
;;
end)
junit '='
Expand Down
10 changes: 6 additions & 4 deletions libexec/shellspec-reporter.sh
Expand Up @@ -19,17 +19,19 @@ color_constants
found_focus='' no_examples='' aborted=1 repetition='' coverage_failed='' \
fail_fast='' fail_fast_count=${SHELLSPEC_FAIL_FAST_COUNT:-999999} reason='' \
current_example_index=0 example_index='' \
last_example_no='' last_skip_id='' not_enough_examples='' \
field_id='' field_type='' field_tag='' field_example_no='' field_focused='' \
field_temporary='' field_skipid='' field_pending='' field_message='' \
field_quick='' field_specfile=''
last_example_no='' last_skip_id='' not_enough_examples=''

# shellcheck disable=SC2034
specfile_count=0 expected_example_count=0 example_count=0 \
succeeded_count='' failed_count='' warned_count='' error_count='' \
todo_count='' fixed_count='' skipped_count='' error_index='' \
suppressed_todo_count='' suppressed_fixed_count='' suppressed_skipped_count=''

# shellcheck disable=SC2034
field_id='' field_type='' field_tag='' field_example_no='' field_focused='' \
field_temporary='' field_skipid='' field_pending='' field_message='' \
field_quick='' field_specfile='' field_stdout='' field_stderr=''

init_quick_data

[ "$SHELLSPEC_GENERATORS" ] && mkdir -p "$SHELLSPEC_REPORTDIR"
Expand Down
7 changes: 7 additions & 0 deletions spec/libexec/reporter_spec.sh
Expand Up @@ -223,6 +223,13 @@ Describe "libexec/reporter.sh"
End
End

Describe "xmlcdata()"
It 'creates xml CDATA'
When call xmlcdata cdata 'test1<![CDATA[test2]]>test3'
The variable cdata should eq '<![CDATA[test1<![CDATA[test2]]]]><![CDATA[>test3]]>'
End
End

Describe "remove_escape_sequence()"
It 'removes escape sequence'
Data printf '\033[1;31m%s\033[0m \033[1;31m%s\033[0m\n' "foo" "bar"
Expand Down

0 comments on commit f4478e7

Please sign in to comment.