-
Notifications
You must be signed in to change notification settings - Fork 35
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
1 parent
3453072
commit e159905
Showing
5 changed files
with
115 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
|
||
[submodule "base/test_helper/bats-support"] | ||
path = base/test_helper/bats-support | ||
url = https://github.com/bats-core/bats-support | ||
path = base/test_helper/bats-support | ||
url = https://github.com/bats-core/bats-support | ||
[submodule "base/test_helper/bats-assert"] | ||
path = base/test_helper/bats-assert | ||
url = https://github.com/bats-core/bats-assert | ||
path = base/test_helper/bats-assert | ||
url = https://github.com/bats-core/bats-assert | ||
[submodule "base/test_helper/bats-file"] | ||
path = base/test_helper/bats-file | ||
url = https://github.com/ztombol/bats-file | ||
[submodule "base/test_helper/bats-mock"] | ||
path = base/test_helper/bats-mock | ||
url = https://github.com/lox/bats-mock | ||
path = base/test_helper/bats-file | ||
url = https://github.com/ztombol/bats-file |
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,4 @@ | ||
#!/bin/bash | ||
|
||
here=$(dirname "$0") | ||
cp "$here"/validate.bash ~/.validate.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,83 @@ | ||
# To use these input validation functions, | ||
# include in a bash command af follows: | ||
# # shellcheck source=/dev/null | ||
# source ~/.validate.bash | ||
# Default error number is 2. | ||
|
||
ERR_INVALID_INPUT=${1:-2} | ||
|
||
function error() { | ||
echo "ERR_INVALID_INPUT" "$1" | ||
exit "$ERR_INVALID_INPUT" | ||
} | ||
|
||
function exists() { | ||
if ! [ -e "$1" ]; then | ||
error "$1 not found" | ||
fi | ||
} | ||
|
||
function file() { | ||
if ! [ -f "$1" ]; then | ||
error "$1 is not a file" | ||
fi | ||
} | ||
|
||
function directory() { | ||
if ! [ -d "$1" ]; then | ||
error "$1 is not a directory" | ||
fi | ||
} | ||
|
||
function readable() { | ||
if ! [ -r "$1" ]; then | ||
error "$1 is not readable" | ||
fi | ||
} | ||
|
||
function writable() { | ||
if ! [ -w "$1" ]; then | ||
error "$1 is not writable" | ||
fi | ||
} | ||
|
||
function executable() { | ||
if ! [ -x "$1" ]; then | ||
error "$1 is not executable" | ||
fi | ||
} | ||
|
||
function readable_file() { | ||
readable "$1" | ||
file "$1" | ||
} | ||
|
||
function integer() { | ||
local key=$1 | ||
local value=$2 | ||
if ! [ "$value" -eq "$value" ]; then | ||
error "$key: $value is not an integer" | ||
fi | ||
} | ||
|
||
function positive_integer() { | ||
local key=$1 | ||
local value=$2 | ||
if ! [ "$value" -ge 0 ]; then | ||
error "$key: $value is not a positive integer" | ||
fi | ||
} | ||
|
||
function length() { | ||
local key=$1 | ||
local value=$2 | ||
local length=$3 | ||
if ! [ "${#value}" -eq "$length" ]; then | ||
error "$key: $value is not $length characters long" | ||
fi | ||
} | ||
|
||
function positive_integer_length() { | ||
positive_integer "$1" "$2" | ||
length "$1" "$2" "$3" | ||
} |
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,12 @@ | ||
#!/bin/bash | ||
|
||
if ! command -v bats; then | ||
bats_url=https://github.com/bats-core/bats-core | ||
echo "WARN - Cannot test without [bats]($bats_url); continuing without running any tests now." | ||
echo "Consider npm install -g bats" | ||
exit | ||
fi | ||
|
||
"$DOCKER_BASE"/plugins/validate/install.sh | ||
|
||
time bats -r "${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,10 @@ | ||
# Start any bats file with: | ||
# #!/usr/bin/env bats | ||
# load "$DOCKER_BASE"/test_helper/load.bash | ||
|
||
base=$(basename "$BATS_TEST_FILENAME" .bats) | ||
cmd="$BATS_TEST_DIRNAME"/"$base" | ||
|
||
load "$DOCKER_BASE"/test_helper/bats-support/load.bash | ||
load "$DOCKER_BASE"/test_helper/bats-assert/load.bash | ||
load "$DOCKER_BASE"/test_helper/bats-file/load.bash |