Skip to content

Commit

Permalink
Output to SHELLSPEC_OUTPUT_FD instead of stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Jun 8, 2020
1 parent c729d88 commit 2af886c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/core/dsl.sh
Expand Up @@ -48,7 +48,7 @@ shellspec_finished() {
if [ "${1:-}" ]; then
shellspec_output FINISHED
else
shellspec_putsn
shellspec_output_to_fd shellspec_putsn
fi
}

Expand Down
25 changes: 15 additions & 10 deletions lib/core/output.sh
Expand Up @@ -5,6 +5,11 @@ shellspec_output() {
"shellspec_output_$@"
}

shellspec_output_to_fd() {
# shellcheck disable=SC2039
"$@" >&"$SHELLSPEC_OUTPUT_FD"
}

shellspec_output_raw() {
[ $# -gt 0 ] || return 0

Expand All @@ -13,13 +18,13 @@ shellspec_output_raw() {
shellspec_output_buf="${shellspec_output_buf}$1${SHELLSPEC_US}"
shift
done
shellspec_puts "${shellspec_output_buf}$1"
shellspec_output_to_fd shellspec_puts "${shellspec_output_buf}$1"
shellspec_output_buf=$SHELLSPEC_LF
}

shellspec_output_raw_append() {
shellspec_puts "$SHELLSPEC_US"
shellspec_putsn "$@"
shellspec_output_to_fd shellspec_puts "$SHELLSPEC_US"
shellspec_output_to_fd shellspec_putsn "$@"
}

shellspec_output_meta() {
Expand Down Expand Up @@ -63,15 +68,15 @@ shellspec_output_unless() {
}

shellspec_output_failure_message() {
shellspec_puts "${SHELLSPEC_US}failure_message:"
shellspec_output_to_fd shellspec_puts "${SHELLSPEC_US}failure_message:"
set -- "$(shellspec_output_subject)" "$(shellspec_output_expect)"
shellspec_matcher__failure_message "$@"
shellspec_output_to_fd shellspec_matcher__failure_message "$@"
}

shellspec_output_failure_message_when_negated() {
shellspec_puts "${SHELLSPEC_US}failure_message:"
shellspec_output_to_fd shellspec_puts "${SHELLSPEC_US}failure_message:"
set -- "$(shellspec_output_subject)" "$(shellspec_output_expect)"
shellspec_matcher__failure_message_when_negated "$@"
shellspec_output_to_fd shellspec_matcher__failure_message_when_negated "$@"
}

shellspec_output_following_words() {
Expand All @@ -90,9 +95,9 @@ shellspec_output_following_words() {
[ "$2" -eq "$3" ] || shellspec_puts ', '
[ $(( $2 % 8)) -ne 0 ] || shellspec_puts "$SHELLSPEC_LF"
}
shellspec_putsn
shellspec_each callback "$@"
shellspec_putsn
shellspec_output_to_fd shellspec_putsn
shellspec_output_to_fd shellspec_each callback "$@"
shellspec_output_to_fd shellspec_putsn
}

shellspec_output_syntax_name() {
Expand Down
4 changes: 2 additions & 2 deletions lib/libexec/kcov-executor.sh
Expand Up @@ -19,7 +19,7 @@ executor() {
# The directory of $SHELLSPEC_KCOV_IN_FILE should be empty
# kcov try to parse files around $SHELLSPEC_KCOV_IN_FILE
mkdir -p "${SHELLSPEC_KCOV_IN_FILE%/*}"
translator --coverage --fd=9 --progress "$@" > "$SHELLSPEC_KCOV_IN_FILE"
translator --coverage --fd=8 --progress "$@" > "$SHELLSPEC_KCOV_IN_FILE"

kcov_preprocess

Expand All @@ -33,7 +33,7 @@ executor() {
--bash-parse-files-in-dir=. \
--configure=command-name="shellspec $*" \
"$SHELLSPEC_COVERAGE_DIR" "$SHELLSPEC_KCOV_IN_FILE"
) 9>&1
)

eval "kcov_postprocess; return $?"
}
Expand Down
8 changes: 5 additions & 3 deletions lib/libexec/parallel-executor.sh
Expand Up @@ -10,8 +10,9 @@ worker() {
(mkdir "$SHELLSPEC_JOBDIR/$1.lock") 2>/dev/null || return 0
IFS= read -r specfile < "$SHELLSPEC_JOBDIR/$1.job"
translator --no-metadata --no-finished --spec-no="$1" "$specfile" \
| $SHELLSPEC_SHELL \
> "$SHELLSPEC_JOBDIR/$1.stdout" 2> "$SHELLSPEC_JOBDIR/$1.stderr" &&:
| eval "\$SHELLSPEC_SHELL" \
"$SHELLSPEC_OUTPUT_FD> \"\$SHELLSPEC_JOBDIR/\$1.stdout\"" \
"2> \"\$SHELLSPEC_JOBDIR/\$1.stderr\" &&:" &&:
echo "$?" > "$SHELLSPEC_JOBDIR/$1.status"
: > "$SHELLSPEC_JOBDIR/$1.done"
}
Expand All @@ -22,7 +23,8 @@ reduce() {
i=0
while [ $i -lt "$1" ] && i=$(($i + 1)); do
until [ -e "$SHELLSPEC_JOBDIR/$i.done" ]; do sleep 0; done
cat "$SHELLSPEC_JOBDIR/$i.stdout"
# shellcheck disable=SC2039
cat "$SHELLSPEC_JOBDIR/$i.stdout" >&"$SHELLSPEC_OUTPUT_FD"
cat "$SHELLSPEC_JOBDIR/$i.stderr" >&2
read -r exit_status < "$SHELLSPEC_JOBDIR/$i.status"
[ "$exit_status" -eq 0 ] || exit "$exit_status"
Expand Down
4 changes: 2 additions & 2 deletions libexec/shellspec-runner.sh
Expand Up @@ -136,7 +136,7 @@ fi
# and capture stderr both of the runner and the reporter
# and the stderr streams to error hander
# and also handle both exit status. As a result of
( ( ( ( set -e; executor "$@"; echo $? >&5 ) \
( ( ( ( set -e; executor "$@" 9>&1 >&8; echo $? >&5 ) \
| reporter "$@" >&3; echo $? >&5 ) 2>&1 \
| error_handler >&4; echo $? >&5 ) 5>&1 \
| (
Expand All @@ -153,7 +153,7 @@ fi
esac
set_exit_status "${xs:-1}"
)
) 3>&1 4>&2 &&:
) 3>&1 4>&2 8>&1 &&:
exit_status=$?

case $exit_status in
Expand Down
1 change: 1 addition & 0 deletions shellspec
Expand Up @@ -76,6 +76,7 @@ export SHELLSPEC_KCOV_COMMON_OPTS=''
export SHELLSPEC_KCOV_OPTS=''
export SHELLSPEC_KCOV_FILENAME=''
export SHELLSPEC_KCOV_IN_FILE=''
export SHELLSPEC_OUTPUT_FD=9
export SHELLSPEC_REPORTER_PID='.shellspec-reporter.pid'
export SHELLSPEC_PROFILER=''
export SHELLSPEC_PROFILER_LOG=''
Expand Down
1 change: 1 addition & 0 deletions spec/core/output_spec.sh
Expand Up @@ -3,6 +3,7 @@
Describe "core/output.sh"
Include "$SHELLSPEC_LIB/core/output.sh"
BeforeRun shellspec_output_buf=''
BeforeRun SHELLSPEC_OUTPUT_FD=1

Describe "shellspec_output()"
shellspec_output_ABC() { echo abc "$@"; }
Expand Down

0 comments on commit 2af886c

Please sign in to comment.