1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-26 21:22:00 +03:00
kakoune/test/run

134 lines
4.2 KiB
Plaintext
Raw Normal View History

2014-06-30 14:22:50 +04:00
#!/bin/sh
2017-02-22 02:26:39 +03:00
# Color codes ├──────────────────────────────────────────────────────────────────
none='\033[0m'; red='\033[31m'; green='\033[32m'; yellow='\033[33m'; magenta='\033[35m'; bold='\033[1m'
2017-02-22 02:26:39 +03:00
2014-06-30 14:22:50 +04:00
# Main ├────────────────────────────────────────────────────────────────────────
main() {
2017-02-22 02:26:39 +03:00
kak_commands='
set global autoreload yes
2017-02-22 02:26:39 +03:00
set global autoinfo ""
set global autocomplete ""
try %{
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 }
try %{ source rc }
hook global RuntimeError .+ %{
2016-05-10 15:51:00 +03:00
echo -debug -- error: %val{hook_param}
eval -buffer *debug* write debug
quit!
}
try %{ exec -with-maps -with-hooks "%sh{cat cmd}" }
exec -with-hooks <c-l>
eval -buffer *debug* write debug
nop %sh{
2019-06-23 05:03:40 +03:00
printf %s\\n "$kak_quoted_selections" > selections
printf %s\\n "$kak_quoted_selections_desc" > state
}
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
[ -f $file ] && cp $file $work/$dir/
2017-02-22 02:26:39 +03:00
done
cd $work/$dir;
indent="$(echo "$dir/" | sed -e 's|[^/]*//*| |g')"
2017-02-22 02:26:39 +03:00
name=${PWD##*/}
if [ ! -f cmd ]; then
2017-02-22 02:26:39 +03:00
echo "$indent$name"
continue
elif [ -x enabled ] && ! ./enabled; then
printf "${yellow}$indent%s (disabled)${none}\n" "$name"
2017-02-22 02:26:39 +03:00
continue
fi
ui_in="${root}/${dir}/ui-in"
[ ! -f $ui_in ] && ui_in="/dev/null"
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
$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
printf "${red}$indent%s${none}\n" "$name"
2017-02-22 02:26:39 +03:00
echo "$indent Kakoune returned error $retval"
failed=1
2015-12-12 11:51:48 +03:00
else
for file in out selections state ui-out; do
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
printf "${red}$indent%s${none}\n" "$name"
2017-02-22 02:26:39 +03:00
failed=1
fi
2017-02-22 02:26:39 +03:00
show_diff $root/$dir/$file $file
fi
done
if [ $failed -ne 0 ] && [ -f debug ]; then
printf "\n${yellow}debug buffer:${none}\n"
2017-02-22 02:26:39 +03:00
cat debug
2015-12-12 11:51:48 +03:00
fi
2017-02-22 02:26:39 +03:00
fi
else # failure expected
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
printf "${yellow}$indent%s${none}\n" "$name"
2017-02-22 02:26:39 +03:00
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
printf "${red}$indent%s${none}\n" "$name"
2017-02-22 02:26:39 +03:00
echo "$indent Expected failure, but Kakoune returned 0"
failed=1
2015-12-12 11:51:48 +03:00
fi
fi
2017-02-22 02:26:39 +03:00
if [ $failed -eq 0 ]; then
printf "${green}$indent%s${none}\n" "$name"
2017-02-22 02:26:39 +03:00
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
else
2017-02-22 02:26:39 +03:00
color=$green
fi
printf "\n${color}Summary: %s tests, %s failures${none}\n" $number_tests $number_failures
exit $number_failures
2014-06-30 14:22:50 +04:00
}
# Utility ├─────────────────────────────────────────────────────────────────────
2016-04-26 00:17:42 +03:00
show_diff() {
diff -u $1 $2 | while IFS='' read -r line; do
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
printf "${color}%s${none}\n" "$line"
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 "$@"