Improve test runner (#41)

This commit is contained in:
Denis Isidoro 2019-09-23 08:56:15 -03:00 committed by GitHub
parent be92d158ad
commit b3f8e0b374
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 34 deletions

View file

@ -40,9 +40,9 @@ opts::eval() {
--command-for) wait_for="command-for" ;;
--no-preview) preview=false ;;
--path) wait_for="path" ;;
search) entry_point="search"; wait_for="search";;
preview) entry_point="preview"; wait_for="preview";;
q|query) wait_for="query";;
search) entry_point="search"; wait_for="search" ;;
preview) entry_point="preview"; wait_for="preview" ;;
q|query) wait_for="query" ;;
esac
done
}

4
test/cheat_test.sh Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
test::run "We can find at least one known cheatsheet" \
'cheat::find | grep -q "docker.cheat"'

View file

@ -2,13 +2,18 @@
source "${SCRIPT_DIR}/src/main.sh"
PASSED=0
FAILED=0
test::success() {
PASSED=$((PASSED+1))
echo "Test passed!"
}
test::fail() {
FAILED=$((FAILED+1))
echo "Test failed..."
exit 42
return
}
test::run() {
@ -17,3 +22,14 @@ test::run() {
shift
eval "$*" && test::success || test::fail
}
test::finish() {
echo
if [ $FAILED -gt 0 ]; then
echo "${PASSED} tests passed but ${FAILED} failed... :("
exit "${FAILED}"
else
echo "All ${PASSED} tests passed! :)"
exit 0
fi
}

View file

@ -4,21 +4,10 @@ set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
source "${SCRIPT_DIR}/test/core.sh"
check_all_vars() {
local arg
IFS=$'\n'
for var in $(cat "$1" | grep -Eo "<[^>]*>"); do
if ! echo "$var" | grep -qE "$ARG_REGEX"; then
echoerr "$var isn't a valid variable name!"
exit 1
fi
done
}
tests="$(find "$SCRIPT_DIR/test" -iname '*_test.sh')"
test::run "We can find at least one known cheatsheet" \
'cheat::find | grep -q "docker.cheat"'
for cheat in $(cheat::find); do
test::run "All variables in $(basename $cheat) are valid" \
'check_all_vars "$cheat"'
for test in $tests; do
source "$test"
done
test::finish

17
test/var_test.sh Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
check_all_vars() {
local arg
IFS=$'\n'
for var in $(cat "$1" | grep -Eo "<[^>]*>"); do
if ! echo "$var" | grep -qE "$ARG_REGEX"; then
echoerr "$var isn't a valid variable name!"
return 1
fi
done
}
for cheat in $(cheat::find); do
test::run "All variables in $(basename $cheat) are valid" \
'check_all_vars "$cheat"'
done