From d591867b356566bb419433cca8fab8de5ed01104 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 30 Dec 2011 14:12:15 -0600 Subject: [PATCH] Add -v/--version --- libexec/bats | 13 ++++++++++++- test/bats.bats | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libexec/bats b/libexec/bats index 9a22cfa..67f9ab3 100755 --- a/libexec/bats +++ b/libexec/bats @@ -1,6 +1,10 @@ #!/usr/bin/env bash set -e +version() { + echo "Bats 0.1.0" +} + resolve_link() { $(type -p greadlink readlink | head -1) "$1" } @@ -31,9 +35,16 @@ BATS_LIBEXEC="$(abs_dirname "$0")" export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" export PATH="$BATS_LIBEXEC:$PATH" +if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then + version + exit 0 +fi + filename="$1" if [ -z "$filename" ]; then - echo "usage: $0 " >&2 + { version + echo "usage: $0 " + } >&2 exit 1 else shift diff --git a/test/bats.bats b/test/bats.bats index 8a57b55..f230ab3 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -10,7 +10,13 @@ teardown() { @test "no arguments prints usage instructions" { run bats [ $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" {