mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 03:32:27 +01:00
Initial tests
This commit is contained in:
parent
c850527cce
commit
b9cfa7470c
|
@ -20,7 +20,11 @@ abs_dirname() {
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_path() {
|
expand_path() {
|
||||||
echo "$(abs_dirname "$(dirname "$1")")/$(basename "$1")"
|
{ cd "$(dirname "$1")" 2>/dev/null
|
||||||
|
local dirname="$PWD"
|
||||||
|
cd "$OLDPWD"
|
||||||
|
echo "$dirname/$(basename "$1")"
|
||||||
|
} || echo "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
BATS_LIBEXEC="$(abs_dirname "$0")"
|
BATS_LIBEXEC="$(abs_dirname "$0")"
|
||||||
|
|
|
@ -19,6 +19,15 @@ load() {
|
||||||
source "$BATS_TEST_DIRNAME/$1.bash"
|
source "$BATS_TEST_DIRNAME/$1.bash"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
local e
|
||||||
|
[[ ! "$-" =~ e ]] || e=1
|
||||||
|
set +e
|
||||||
|
output="$("$@" 2>&1)"
|
||||||
|
status="$?"
|
||||||
|
[ -z "$e" ] || set -e
|
||||||
|
}
|
||||||
|
|
||||||
abort() {
|
abort() {
|
||||||
[ "$#" -eq 0 ] || echo error: "$@" >&2
|
[ "$#" -eq 0 ] || echo error: "$@" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -43,6 +52,7 @@ bats_test_function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_exit_trap() {
|
bats_exit_trap() {
|
||||||
|
trap - err exit
|
||||||
if [ -z "$BATS_TEST_COMPLETED" ]; then
|
if [ -z "$BATS_TEST_COMPLETED" ]; then
|
||||||
echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION"
|
echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
21
test/bats.bats
Normal file
21
test/bats.bats
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
|
||||||
|
|
||||||
|
@test "running 'bats' with no arguments prints usage instructions" {
|
||||||
|
run bats
|
||||||
|
[[ $status -eq 1 ]]
|
||||||
|
[[ $output =~ ^usage: ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "running 'bats' with an invalid filename prints an error" {
|
||||||
|
run bats nonexistent
|
||||||
|
[[ $status -eq 1 ]]
|
||||||
|
[[ $output =~ does\ not\ exist ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "running 'bats' with an empty test file runs zero tests" {
|
||||||
|
run bats "$FIXTURE_ROOT/empty.bats"
|
||||||
|
[[ $status -eq 0 ]]
|
||||||
|
[[ $output = "1..0" ]]
|
||||||
|
}
|
0
test/fixtures/empty.bats
vendored
Normal file
0
test/fixtures/empty.bats
vendored
Normal file
Loading…
Reference in New Issue
Block a user