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