Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
* fix unbound variable errors with `set -u` on `setup_suite` failures (#643)
* fix `load` not being available in `setup_suite` (#644)
* fix RPM spec, add regression test (#648)
* fix handling of `IFS` by `run` (#650)

#### Documentation

Expand Down
6 changes: 2 additions & 4 deletions lib/bats-core/test_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,16 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] <command to run..

local origFlags="$-"
set +eET
local origIFS="$IFS"
if [[ $keep_empty_lines ]]; then
# 'output', 'status', 'lines' are global variables available to tests.
# preserve trailing newlines by appending . and removing it later
# shellcheck disable=SC2034
output="$($pre_command "$@"; status=$?; printf .; exit $status)" && status=0 || status=$?
output="$("$pre_command" "$@"; status=$?; printf .; exit $status)" && status=0 || status=$?
output="${output%.}"
else
# 'output', 'status', 'lines' are global variables available to tests.
# shellcheck disable=SC2034
output="$($pre_command "$@")" && status=0 || status=$?
output="$("$pre_command" "$@")" && status=0 || status=$?
fi

bats_separate_lines lines output
Expand All @@ -265,7 +264,6 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] <command to run..

# shellcheck disable=SC2034
BATS_RUN_COMMAND="${*}"
IFS="$origIFS"
set "-$origFlags"

if [[ ${BATS_VERBOSE_RUN:-} ]]; then
Expand Down
6 changes: 3 additions & 3 deletions test/pretty-formatter.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ HERE
}
run format_example_stream
# black text, green timing
[[ "${lines[1]}" == *$'\x1b[2G\x1b[1G ✓ test timing=1, timeout=0\x1b[32;22m [123]'* ]]
[[ "${lines[1]}" == *$'\x1b[2G\x1b[1G ✓ test timing=1, timeout=0\x1b[32;22m [123]'* ]] || false
# red bold text, green timing
[[ "${lines[2]}" == *$'\x1b[2G\x1b[33;1m\x1b[1G ✗ test timing=1, timeout=1\x1b[32;22m [456 (timeout: 0s)]'* ]]
[[ "${lines[4]}" == *$'2 tests, 0 failures, 1 timed out in 0 seconds'* ]]
[[ "${lines[2]}" == *$'\x1b[2G\x1b[33;1m\x1b[1G ✗ test timing=1, timeout=1\x1b[32;22m [456 (timeout: 0s)]'* ]] || false
[[ "${lines[4]}" == *'2 tests, 0 failures, 1 timed out in '*' seconds' ]] || false

format_example_stream() {
bats-format-pretty <<HERE
Expand Down
18 changes: 18 additions & 0 deletions test/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,21 @@ print-stderr-stdout() {
[ "${lines[7]}" == "# \`run -256 echo hi' failed" ]
[ "${lines[8]}" == "# Usage error: run: '-NNN': NNN must be <= 255 (got: 256)" ]
}

@test "run is not affected by IFS" {
IFS=_
run true
[ "$status" -eq 0 ]
IFS=0
run true
[ "$status" -eq 0 ]
}

@test "run does not change IFS" {
local IFS=_
run true
[ "$IFS" = _ ]
unset IFS
run true
[ "${IFS-(unset)}" = '(unset)' ]
}