1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 03:32:27 +01:00

Source all files of a library if no loading file exists

This commit is contained in:
Nelo Wallus 2017-03-22 19:49:49 +01:00 committed by Nelo-T. Wallus
parent cb434296c5
commit e96502c7ff

View File

@ -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