home/test/run

164 lines
4.8 KiB
Plaintext
Raw Normal View History

2014-06-30 12:22:50 +02:00
#!/bin/sh
# Main ├────────────────────────────────────────────────────────────────────────
main() {
number_tests=0
number_failures=0
2014-12-11 14:43:10 +01:00
dirs="${@:-.}"
test=$(pwd)
2016-12-17 11:26:37 +01:00
tmpdir="${TMPDIR:-/tmp}"
work=$(mktemp -d ${tmpdir}/kak-tests.XXXXXXXX)
trap "rm -R $work" EXIT
for dir in $(find $dirs -type d | sort); do
cd $test/$dir;
2016-03-08 14:42:27 +01:00
test_files=$(ls out selections state display 2>/dev/null)
mkdir -p $work/$dir
for file in $(ls in cmd rc 2>/dev/null); do
cp $file $work/$dir/
done
cd $work/$dir;
indent="$(echo "${dir}/" | sed -e 's|[^/]*/\+| |g')"
name=$(basename $PWD)
should_fail=$(test ! -e error; echo $?)
2014-10-29 00:28:10 +01:00
if ! test -e cmd; then
echo "$indent$name"
elif test -x enabled && ! ./enabled; then
echo "$indent$name (disabled)" | colorize yellow normal
else
number_tests=$(($number_tests + 1))
touch in; cp in out
kak_commands="
set global autoreload yes
2016-03-08 14:42:27 +01:00
set global autoinfo ''
set global autoshowcompl false
2016-05-10 14:51:00 +02:00
try %{ source rc }
try %{
exec -save-regs '/' '%s%\(\K[^)]+<ret><c-s>ld<a-t>(hHdi<c-u><esc><c-o>'
2016-05-10 14:51:00 +02:00
} catch %{ exec gg }
hook global RuntimeError .+ %{
2016-05-10 14:51:00 +02:00
echo -debug -- error: %val{hook_param}
eval -buffer *debug* write debug
quit!
}
exec '$(cat cmd | sed -e s/\'/\\\\\'/g)'
2016-03-08 14:42:27 +01:00
exec <c-l>
eval -buffer *debug* write debug
nop %sh{
IFS==
printf '%s\\n' \"\$kak_selections\" > selections
printf '%s\\n' \"\$kak_selections_desc\" > state
}
write out
quit!
"
session="kak-tests"
2016-12-17 11:26:37 +01:00
rm -f ${tmpdir}/kakoune/$USER/$session
2016-03-08 14:42:27 +01:00
${test}/../src/kak out -n -s "$session" -ui json -e "$kak_commands" > display
retval=$?
if [ $should_fail -eq 0 ]; then
2015-12-12 09:51:48 +01:00
if [ $retval -ne 0 ]; then
echo "Kakoune returned error $retval"
number_failures=$(($number_failures + 1))
echo "$indent$name" | colorize red normal
else
failed=no
for expect in $test_files; do
if ! cmp -s $test/$dir/$expect $expect; then
if [ "$failed" = no ]; then
echo "$indent$name" | colorize red normal
failed=yes
fi
echo
2016-04-25 23:17:42 +02:00
show_diff $test/$dir/$expect $expect
fi
done
if [ "$failed" = no ]; then
echo "$indent$name" | colorize green normal
else
number_failures=$(($number_failures + 1))
echo
if test -e debug; then
echo "debug buffer:" | colorize yellow normal
cat debug
echo
fi
fi
fi
2015-12-12 09:51:48 +01:00
else
2016-04-25 23:17:42 +02:00
failed=no
if [ ! -e stderr ]; then
if [ $retval -eq 0 ]; then
2016-04-25 23:17:42 +02:00
echo "$indent$name" | colorize red normal
number_failures=$(($number_failures + 1))
2016-04-25 23:17:42 +02:00
failed=yes
fi
else
2016-04-25 14:57:49 +02:00
sed -i -e 's/^[0-9]*:[0-9]*: //g' stderr
if [ -s error ] && ! cmp -s error stderr; then
2016-04-25 23:17:42 +02:00
echo "$indent$name" | colorize yellow normal
show_diff error stderr
failed=yes
fi
2015-12-12 09:51:48 +01:00
fi
2016-04-25 23:17:42 +02:00
if [ "$failed" = no ]; then
echo "$indent$name" | colorize green normal
fi
2015-12-12 09:51:48 +01:00
fi
fi
2014-06-30 12:22:50 +02:00
done
if expr $number_failures > 0; then
color=red
else
color=green
fi
2014-06-30 12:22:50 +02:00
echo
echo Resume:
echo $number_tests tests, $number_failures failures | colorize $color normal
exit $number_failures
2014-06-30 12:22:50 +02:00
}
# Utility ├─────────────────────────────────────────────────────────────────────
get_ansi_code() {
color_name=${1:-none}
style_name=${2:-none}
2014-10-29 00:28:10 +01:00
case "$color_name" in
none) color_nr=00 ;;
red) color_nr=31 ;;
green) color_nr=32 ;;
yellow) color_nr=33 ;;
magenta) color_nr=35 ;;
*) color_nr=00 ;;
esac
case "$style_name" in
none) style_nr=00 ;;
bold) style_nr=01 ;;
*) style_nr=00 ;;
esac
printf '\033[%s;%sm' $style_nr $color_nr
2014-06-30 12:22:50 +02:00
}
colorize() {
text=$(cat)
color_name=${1:-none}
style_name=${2:-none}
printf '%s\n' "$(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none)"
2014-06-30 12:22:50 +02:00
}
2016-04-25 23:17:42 +02:00
show_diff() {
diff -u $1 $2 | while IFS='' read -r line; do
first_character=$(printf '%s\n' "$line" | cut -b 1)
2016-04-25 23:17:42 +02:00
case $first_character in
+) color=green ;;
-) color=red ;;
@) color=magenta ;;
*) color=none ;;
esac
printf '%s\n' "$line" | colorize $color normal
2016-04-25 23:17:42 +02:00
done
}
2014-06-30 12:22:50 +02:00
main $@