An error occurred while loading the file. Please try again.
-
Lukáš Bařinka authorede8649643
cd /mnt
################################################
badge_generate() { printf -v x '%60s'; printf '%s\n' "${x// /-}" "$*"; }
badge_init() { :; }
################################################
export LANG=C LC_ALL=C
shopt -s nullglob
HOST='http://localhost'
badge_init 'Tests'
info() {
printf '%s[info]: %s\n' "${0##*/}" "$*" >&2
}
err() {
printf '%s[error]: %s\n' "${0##*/}" "$*" >&2
exit 2
}
test_results() {
printf '%s[test]: %-30s\t[ %s ]\n' "${0##*/}" "${task} ${test_id}: ${1}" "${2}" >&2
}
url() {
case "${1}" in
/*) url="${HOST}${1// /}";;
*) url="${1// /}"
esac
}
equal() {
local test_name="${1}"
local expected="${2}"
local tested="${3}"
(( total++ ))
if [[ "${expected}" == "${tested}" ]]; then
test_results "${test_name}" "OK"
(( passed++ ))
else
test_results "${test_name}" "FAILED"
diff -s <( printf -- '%s\n' "${expected}" ) <( printf -- '%s\n' "${tested}" )
fi
}
test_status() {
equal 'Status' \
"$( sed -n '1p' "${test%_*}_s" )" \
"$( sed -n '1p' <<< "${output}" )"
}
test_headers() {
equal 'Headers' \
"$( sort "${test%_*}_h" )" \
"$( sed -n '2,/^$/p' <<< "${output}" | grep -f <( sed 's,^\([^:]*: \).*,^\1,' "${test%_*}_h" ) | sort )"
}
test_content() {
if [[ -f "${test%_*}_ca" ]]; then
equal 'Content' \
"$( < "${test%_*}_c" )" \
"$( sed '1,/^$/d' <<< "${output}" | sed -Ef "${test%_*}_ca" )"
elif [[ -f "${test%_*}_cf" ]]; then
equal 'Content' \
"$( bash "${test%_*}_cf" < "${test%_*}_c" )" \
"$( sed '1,/^$/d' <<< "${output}" | bash "${test%_*}_cf" )"
else
equal 'Content' \
"$( < "${test%_*}_c" )" \
"$( sed '1,/^$/d' <<< "${output}" )"
fi
}
evaluate() {
7172737475767778798081828384858687888990919293949596979899
local total=0
local passed=0
local output
local url
local send_h
for test in .test*_url; do
[[ "${test}" =~ ([[:alnum:]:]+)_[^_]*$ ]]
test_id="${BASH_REMATCH[1]}"
url "$( < ${test} )"
send_h=''
[[ -f "${test%_*}_sh" ]] && send_h=$( < "${test%_*}_sh" )
if [[ -f "${test%_*}_d" ]]; then
output="$( curl -is -H "${send_h}" -d "$(< ${test%_*}_d)" "${url}" | tr -d '\r\0' )"
else
output="$( curl -is -H "${send_h}" "${url}" | tr -d '\r\0' )"
fi
[[ -f "${test%_*}_s" ]] && test_status
[[ -f "${test%_*}_h" ]] && test_headers
[[ -f "${test%_*}_c" ]] && test_content
done
badge_generate "Tests" "${passed}/${total}"
}
# Start webserver
httpd && echo Webserver started || echo Webeserver error
# Run tests...
evaluate