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
4 changes: 3 additions & 1 deletion bin/bats
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ if ! BATS_PATH=$(bats_readlinkf "${BASH_SOURCE[0]}" 2>/dev/null); then
fi

export BATS_SAVED_PATH=$PATH
BATS_BASE_LIBDIR=lib # this will be patched with the true value in install.sh

export BATS_ROOT=${BATS_PATH%/*/*}
export -f bats_readlinkf
exec env BATS_ROOT="$BATS_ROOT" "$BATS_ROOT/libexec/bats-core/bats" "$@"
exec env BATS_ROOT="$BATS_ROOT" BATS_LIBDIR="${BATS_BASE_LIBDIR:-lib}" "$BATS_ROOT/libexec/bats-core/bats" "$@"
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog][kac] and this project adheres to

### Fixed

* `install.sh` now works for deviating `lib/` dirs (like `lib32`,`lib64`) (#487)

#### Documentation

* clarify docker usage (#741)
Expand Down
14 changes: 10 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
set -e

BATS_ROOT="${0%/*}"
PREFIX="$1"
PREFIX="${1%/}"
LIBDIR="${2:-lib}"

if [[ -z "$PREFIX" ]]; then
printf '%s\n' \
"usage: $0 <prefix>" \
" e.g. $0 /usr/local" >&2
"usage: $0 <prefix> [base_libdir]" \
" e.g. $0 /usr/local" \
" $0 /usr/local lib64" >&2
exit 1
fi

install -d -m 755 "$PREFIX"/{bin,libexec/bats-core,"${LIBDIR}"/bats-core,share/man/man{1,7}}
install -d -m 755 "$PREFIX"/{bin,libexec/bats-core,"${LIBDIR}"/bats-core,share/{bats,man/man{1,7}}}

install -m 755 "$BATS_ROOT/bin"/* "$PREFIX/bin"
install -m 755 "$BATS_ROOT/libexec/bats-core"/* "$PREFIX/libexec/bats-core"
install -m 755 "$BATS_ROOT/lib/bats-core"/* "$PREFIX/${LIBDIR}/bats-core"
install -m 644 "$BATS_ROOT/man/bats.1" "$PREFIX/share/man/man1"
install -m 644 "$BATS_ROOT/man/bats.7" "$PREFIX/share/man/man7"

read -rd '' BATS_EXE_CONTENTS <"$PREFIX/bin/bats" || true
BATS_EXE_CONTENTS=${BATS_EXE_CONTENTS/"BATS_BASE_LIBDIR=lib"/"BATS_BASE_LIBDIR=${LIBDIR}"}
printf "%s" "$BATS_EXE_CONTENTS" > "$PREFIX/bin/bats"

echo "Installed Bats to $PREFIX/bin/bats"
4 changes: 2 additions & 2 deletions lib/bats-core/test_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BATS_TEST_DIRNAME="${BATS_TEST_FILENAME%/*}"
BATS_TEST_NAMES=()

# shellcheck source=lib/bats-core/warnings.bash
source "$BATS_ROOT/lib/bats-core/warnings.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/warnings.bash"

# find_in_bats_lib_path echoes the first recognized load path to
# a library in BATS_LIB_PATH or relative to BATS_TEST_DIRNAME.
Expand Down Expand Up @@ -276,7 +276,7 @@ bats_pipe() { # [-N] [--] command0 [ \| command1 [ \| command2 [...]]]

# run commands and return appropriate pipe status
local -a __bats_pipe_eval_pipe_status=()
eval "${escaped_args[@]}" '; __bats_pipe_eval_pipe_status=(${PIPESTATUS[@]})'
eval "${escaped_args[*]}" '; __bats_pipe_eval_pipe_status=(${PIPESTATUS[@]})'

local result_status=
if [ -z "$pipestatus_position" ]; then
Expand Down
4 changes: 2 additions & 2 deletions lib/bats-core/tracing.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# shellcheck source=lib/bats-core/common.bash
source "$BATS_ROOT/lib/bats-core/common.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash"

bats_capture_stack_trace() {
local test_file
Expand Down Expand Up @@ -336,7 +336,7 @@ bats_setup_tracing() {
BATS_ERROR_SUFFIX=
BATS_DEBUG_EXCLUDE_PATHS=()
# exclude some paths by default
bats_add_debug_exclude_path "$BATS_ROOT/lib/"
bats_add_debug_exclude_path "$BATS_ROOT/$BATS_LIBDIR/"
bats_add_debug_exclude_path "$BATS_ROOT/libexec/"

exec 4<&1 # used for tracing
Expand Down
2 changes: 1 addition & 1 deletion lib/bats-core/warnings.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# shellcheck source=lib/bats-core/tracing.bash
source "$BATS_ROOT/lib/bats-core/tracing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash"

# generate a warning report for the parent call's call site
bats_generate_warning() { # <warning number> [--no-stacktrace] [<printf args for warning string>...]
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ if [[ -n "$setup_suite_file" ]]; then
fi

# shellcheck source=lib/bats-core/validator.bash
source "$BATS_ROOT/lib/bats-core/validator.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/validator.bash"

trap 'BATS_INTERRUPTED=true' INT # let the lower levels handle the interruption

Expand Down
10 changes: 5 additions & 5 deletions libexec/bats-core/bats-exec-file
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export BATS_TEST_FILENAME="$filename"

# shellcheck source=lib/bats-core/preprocessing.bash
# shellcheck disable=SC2153
source "$BATS_ROOT/lib/bats-core/preprocessing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/preprocessing.bash"

bats_run_setup_file() {
# shellcheck source=lib/bats-core/tracing.bash
# shellcheck disable=SC2153
source "$BATS_ROOT/lib/bats-core/tracing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash"
# shellcheck source=lib/bats-core/test_functions.bash
# shellcheck disable=SC2153
source "$BATS_ROOT/lib/bats-core/test_functions.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash"

exec 3<&1

Expand Down Expand Up @@ -125,7 +125,7 @@ bats_file_teardown_trap() {
}

# shellcheck source=lib/bats-core/common.bash
source "$BATS_ROOT/lib/bats-core/common.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash"

# shellcheck disable=SC2317
bats_file_exit_trap() {
Expand Down Expand Up @@ -243,7 +243,7 @@ bats_run_tests_in_parallel() {
local status=0
mkdir -p "$output_folder"
# shellcheck source=lib/bats-core/semaphore.bash
source "$BATS_ROOT/lib/bats-core/semaphore.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/semaphore.bash"
bats_semaphore_setup
# the test_number_in_file is not yet incremented -> one before the next test to run
local test_number_in_suite_of_last_finished_test="$BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE" # stores which test was printed last
Expand Down
8 changes: 4 additions & 4 deletions libexec/bats-core/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abort() {
}

# shellcheck source=lib/bats-core/common.bash disable=SC2153
source "$BATS_ROOT/lib/bats-core/common.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash"

while [[ "$#" -ne 0 ]]; do
case "$1" in
Expand Down Expand Up @@ -106,7 +106,7 @@ if [[ "$num_jobs" != 1 ]]; then
abort "Cannot execute \"${num_jobs}\" jobs without GNU parallel"
fi
# shellcheck source=lib/bats-core/semaphore.bash
source "${BATS_ROOT}/lib/bats-core/semaphore.bash"
source "${BATS_ROOT}/$BATS_LIBDIR/bats-core/semaphore.bash"
bats_semaphore_setup
fi

Expand Down Expand Up @@ -348,7 +348,7 @@ fi
IFS=$'\n' read -d '' -r -a BATS_UNIQUE_TEST_FILENAMES < <(printf "%s\n" "$@" | nl | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-) || true

# shellcheck source=lib/bats-core/tracing.bash
source "$BATS_ROOT/lib/bats-core/tracing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash"
bats_setup_tracing

trap bats_suite_exit_trap EXIT
Expand Down Expand Up @@ -425,7 +425,7 @@ if [[ -n "$setup_suite_file" ]]; then
# shellcheck disable=SC2034 # will be used in the sourced file below
BATS_TEST_FILENAME="$setup_suite_file"
# shellcheck source=lib/bats-core/test_functions.bash
source "$BATS_ROOT/lib/bats-core/test_functions.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash"

# shellcheck disable=SC1090
source "$setup_suite_file"
Expand Down
8 changes: 4 additions & 4 deletions libexec/bats-core/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ bats_create_test_tmpdirs() {

# load the test helper functions like `load` or `run` that are needed to run a (preprocessed) .bats file without bash errors
# shellcheck source=lib/bats-core/test_functions.bash disable=SC2153
source "$BATS_ROOT/lib/bats-core/test_functions.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash"
# shellcheck source=lib/bats-core/tracing.bash disable=SC2153
source "$BATS_ROOT/lib/bats-core/tracing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash"

bats_teardown_trap() {
bats_check_status_from_trap
Expand Down Expand Up @@ -109,7 +109,7 @@ bats_teardown_trap() {
}

# shellcheck source=lib/bats-core/common.bash
source "$BATS_ROOT/lib/bats-core/common.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash"

bats_exit_trap() {
local status
Expand Down Expand Up @@ -352,7 +352,7 @@ bats_perform_test() {
trap bats_interrupt_trap INT

# shellcheck source=lib/bats-core/preprocessing.bash
source "$BATS_ROOT/lib/bats-core/preprocessing.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/preprocessing.bash"

exec 3<&1

Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-format-junit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

# shellcheck source=lib/bats-core/formatter.bash
source "$BATS_ROOT/lib/bats-core/formatter.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash"

BASE_PATH=.

Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-format-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

# shellcheck source=lib/bats-core/formatter.bash
source "$BATS_ROOT/lib/bats-core/formatter.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash"

BASE_PATH=.
BATS_ENABLE_TIMING=
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-format-tap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e
trap '' INT

# shellcheck source=lib/bats-core/formatter.bash
source "$BATS_ROOT/lib/bats-core/formatter.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash"

bats_tap_stream_plan() {
printf "1..%d\n" "$1"
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-format-tap13
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trap '' INT
number_of_printed_log_lines_for_this_test_so_far=0

# shellcheck source=lib/bats-core/formatter.bash
source "$BATS_ROOT/lib/bats-core/formatter.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash"

bats_tap_stream_plan() {
printf "TAP version 13\n"
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-preprocess
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ BATS_VALID_TAG_PATTERN="[-_:[:alnum:]]+"
BATS_VALID_TAGS_PATTERN="^ *($BATS_VALID_TAG_PATTERN)?( *, *$BATS_VALID_TAG_PATTERN)* *$"

# shellcheck source=lib/bats-core/common.bash
source "$BATS_ROOT/lib/bats-core/common.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash"

extract_tags() { # <tag_type/return_var> <tags-string>
local -r tag_type=$1 tags_string=$2
Expand Down
2 changes: 1 addition & 1 deletion shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ if [[ $1 == --list ]]; then
exit 0
fi

LC_ALL=C.UTF-8 shellcheck "${targets[@]}"
LC_ALL=C.UTF-8 shellcheck -x "${targets[@]}"

exit $?
2 changes: 1 addition & 1 deletion test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ END_OF_ERR_MSG

@test "test count validator catches mismatch and returns non zero" {
# shellcheck source=lib/bats-core/validator.bash
source "$BATS_ROOT/lib/bats-core/validator.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/validator.bash"
export -f bats_test_count_validator
reentrant_run bash -c "echo $'1..1\n' | bats_test_count_validator"
[[ $status -ne 0 ]]
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/formatter/echo-formatter
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

# shellcheck source=lib/bats-core/formatter.bash
source "$BATS_ROOT/lib/bats-core/formatter.bash"
source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash"

bats_tap_stream_plan() {
echo "STREAM_PLAN: $1"
Expand Down
24 changes: 12 additions & 12 deletions test/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ setup() {
[ "$status" -eq 0 ]
[ "$output" == "Installed Bats to $INSTALL_DIR/bin/bats" ]
[ -x "$INSTALL_DIR/bin/bats" ]
[ -x "$INSTALL_DIR/lib/bats-core/formatter.bash" ]
[ -x "$INSTALL_DIR/lib/bats-core/preprocessing.bash" ]
[ -x "$INSTALL_DIR/lib/bats-core/semaphore.bash" ]
[ -x "$INSTALL_DIR/lib/bats-core/test_functions.bash" ]
[ -x "$INSTALL_DIR/lib/bats-core/tracing.bash" ]
[ -x "$INSTALL_DIR/lib/bats-core/validator.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/formatter.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/preprocessing.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/semaphore.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/test_functions.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/tracing.bash" ]
[ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/validator.bash" ]
[ -x "$INSTALL_DIR/libexec/bats-core/bats" ]
[ -x "$INSTALL_DIR/libexec/bats-core/bats-exec-suite" ]
[ -x "$INSTALL_DIR/libexec/bats-core/bats-exec-test" ]
Expand All @@ -39,12 +39,12 @@ setup() {
run "$PATH_TO_UNINSTALL_SHELL" "$INSTALL_DIR"
[ "$status" -eq 0 ]
[ ! -x "$INSTALL_DIR/bin/bats" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/formatter.bash" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/preprocessing.bash" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/semaphore.bash" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/test_functions.bash" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/tracing.bash" ]
[ ! -x "$INSTALL_DIR/lib/bats-core/validator.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/formatter.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/preprocessing.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/semaphore.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/test_functions.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/tracing.bash" ]
[ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/validator.bash" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-suite" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-test" ]
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ execute_with_unset_bats_vars() { # <command to execute...>
"$@"
}

REENTRANT_RUN_PRESERVE+=(BATS_SAVED_PATH BATS_ROOT BATS_TEST_TAGS BATS_PARALLEL_BINARY_NAME)
REENTRANT_RUN_PRESERVE+=(BATS_SAVED_PATH BATS_ROOT BATS_TEST_TAGS BATS_PARALLEL_BINARY_NAME BATS_LIBDIR)

# call run with all BATS_* variables purged from the environment
reentrant_run() { # <same args as run>
Expand Down
46 changes: 35 additions & 11 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,61 @@
set -e

BATS_ROOT="${0%/*}"
PREFIX="$1"
LIBDIR="${2:-lib}"
PREFIX="${1%/}"

if [[ -z "$PREFIX" ]]; then
printf '%s\n' \
"usage: $0 <prefix>" \
" e.g. $0 /usr/local" >&2
"usage: $0 <prefix> [base_libdir]" \
" e.g. $0 /usr/local" \
" $0 /usr/local lib64" >&2
exit 1
fi

if [[ ! -d "$PREFIX" ]]; then
printf "No valid installation in directory %s.\n" "$PREFIX"
exit 2
fi

if [ -e "$PREFIX/bin/bats" ]; then
LIBDIR=$(grep -e '^BATS_BASE_LIBDIR=' "$PREFIX/bin/bats")
eval "$LIBDIR"
fi
LIBDIR="${BATS_BASE_LIBDIR:-lib}"

remove_file() { # <file>
echo "Removing $1"
rm -f "$1"
}

remove_directory() { # <directory>
local directory=$1
if [[ -d "$directory" ]]; then
echo "Removing $directory"
rmdir "$directory"
fi
}

d="$PREFIX/bin"
for elt in "$BATS_ROOT/bin"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
remove_file "$d/$elt"
done

d="$PREFIX/libexec/bats-core"
for elt in "$BATS_ROOT/libexec/bats-core"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
remove_file "$d/$elt"
done
[[ -d "$d" ]] && rmdir "$d"
remove_directory "$d"

d="$PREFIX/${LIBDIR}/bats-core"
for elt in "$BATS_ROOT/lib/bats-core"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
remove_file "$d/$elt"
done
[[ -d "$d" ]] && rmdir "$d"
remove_directory "$d"

rm -f "$PREFIX"/share/man/man1/bats.1
rm -f "$PREFIX"/share/man/man7/bats.7
remove_file "$PREFIX"/share/man/man1/bats.1
remove_file "$PREFIX"/share/man/man7/bats.7

echo "Uninstalled Bats from $PREFIX/bin/bats"