Skip to content

Commit

Permalink
Merge 0695ae9 into f927dfd
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Nov 5, 2020
2 parents f927dfd + 0695ae9 commit 0b2c832
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
6 changes: 6 additions & 0 deletions lib/libexec/optparser.sh
Expand Up @@ -56,6 +56,12 @@ parser_definition() {
'Fail on low coverage [default: disabled]' \
' The coverage threshold is specified by the coverage option'

param FAILURE_EXIT_CODE --failure-exit-code validate:check_number init:=101 var:CODE -- \
'Override the exit code used when there are failing specs [default: 101]'

param ERROR_EXIT_CODE --error-exit-code validate:check_number init:=102 var:CODE -- \
'Override the exit code used when there are fatal errors [default: 102]'

flag PROFILER -p +p --{no-}profile -- \
'Enable profiling and list the slowest examples [default: disabled]' \
' Profiler tries to use 100% ability of 1 CPU (1 core).' \
Expand Down
2 changes: 1 addition & 1 deletion lib/libexec/translator.sh
Expand Up @@ -163,7 +163,7 @@ block_example() {

block_end() {
if [ ! "$_block_no_stack" ]; then
syntax_error "unexpected 'End'"
syntax_error "Unexpected 'End'"
return 0
fi

Expand Down
10 changes: 5 additions & 5 deletions libexec/shellspec-reporter.sh
Expand Up @@ -192,19 +192,19 @@ if [ -e "$SHELLSPEC_TMPBASE/$SHELLSPEC_DEPRECATION_LOGFILE" ]; then
fi

if [ "$repetition" ]; then
exit_status=$SHELLSPEC_SYNTAX_ERROR_CODE
exit_status=$SHELLSPEC_ERROR_EXIT_CODE
elif [ "$interrupt" ]; then
exit_status=130
elif [ "$aborted" ]; then
exit_status=1
elif [ "$SHELLSPEC_FAIL_LOW_COVERAGE" ] && [ "$coverage_failed" ]; then
exit_status=$SHELLSPEC_SPEC_FAILURE_CODE
exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
elif [ "$SHELLSPEC_WARNING_AS_FAILURE" ] && [ "$warned_count" ]; then
exit_status=$SHELLSPEC_SPEC_FAILURE_CODE
exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
elif [ "${failed_count}${error_count}${fixed_count}" ]; then
exit_status=$SHELLSPEC_SPEC_FAILURE_CODE
exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
elif [ "${not_enough_examples}${no_examples}" ]; then
exit_status=$SHELLSPEC_SPEC_FAILURE_CODE
exit_status=$SHELLSPEC_FAILURE_EXIT_CODE
else
exit_status=0
fi
Expand Down
22 changes: 13 additions & 9 deletions libexec/shellspec-runner.sh
Expand Up @@ -59,7 +59,7 @@ error_handler() {
error "$line"
done

[ "$error_count" -eq 0 ] || exit "$SHELLSPEC_STDERR_OUTPUT_CODE"
[ "$error_count" -eq 0 ] || exit "$SHELLSPEC_ERROR_EXIT_CODE"
}

"$SHELLSPEC_TRAP" 'interrupt' INT
Expand Down Expand Up @@ -144,22 +144,26 @@ fi
| error_handler >&4; echo $? >&5 ) 5>&1 \
| (
read -r xs1; read -r xs2; read -r xs3
xs=0 msg="Aborted with status code"
xs='' error='' msg="Aborted with status code"
for i in "$xs1" "$xs2" "$xs3"; do
[ "$i" = 0 ] && continue || xs=$i
if [ ! "$i" = "$SHELLSPEC_SPEC_FAILURE_CODE" ]; then
error "$msg [executor: $xs1] [reporter: $xs2] [error handler: $xs3]"
break
fi
case $i in
0) continue ;;
"$SHELLSPEC_FAILURE_EXIT_CODE") [ "$xs" ] || xs=$i ;;
"$SHELLSPEC_ERROR_EXIT_CODE") xs=$i error=1 && break ;;
*) [ "${xs#$SHELLSPEC_FAILURE_EXIT_CODE}" ] || xs=$i; error=1
esac
done
set_exit_status "$xs"
if [ "$error" ]; then
error "$msg [executor: $xs1] [reporter: $xs2] [error handler: $xs3]"
fi
set_exit_status "${xs:-0}"
)
) 3>&1 4>&2 8>&1 &&:
exit_status=$?

case $exit_status in
0) ;; # Running specs exit with successfully.
"$SHELLSPEC_SPEC_FAILURE_CODE") ;; # Running specs exit with failure.
"$SHELLSPEC_FAILURE_EXIT_CODE") ;; # Running specs exit with failure.
*) error "Fatal error occurred, terminated with exit status $exit_status."
esac

Expand Down
2 changes: 1 addition & 1 deletion libexec/shellspec-translate.sh
Expand Up @@ -192,7 +192,7 @@ trans_with_function() {

syntax_error() {
set -- "Syntax error: $1 in $specfile line $lineno" "${2:-}"
putsn "shellspec_abort $SHELLSPEC_SYNTAX_ERROR_CODE \"$1\" \"$2\" 2>&3"
putsn "shellspec_abort $SHELLSPEC_ERROR_EXIT_CODE \"$1\" \"$2\" 2>&3"
}

metadata=1 finished=1 coverage='' fd='' spec_no=1 progress=''
Expand Down
3 changes: 0 additions & 3 deletions shellspec
Expand Up @@ -38,9 +38,6 @@ export SHELLSPEC_TIME=''
export SHELLSPEC_TMPBASE=''
export SHELLSPEC_TIME_LOG=''
export SHELLSPEC_REPORTDIR=''
export SHELLSPEC_SPEC_FAILURE_CODE=101
export SHELLSPEC_STDERR_OUTPUT_CODE=102
export SHELLSPEC_SYNTAX_ERROR_CODE=103
export SHELLSPEC_BANNER_FILE=''
export SHELLSPEC_LIST=''
export SHELLSPEC_COUNT_FILE=''
Expand Down
2 changes: 1 addition & 1 deletion spec/libexec/translator_spec.sh
Expand Up @@ -366,7 +366,7 @@ Describe "libexec/translator.sh"
Context "when outside of block"
It "outputs syntax error"
When run block_end "desc"
The stdout should eq "unexpected 'End'"
The stdout should eq "Unexpected 'End'"
End
End

Expand Down

0 comments on commit 0b2c832

Please sign in to comment.