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
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
* `teardown_file` errors don't swallow `setup_file` errors anymore, the behavior
is more like `teardown`'s now (only `return`/last command can trigger `teardown`
errors) (#623)
* upgraded from deprecated CI envs for MacOS (10 -> 11,12) and Ubuntu
* upgraded from deprecated CI envs for MacOS (10 -> 11,12) and Ubuntu
(18.04 -> 22.04) (#630)
* add `/usr/lib/bats` as default value for `BATS_LIB_PATH` (#628)

#### Documentation

Expand Down
10 changes: 0 additions & 10 deletions lib/bats-core/test_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,9 @@ bats_load_safe() {
return 1
}

bats_require_lib_path() {
if [[ -z "${BATS_LIB_PATH:-}" ]]; then
printf "%s: requires BATS_LIB_PATH to be set!\n" "${FUNCNAME[1]}" >&2
exit 1
fi
}

bats_load_library_safe() { # <slug>
local slug="${1:?}" library_path

bats_require_lib_path

# Check for library load paths in BATS_TEST_DIRNAME and BATS_LIB_PATH
if [[ ${slug:0:1} != / ]]; then
find_in_bats_lib_path library_path "$slug"
Expand All @@ -151,7 +142,6 @@ bats_load_library_safe() { # <slug>

# immediately exit on error, use bats_load_library_safe to catch and handle errors
bats_load_library() { # <slug>
bats_require_lib_path
if ! bats_load_library_safe "$@"; then
exit 1
fi
Expand Down
1 change: 1 addition & 0 deletions libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export BATS_TMPDIR="${TMPDIR:-/tmp}"
BATS_TMPDIR=${BATS_TMPDIR%/} # chop off trailing / to avoid duplication
export BATS_RUN_TMPDIR=
export BATS_GUARANTEED_MINIMUM_VERSION=0.0.0
export BATS_LIB_PATH=${BATS_LIB_PATH-/usr/lib/bats}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the drive-by comment, but shouldn't this be ${BATS_LIB_PATH:-/usr/lib/bats}? (Note the colon.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only translated this from the original Code but I assumed the intention is to allow for users to specify an empty search path. This would mit ve possible with colon.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but the syntax for that is ${var:-default}, not ${var-default}, right? (Bash docs)

Copy link
Member

@martin-schulze-vireso martin-schulze-vireso Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, :- is alternative value for unset or empty, - only replaces unset variables. Or from your link:

Omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the operator tests for both parameter’s existence and that its value is not null; if the colon is omitted, the operator tests only for existence.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that. Thank you for the explanation!


if [[ ! -d "${BATS_TMPDIR}" ]];then
printf "Error: BATS_TMPDIR (%s) does not exist or is not a directory" "${BATS_TMPDIR}" >&2
Expand Down
8 changes: 1 addition & 7 deletions test/load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ setup() {
run -0 bats "$FIXTURE_ROOT/load.bats"
}

@test "bats_load_library requires BATS_LIB_PATH to be set" {
unset BATS_LIB_PATH
run ! bats "$FIXTURE_ROOT/bats_load_library.bats"
[ "${lines[4]}" == '# bats_load_library: requires BATS_LIB_PATH to be set!' ]
}

@test "bats_load_library supports libraries with loaders on the BATS_LIB_PATH" {
path_dir="$BATS_TEST_TMPDIR/libraries/$BATS_TEST_NAME"
mkdir -p "$path_dir"
Expand Down Expand Up @@ -192,4 +186,4 @@ setup() {
[ "${lines[1]}" = "not ok 1 failed" ]
[ "${lines[3]}" = "# \`false' failed" ]
[ ${#lines[@]} -eq 4 ]
}
}