kakoune/test/run

137 lines
4.2 KiB
Plaintext
Raw Normal View History

2014-06-30 12:22:50 +02:00
#!/bin/sh
2017-02-22 00:26:39 +01:00
# Color codes ├──────────────────────────────────────────────────────────────────
none="00"; red="31"; green="32"; yellow="33"; magenta="35"; bold="01"
2014-06-30 12:22:50 +02:00
# Main ├────────────────────────────────────────────────────────────────────────
main() {
2017-02-22 00:26:39 +01:00
kak_commands='
set global autoreload yes
2017-02-22 00:26:39 +01:00
set global autoinfo ""
2016-03-08 14:42:27 +01:00
set global autoshowcompl false
2016-05-10 14:51:00 +02:00
try %{ source rc }
try %{
2017-02-22 00:26:39 +01:00
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!
}
2017-02-22 00:26:39 +01:00
exec "%sh{cat cmd}"
2016-03-08 14:42:27 +01:00
exec <c-l>
eval -buffer *debug* write debug
nop %sh{
2017-02-22 00:26:39 +01:00
printf %s\\n "$kak_selections" > selections
printf %s\\n "$kak_selections_desc" > state
}
write out
quit!
2017-02-22 00:26:39 +01:00
'
root=$PWD
tmpdir="${TMPDIR:-/tmp}"
work=$(mktemp -d $tmpdir/kak-tests.XXXXXXXX)
trap "rm -R $work" EXIT
number_tests=0
number_failures=0
for dir in $(find "${@:-.}" -type d | sort); do
cd $root/$dir;
mkdir -p $work/$dir
for file in in cmd rc; do
[ -e $file ] && cp $file $work/$dir/
done
cd $work/$dir;
indent="$(echo "$dir/" | sed -e 's|[^/]*/\+| |g')"
name=${PWD##*/}
if [ ! -e cmd ]; then
echo "$indent$name"
continue
elif [ -x enabled ] && ! ./enabled; then
echo "$indent$name (disabled)" | colorize $yellow $none
continue
fi
number_tests=$(($number_tests + 1))
touch in; cp in out
session="kak-tests"
rm -f $tmpdir/kakoune/$USER/$session
$root/../src/kak out -n -s "$session" -ui json -e "$kak_commands" > display
retval=$?
failed=0
if [ ! -e error ]; then # failure not expected
if [ $retval -ne 0 ]; then
echo "$indent$name" | colorize $red $none
echo "$indent Kakoune returned error $retval"
failed=1
2015-12-12 09:51:48 +01:00
else
2017-02-22 00:26:39 +01:00
for file in out selections state display; do
if [ -e $root/$dir/$file ] && ! cmp -s $root/$dir/$file $file; then
if [ $failed -eq 0 ]; then
echo "$indent$name" | colorize $red $none
failed=1
fi
2017-02-22 00:26:39 +01:00
show_diff $root/$dir/$file $file
fi
done
if [ $failed -ne 0 ] && [ -e debug ]; then
printf "\ndebug buffer:\n" | colorize $yellow $none
cat debug
2015-12-12 09:51:48 +01:00
fi
2017-02-22 00:26:39 +01:00
fi
else # failure expected
if [ -e stderr ]; then
sed -i -e 's/^[0-9]*:[0-9]*: //g' stderr
if [ -s error ] && ! cmp -s error stderr; then
echo "$indent$name" | colorize $yellow $none
show_diff error stderr
failed=1
2016-04-25 23:17:42 +02:00
fi
2017-02-22 00:26:39 +01:00
elif [ $retval -eq 0 ]; then
echo "$indent$name" | colorize $red $none
echo "$indent Expected failure, but Kakoune returned 0"
failed=1
2015-12-12 09:51:48 +01:00
fi
fi
2017-02-22 00:26:39 +01:00
if [ $failed -eq 0 ]; then
echo "$indent$name" | colorize $green $none
else
number_failures=$(($number_failures + 1))
fi
2014-06-30 12:22:50 +02:00
done
2017-02-22 00:26:39 +01:00
if [ $number_failures -gt 0 ]; then
color=$red
else
2017-02-22 00:26:39 +01:00
color=$green
fi
2017-02-22 00:26:39 +01:00
printf "\nResume: %s tests, %s failures\n" $number_tests $number_failures | colorize $color $none
exit $number_failures
2014-06-30 12:22:50 +02:00
}
# Utility ├─────────────────────────────────────────────────────────────────────
colorize() {
2017-02-22 00:26:39 +01:00
color=${1:-$none}
style=${2:-$none}
printf '\033[%s;%sm%s\033[00;00m\n' $style $color "$(cat)"
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
2017-02-22 00:26:39 +01:00
+) color=$green ;;
-) color=$red ;;
@) color=$magenta ;;
*) color=$none ;;
2016-04-25 23:17:42 +02:00
esac
2017-02-22 00:26:39 +01:00
printf '%s\n' "$line" | colorize $color $none
2016-04-25 23:17:42 +02:00
done
}
2014-06-30 12:22:50 +02:00
2017-02-22 00:26:39 +01:00
main "$@"