2014-06-30 14:22:50 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-02-22 02:26:39 +03:00
|
|
|
# Color codes ├──────────────────────────────────────────────────────────────────
|
|
|
|
none="00"; red="31"; green="32"; yellow="33"; magenta="35"; bold="01"
|
|
|
|
|
2014-06-30 14:22:50 +04:00
|
|
|
# Main ├────────────────────────────────────────────────────────────────────────
|
|
|
|
|
2014-10-12 15:27:22 +04:00
|
|
|
main() {
|
2017-02-22 02:26:39 +03:00
|
|
|
kak_commands='
|
2014-10-12 15:27:22 +04:00
|
|
|
set global autoreload yes
|
2017-02-22 02:26:39 +03:00
|
|
|
set global autoinfo ""
|
2016-03-08 16:42:27 +03:00
|
|
|
set global autoshowcompl false
|
2014-10-12 15:27:22 +04:00
|
|
|
try %{
|
2018-02-24 12:59:31 +03:00
|
|
|
exec -save-regs / %{%s%\(\K[^)]+\)<ret>a<backspace><esc>i<backspace><backspace><c-u><esc><a-;>}
|
2016-05-10 15:51:00 +03:00
|
|
|
} catch %{ exec gg }
|
2018-02-24 12:59:31 +03:00
|
|
|
try %{ source rc }
|
2015-12-14 15:35:23 +03:00
|
|
|
hook global RuntimeError .+ %{
|
2016-05-10 15:51:00 +03:00
|
|
|
echo -debug -- error: %val{hook_param}
|
|
|
|
eval -buffer *debug* write debug
|
|
|
|
quit!
|
2015-12-14 15:35:23 +03:00
|
|
|
}
|
2018-02-25 18:16:25 +03:00
|
|
|
try %{ exec -with-maps "%sh{cat cmd}" }
|
2016-03-08 16:42:27 +03:00
|
|
|
exec <c-l>
|
2014-10-12 15:27:22 +04:00
|
|
|
eval -buffer *debug* write debug
|
2015-10-17 13:32:32 +03:00
|
|
|
nop %sh{
|
2017-02-22 02:26:39 +03:00
|
|
|
printf %s\\n "$kak_selections" > selections
|
|
|
|
printf %s\\n "$kak_selections_desc" > state
|
2014-10-12 15:27:22 +04:00
|
|
|
}
|
|
|
|
write out
|
|
|
|
quit!
|
2017-02-22 02:26:39 +03: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
|
2017-06-15 14:44:50 +03:00
|
|
|
[ -f $file ] && cp $file $work/$dir/
|
2017-02-22 02:26:39 +03:00
|
|
|
done
|
|
|
|
cd $work/$dir;
|
2018-02-07 11:38:13 +03:00
|
|
|
indent="$(echo "$dir/" | sed -e 's|[^/]*//*| |g')"
|
2017-02-22 02:26:39 +03:00
|
|
|
name=${PWD##*/}
|
2017-06-15 14:44:50 +03:00
|
|
|
if [ ! -f cmd ]; then
|
2017-02-22 02:26:39 +03:00
|
|
|
echo "$indent$name"
|
|
|
|
continue
|
|
|
|
elif [ -x enabled ] && ! ./enabled; then
|
|
|
|
echo "$indent$name (disabled)" | colorize $yellow $none
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-05-19 02:59:06 +03:00
|
|
|
ui_in="${root}/${dir}/ui-in"
|
2018-06-28 15:56:50 +03:00
|
|
|
[ ! -f $ui_in ] && ui_in="/dev/null"
|
2018-05-19 02:59:06 +03:00
|
|
|
|
2017-02-22 02:26:39 +03:00
|
|
|
number_tests=$(($number_tests + 1))
|
|
|
|
touch in; cp in out
|
|
|
|
session="kak-tests"
|
|
|
|
rm -f $tmpdir/kakoune/$USER/$session
|
2018-05-19 02:59:06 +03:00
|
|
|
$root/../src/kak out -n -s "$session" -ui json -e "$kak_commands" > ui-out < "${ui_in}"
|
2017-02-22 02:26:39 +03:00
|
|
|
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 11:51:48 +03:00
|
|
|
else
|
2018-05-19 02:58:27 +03:00
|
|
|
for file in out selections state ui-out; do
|
2017-06-15 14:44:50 +03:00
|
|
|
if [ -f $root/$dir/$file ] && ! cmp -s $root/$dir/$file $file; then
|
2017-02-22 02:26:39 +03:00
|
|
|
if [ $failed -eq 0 ]; then
|
|
|
|
echo "$indent$name" | colorize $red $none
|
|
|
|
failed=1
|
2015-12-15 11:13:04 +03:00
|
|
|
fi
|
2017-02-22 02:26:39 +03:00
|
|
|
show_diff $root/$dir/$file $file
|
|
|
|
fi
|
|
|
|
done
|
2017-06-15 14:44:50 +03:00
|
|
|
if [ $failed -ne 0 ] && [ -f debug ]; then
|
2017-02-22 02:26:39 +03:00
|
|
|
printf "\ndebug buffer:\n" | colorize $yellow $none
|
|
|
|
cat debug
|
2015-12-12 11:51:48 +03:00
|
|
|
fi
|
2017-02-22 02:26:39 +03:00
|
|
|
fi
|
|
|
|
else # failure expected
|
2017-06-15 14:44:50 +03:00
|
|
|
if [ -f stderr ]; then
|
2017-02-22 02:26:39 +03:00
|
|
|
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-26 00:17:42 +03:00
|
|
|
fi
|
2017-02-22 02:26:39 +03: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 11:51:48 +03:00
|
|
|
fi
|
2014-10-12 15:27:22 +04:00
|
|
|
fi
|
2017-02-22 02:26:39 +03:00
|
|
|
|
|
|
|
if [ $failed -eq 0 ]; then
|
|
|
|
echo "$indent$name" | colorize $green $none
|
|
|
|
else
|
|
|
|
number_failures=$(($number_failures + 1))
|
|
|
|
fi
|
2014-06-30 14:22:50 +04:00
|
|
|
done
|
2017-02-22 02:26:39 +03:00
|
|
|
|
|
|
|
if [ $number_failures -gt 0 ]; then
|
|
|
|
color=$red
|
2014-10-12 15:27:22 +04:00
|
|
|
else
|
2017-02-22 02:26:39 +03:00
|
|
|
color=$green
|
2014-10-12 15:27:22 +04:00
|
|
|
fi
|
2017-02-22 02:26:39 +03:00
|
|
|
printf "\nResume: %s tests, %s failures\n" $number_tests $number_failures | colorize $color $none
|
2014-12-13 16:11:38 +03:00
|
|
|
exit $number_failures
|
2014-06-30 14:22:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Utility ├─────────────────────────────────────────────────────────────────────
|
|
|
|
|
2014-10-12 15:27:22 +04:00
|
|
|
colorize() {
|
2017-02-22 02:26:39 +03:00
|
|
|
color=${1:-$none}
|
|
|
|
style=${2:-$none}
|
|
|
|
printf '\033[%s;%sm%s\033[00;00m\n' $style $color "$(cat)"
|
2014-06-30 14:22:50 +04:00
|
|
|
}
|
|
|
|
|
2016-04-26 00:17:42 +03:00
|
|
|
show_diff() {
|
2016-05-10 11:38:47 +03:00
|
|
|
diff -u $1 $2 | while IFS='' read -r line; do
|
2016-12-17 13:36:00 +03:00
|
|
|
first_character=$(printf '%s\n' "$line" | cut -b 1)
|
2016-04-26 00:17:42 +03:00
|
|
|
case $first_character in
|
2017-02-22 02:26:39 +03:00
|
|
|
+) color=$green ;;
|
|
|
|
-) color=$red ;;
|
|
|
|
@) color=$magenta ;;
|
|
|
|
*) color=$none ;;
|
2016-04-26 00:17:42 +03:00
|
|
|
esac
|
2017-02-22 02:26:39 +03:00
|
|
|
printf '%s\n' "$line" | colorize $color $none
|
2016-04-26 00:17:42 +03:00
|
|
|
done
|
|
|
|
}
|
2014-06-30 14:22:50 +04:00
|
|
|
|
2017-02-22 02:26:39 +03:00
|
|
|
main "$@"
|