-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
source "$(dirname "${BASH_SOURCE[0]}")/src/output.bash" | ||
source "$(dirname "${BASH_SOURCE[0]}")/src/error.bash" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# bats-support - Supporting library for Bats test helpers | ||
# | ||
# Written in 2016 by Zoltan Tombol <zoltan dot tombol at gmail dot com> | ||
# | ||
# To the extent possible under law, the author(s) have dedicated all | ||
# copyright and related and neighboring rights to this software to the | ||
# public domain worldwide. This software is distributed without any | ||
# warranty. | ||
# | ||
# You should have received a copy of the CC0 Public Domain Dedication | ||
# along with this software. If not, see | ||
# <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
# | ||
|
||
# | ||
# error.bash | ||
# ---------- | ||
# | ||
# Functions implementing error reporting. Used by public helper | ||
# functions or test suits directly. | ||
# | ||
|
||
# Fail and display a message. When no parameters are specified, the | ||
# message is read from the standard input. Other functions use this to | ||
# report failure. | ||
# | ||
# Globals: | ||
# none | ||
# Arguments: | ||
# $@ - [=STDIN] message | ||
# Returns: | ||
# 1 - always | ||
# Inputs: | ||
# STDIN - [=$@] message | ||
# Outputs: | ||
# STDERR - message | ||
fail() { | ||
(( $# == 0 )) && batslib_err || batslib_err "$@" | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
@test 'fail() <message>: returns 1 and displays <message>' { | ||
run fail 'message' | ||
[ "$status" -eq 1 ] | ||
[ "$output" == 'message' ] | ||
} | ||
|
||
@test 'fail(): reads <message> from STDIN' { | ||
run bash -c "source '${TEST_MAIN_DIR}/load.bash' | ||
echo 'message' | fail" | ||
[ "$status" -eq 1 ] | ||
[ "$output" == 'message' ] | ||
} |