Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* bash-tap 1.0.4 (2015-05-30-22:05)
* Updated skip() function and 'plan skip_all desc'
* Updated BAIL_OUT() function. Test named bailout.t2 and an be
run with 'prove -v t/bailout.t2'. It will fail, as expected.
* Added t/ directory with example tests

* bash-tap 1.0.3 (2015-05-29-23:30)
* Add note() function, similar in nature to diag()

* bash-tap 1.0.2 (2013-05-19-00:59)
* Make bash-tap-mock work with -e.
Contributed by Daniel Nephin (@dnephin).
Expand Down
3 changes: 3 additions & 0 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ total_rowsets=2

plan tests $(((columns_per_row * max_rows_per_rowset * total_rowsets) + total_rowsets))

note "This note will be seen with 'prove test.t'"
diag "This diag will be seen with 'prove -v test.t'"

# Test data, resultset 1
results1="artist Assemblage 23
track Naked (God Module RMX)
Expand Down
34 changes: 31 additions & 3 deletions bash-tap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

bash_tap_version='1.0.2'
bash_tap_version='1.0.5'

# Our state.

Expand Down Expand Up @@ -111,6 +111,7 @@ function has_plan() {
function skip_all() {
local reason="${*:?}"

_bt_plan="skip all"
_bt_output_plan 0 SKIP "$reason"
}

Expand Down Expand Up @@ -237,11 +238,26 @@ function cmp_ok() {
# Other helper functions

function BAIL_OUT() {
echo TODO
# Note: it is up to the calling shell script to stop testing after this function is called

local message="$1"
_bt_escaped_echo "Bail out! $message"
}

function skip() {
echo TODO
local message="$1"
local pattern="$2"
local name="$3"

_bt_current_test=$((_bt_current_test + 1))

if [ -n "$message" ]; then
if [ "$_bt_plan" == "skip all" ]; then
_bt_escaped_echo "#skip $name"
else
_bt_escaped_echo "ok # skip $name"
fi
fi
}

function todo_skip() {
Expand All @@ -266,6 +282,18 @@ function diag() {
fi
}

function note() {
local message="$*"

if [ -n "$message" ]; then
local output=''
while IFS= read -r line; do
output="$output\n# $line"
done <<<"$message"
echo -e "# ${output:4}" >&2
fi
}

# Util functions for output capture within current shell

function start_output_capture() {
Expand Down
20 changes: 17 additions & 3 deletions bash-tap-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# It takes care of finding bash-tap or outputing a usage message.
#

bash_tap_bootstrap_version='1.0.2'
bash_tap_bootstrap_version='1.0.3'

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
# Being run directly, probably by test harness running entire dir.
Expand All @@ -16,8 +16,22 @@ if [ "${BASH_SOURCE[0]}" = "$0" ]; then
fi

if [ -z "$BASH_TAP_ROOT" ]; then
# TODO: search likely locations.
BASH_TAP_ROOT="$(dirname ${BASH_SOURCE[0]})/../../bash-tap"
BASH_TAP_ROOT="$(dirname ${BASH_SOURCE[0]})/../../"
fi


##### search likely locations.

if [ -f "$HOME/bash-tap/bash-tap" ]; then
BASH_TAP_ROOT="$HOME/bash-tap/"
fi

if [ -f "$HOME/bash-tap" ]; then
BASH_TAP_ROOT="$HOME/"
fi

if [ -f "./bash-tap" ]; then
BASH_TAP_ROOT="./"
fi

if [ -f "$BASH_TAP_ROOT/bash-tap" ]; then
Expand Down
14 changes: 14 additions & 0 deletions t/bailout.t2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan tests 3

is "hello" "hello" "plan test 1"
if [ 1 -eq 1 ]
then
BAIL_OUT "Error, 1 equal 1!"
exit
fi
is "hello" "hello" "plan test 2"
like "hello" "hell" "plan test 3"
42 changes: 42 additions & 0 deletions t/bash-tap-bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Bash TAP Bootstrap:
# Copy this file into your project tests dir and source it
# from each test file with:
# . $(dirname $0)/bash-tap-bootstrap
# It takes care of finding bash-tap or outputing a usage message.
#

bash_tap_bootstrap_version='1.0.3'

if [ "${BASH_SOURCE[0]}" = "$0" ]; then
# Being run directly, probably by test harness running entire dir.
echo "1..0 # SKIP bash-tap-bootstrap isn't a test file"
exit 0
fi

if [ -z "$BASH_TAP_ROOT" ]; then
BASH_TAP_ROOT="$(dirname ${BASH_SOURCE[0]})/../../"
fi


##### search likely locations.

if [ -f "$HOME/bash-tap/bash-tap" ]; then
BASH_TAP_ROOT="$HOME/bash-tap/"
fi

if [ -f "$HOME/bash-tap" ]; then
BASH_TAP_ROOT="$HOME/"
fi

if [ -f "./bash-tap" ]; then
BASH_TAP_ROOT="./"
fi

if [ -f "$BASH_TAP_ROOT/bash-tap" ]; then
. "$BASH_TAP_ROOT/bash-tap"
else
echo "Bail out! Unable to find bash-tap. Install from https://github.com/illusori/bash-tap or set \$BASH_TAP_ROOT if you have it installed somewhere unusual."
exit 255
fi
11 changes: 11 additions & 0 deletions t/no_plan.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan no_plan

is "hello" "hello" "no_plan test 1"
is "hello" "hello" "no_plan test 2"
like "hello" "hell" "no_plan test 3"

done_testing
12 changes: 12 additions & 0 deletions t/note_diag.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan no_plan

is "hello" "hello" "note_diag test 1"

note "This note will be seen with 'prove test.t'"
diag "This diag will be seen with 'prove -v test.t'"

done_testing
11 changes: 11 additions & 0 deletions t/ok.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan tests 5

ok "1" "plan test 1"
ok "100" "plan test 2"
ok "-1" "plan test 3"
ok "" "plan test 4"
ok "hello" "plan test 5"
9 changes: 9 additions & 0 deletions t/plan.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan tests 3

is "hello" "hello" "plan test 1"
is "hello" "hello" "plan test 2"
like "hello" "hell" "plan test 3"
11 changes: 11 additions & 0 deletions t/skip.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan no_plan

is "hello" "hello" "hello test 1"
skip "hello" "hello" "hello test 2"
like "hello" "hell" "hello test 3"

done_testing
10 changes: 10 additions & 0 deletions t/skip_all.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

. $(dirname $0)/bash-tap-bootstrap

plan skip_all "skip_all testing.. for fun and profit"

skip "hello" "hello" "skip_all test 1"
skip "hello" "hello" "skip_all test 2"
skip "hello" "hell" "skip_all test 3"