Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Source all files of a library if no loading file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnn committed Mar 22, 2017
1 parent d8d52e7 commit 451584a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ load() {
local libpath="${BATS_LIB_PATH:-$HOME/.bats/lib:/usr/lib/bats}"
libpath="$BATS_TEST_DIRNAME:$libpath"

# Test for library file in each libpath, source and return if it
# exists
for part in ${libpath//:/ }; do
filename="$part/$name.bash"
# Test for library in each libpath
for libdir in ${libpath//:/ }; do
dirname="$libdir/$name"
filename="$dirname.bash"

# Test for loading file of library
if [[ -f "$filename" ]]; then
source "$filename"
return
fi

# Test for library and source all files within
if [[ -d "$dirname" ]]; then
for libfile in $dirname/*.bash; do
source $libfile
done
return
fi
done

echo "bats: No file $name in BATS_LIB_PATH found" >&2
Expand Down

0 comments on commit 451584a

Please sign in to comment.