notea-de-me/crawler/test.sh

53 lines
877 B
Bash

#! /bin/bash
main() {
local ret=0
for f in ./*_test.sh; do
if ! one_main "$f"; then
echo failed $f >&2
ret=$((ret+1))
fi
done
if [ $ret != 0 ]; then
echo failed >&2
fi
return $ret
}
one_main() (
local f="$1"
local ret=0
for t in $(grep ^test_ "$f" | sed 's/(.*//'); do
one_test "$f" "$t"
local test_ret=$?
if [ $test_ret != 0 ]; then
echo failed $f:$t: $test_ret >&2
ret=$((ret+1))
fi
done
return $ret
)
one_test() (
local f="$1"
local t="$2"
each
source "${f%_test.sh}.sh"
source "$f"
eval "$t"
)
each() {
export CACHE=$(mktemp -d)
export GITLAB_PAT=gibberish
export NOTES_ADDR=http://127.0.0.1:61111
source ./cache.sh
set -e
set -o pipefail
log() { echo "> $*" >&2; }
}
if [ "$0" == "$BASH_SOURCE" ]; then
main "$@"
fi