1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-12-27 06:59:45 +01:00

Add -v/--version

This commit is contained in:
Sam Stephenson 2011-12-30 14:12:15 -06:00
parent 841d417b11
commit d591867b35
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
version() {
echo "Bats 0.1.0"
}
resolve_link() { resolve_link() {
$(type -p greadlink readlink | head -1) "$1" $(type -p greadlink readlink | head -1) "$1"
} }
@ -31,9 +35,16 @@ BATS_LIBEXEC="$(abs_dirname "$0")"
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
export PATH="$BATS_LIBEXEC:$PATH" export PATH="$BATS_LIBEXEC:$PATH"
if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
version
exit 0
fi
filename="$1" filename="$1"
if [ -z "$filename" ]; then if [ -z "$filename" ]; then
echo "usage: $0 <filename>" >&2 { version
echo "usage: $0 <filename>"
} >&2
exit 1 exit 1
else else
shift shift

View File

@ -10,7 +10,13 @@ teardown() {
@test "no arguments prints usage instructions" { @test "no arguments prints usage instructions" {
run bats run bats
[ $status -eq 1 ] [ $status -eq 1 ]
[ $(expr "$output" : "usage:") -ne 0 ] [ $(expr "${lines[1]}" : "usage:") -ne 0 ]
}
@test "-v and --version print version number" {
run bats -v
[ $status -eq 0 ]
[ $(expr "$output" : "Bats [0-9][0-9.]*") -ne 0 ]
} }
@test "invalid filename prints an error" { @test "invalid filename prints an error" {