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

Commit

Permalink
Merge pull request #56 from ahippo/load-abs
Browse files Browse the repository at this point in the history
Make `load` handle absolute paths too
  • Loading branch information
sstephenson committed Jun 1, 2014
2 parents 219fca7 + 35f9630 commit 6b4802c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
BATS_TEST_NAMES=()

load() {
local filename="$BATS_TEST_DIRNAME/$1.bash"
local inc="$1"
local filename

if [[ "${inc}" == "/"* ]] ; then
filename="${inc}"
else
filename="$BATS_TEST_DIRNAME/${inc}.bash"
fi
[ -f "$filename" ] || {
echo "bats: $filename does not exist" >&2
exit 1
}

source "$BATS_TEST_DIRNAME/$1.bash"
source "${filename}"
}

run() {
Expand Down
10 changes: 10 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ fixtures bats
[ $status -eq 1 ]
}

@test "load sources scripts by absolute path" {
HELPER_NAME="${FIXTURE_ROOT}/test_helper.bash" run bats "$FIXTURE_ROOT/load.bats"
[ $status -eq 0 ]
}

@test "load aborts if the script, specified by an absolute path, does not exist" {
HELPER_NAME="${FIXTURE_ROOT}/nonexistent" run bats "$FIXTURE_ROOT/load.bats"
[ $status -eq 1 ]
}

@test "output is discarded for passing tests and printed for failing tests" {
run bats "$FIXTURE_ROOT/output.bats"
[ $status -eq 1 ]
Expand Down

0 comments on commit 6b4802c

Please sign in to comment.