Skip to content

Commit

Permalink
Allow dirs with spaces, fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pproenca committed Jan 23, 2017
1 parent 027ac1c commit 271e96a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
16 changes: 8 additions & 8 deletions bashunit
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function bashunit.get_current_script_dir()
src="$( readlink "$src" )"

# relative symlink
[[ $src != /* ]] && src="$dir/$src"
[[ "$src" != /* ]] && src="$dir/$src"
done
dir="$( cd -P "$( dirname "$src" )" && pwd )"
echo "$dir"
Expand All @@ -40,7 +40,7 @@ for ((i=0; i<${#args[*]}; i++)); do
case "${args[i]}" in
"--bootstrap"* )
file="${args[i]//--bootstrap=/}"
bootstrap_file="$(bashunit.utils.absolutepath $file 2>/dev/null)"
bootstrap_file="$(bashunit.utils.absolutepath "$file" 2>/dev/null)"
if [ $? -ne 0 ]; then
bashunit.utils.exit_with_msg "bootstrap file '$file' does not exist!"
fi
Expand All @@ -54,21 +54,21 @@ done
# show coverage
if [ -n "${args[1]}" ]; then
show_list=0
source_dir=$(bashunit.utils.absolutepath ${args[1]})
source_dir="$(bashunit.utils.absolutepath "${args[1]}")"
if [ $? -ne 0 ]; then
bashunit.utils.exit_with_msg "source directory '$source_dir' does not exist!"
fi
if [ -n "${args[2]}" ]; then
show_list=1
fi
bashunit.test.show_coverage $source_dir ${args[0]} $show_list
bashunit.test.show_coverage "$source_dir" "${args[0]}" $show_list
fi

BASHUNIT_TESTS_DIR=$(bashunit.utils.absolutepath "${args[0]}")
target=$BASHUNIT_TESTS_DIR
if [ -f $BASHUNIT_TESTS_DIR ]; then
BASHUNIT_TESTS_DIR="$(bashunit.utils.absolutepath "${args[0]}")"
target="$BASHUNIT_TESTS_DIR"
if [ -f "$BASHUNIT_TESTS_DIR" ]; then
target="$BASHUNIT_TESTS_DIR"
BASHUNIT_TESTS_DIR=$(dirname $BASHUNIT_TESTS_DIR)
BASHUNIT_TESTS_DIR="$(dirname "$BASHUNIT_TESTS_DIR")"
fi

# load bootstrap file
Expand Down
6 changes: 5 additions & 1 deletion lib/functions.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ function bashunit.test.run_suite()
local target
bashunit.test._save_state

target=$(bashunit.utils.absolutepath "$1" 2>/dev/null)
target="$(bashunit.utils.absolutepath "$1" 2>/dev/null)"

if [ $? -ne 0 ]; then
bashunit.utils.exit_with_msg "target '$1' does not exist!"
fi
Expand All @@ -93,10 +94,13 @@ function bashunit.test.run_suite()
bashunit.utils.dir_exists_or_fail "$target"
bashunit.test._start_suite

local old_ifs="$IFS"
IFS=$'\n'
for test_suite in $(find "$target" -name "test.*sh")
do
bashunit.test._run_test_case "$test_suite"
done
IFS="$old_ifs"

bashunit.test._end_suite
return $?
Expand Down
8 changes: 4 additions & 4 deletions lib/functions.utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ function bashunit.utils.absolutepath()
fi

local dir
dir=$(dirname "$1")
if [ ! -d "$dir" ]; then
dir="$(dirname "$1")"
if [[ ! -d "$dir" ]]; then
bashunit.utils.exit_with_msg "'$dir' does not exist!"
return 1
fi

local path
path=$(cd "$dir" && pwd)/$(basename "$1")
if test ! -f "$path" && test ! -d "$path"; then
path="$(cd "$dir" && pwd)/$(basename "$1")"
if [[ ! -f "$path" ]] && [[ ! -d "$path" ]]; then
bashunit.utils.exit_with_msg "'$path' does not exist!"
return 1
fi
Expand Down

0 comments on commit 271e96a

Please sign in to comment.