2014-06-30 12:22:50 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-02-22 00:26:39 +01:00
|
|
|
# Color codes ├──────────────────────────────────────────────────────────────────
|
2019-03-07 18:06:27 +01:00
|
|
|
none='\033[0m'; red='\033[31m'; green='\033[32m'; yellow='\033[33m'; magenta='\033[35m'; bold='\033[1m'
|
2017-02-22 00:26:39 +01:00
|
|
|
|
2014-06-30 12:22:50 +02:00
|
|
|
# Main ├────────────────────────────────────────────────────────────────────────
|
|
|
|
|
2014-10-12 13:27:22 +02:00
|
|
|
main() {
|
2017-02-22 00:26:39 +01:00
|
|
|
kak_commands='
|
2014-10-12 13:27:22 +02:00
|
|
|
set global autoreload yes
|
2017-02-22 00:26:39 +01:00
|
|
|
set global autoinfo ""
|
2018-07-19 10:10:10 +02:00
|
|
|
set global autocomplete ""
|
2014-10-12 13:27:22 +02:00
|
|
|
try %{
|
2018-02-24 10:59:31 +01:00
|
|
|
exec -save-regs / %{%s%\(\K[^)]+\)<ret>a<backspace><esc>i<backspace><backspace><c-u><esc><a-;>}
|
2016-05-10 14:51:00 +02:00
|
|
|
} catch %{ exec gg }
|
2018-02-24 10:59:31 +01:00
|
|
|
try %{ source rc }
|
2023-03-13 21:39:32 +01:00
|
|
|
try %{ eval -draft %{ edit cmd; exec \%H"zy; delete-buffer } }
|
|
|
|
try %{ exec -with-maps -with-hooks %reg{z} }
|
2018-05-15 13:26:41 +02:00
|
|
|
exec -with-hooks <c-l>
|
2017-02-22 00:26:39 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
root=$PWD
|
|
|
|
tmpdir="${TMPDIR:-/tmp}"
|
|
|
|
work=$(mktemp -d $tmpdir/kak-tests.XXXXXXXX)
|
2023-03-13 21:39:32 +01:00
|
|
|
session="kak-tests"
|
|
|
|
if [ -n "$XDG_RUNTIME_DIR" ]; then
|
|
|
|
session_path="${XDG_RUNTIME_DIR}/kakoune/$session"
|
|
|
|
else
|
|
|
|
session_path="${TMPDIR:-/tmp}/kakoune/${USER}/$session"
|
|
|
|
fi
|
2017-02-22 00:26:39 +01:00
|
|
|
trap "rm -R $work" EXIT
|
|
|
|
|
|
|
|
number_tests=0
|
|
|
|
number_failures=0
|
|
|
|
for dir in $(find "${@:-.}" -type d | sort); do
|
|
|
|
cd $root/$dir;
|
2018-02-07 09:38:13 +01:00
|
|
|
indent="$(echo "$dir/" | sed -e 's|[^/]*//*| |g')"
|
2017-02-22 00:26:39 +01:00
|
|
|
name=${PWD##*/}
|
2017-06-15 13:44:50 +02:00
|
|
|
if [ ! -f cmd ]; then
|
2017-02-22 00:26:39 +01:00
|
|
|
echo "$indent$name"
|
|
|
|
continue
|
|
|
|
elif [ -x enabled ] && ! ./enabled; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${yellow}$indent%s (disabled)${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-03-13 21:39:32 +01:00
|
|
|
env_vars=$(ls -1 kak_* 2>/dev/null)
|
|
|
|
number_tests=$(($number_tests + 1))
|
|
|
|
mkdir -p $work/$dir
|
|
|
|
cp in cmd rc $work/$dir/ 2>/dev/null
|
|
|
|
cd $work/$dir;
|
2018-05-19 01:59:06 +02:00
|
|
|
|
2019-10-04 04:09:51 +02:00
|
|
|
mkfifo ui-in ui-out
|
2017-02-22 00:26:39 +01:00
|
|
|
touch in; cp in out
|
2023-03-13 21:39:32 +01:00
|
|
|
rm -f "$session_path"
|
2021-01-22 07:19:36 +01:00
|
|
|
$DEBUGGER $root/../src/kak out -n -s "$session" -ui json -e "$kak_commands" >ui-out <ui-in &
|
2019-10-04 04:09:51 +02:00
|
|
|
kakpid=$!
|
|
|
|
|
2017-02-22 00:26:39 +01:00
|
|
|
failed=0
|
2019-10-04 04:09:51 +02:00
|
|
|
exec 4<ui-out 3>ui-in
|
|
|
|
|
|
|
|
if [ -f "${root}/${dir}/script" ]; then
|
|
|
|
. "${root}/${dir}/script"
|
|
|
|
else
|
|
|
|
# At least wait for kak to initialize so we don't deadlock
|
|
|
|
ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }'
|
|
|
|
fi
|
|
|
|
|
|
|
|
finished_commands |$root/../src/kak -p "$session" 2>/dev/null
|
2020-06-10 01:26:32 +02:00
|
|
|
cat <&4 >/dev/null
|
2019-10-04 04:09:51 +02:00
|
|
|
|
|
|
|
wait $kakpid
|
|
|
|
retval=$?
|
|
|
|
|
|
|
|
exec 3>&- 4<&-
|
|
|
|
|
2017-02-22 00:26:39 +01:00
|
|
|
if [ ! -e error ]; then # failure not expected
|
|
|
|
if [ $retval -ne 0 ]; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${red}$indent%s${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
echo "$indent Kakoune returned error $retval"
|
|
|
|
failed=1
|
2015-12-12 09:51:48 +01:00
|
|
|
else
|
2019-10-04 04:09:51 +02:00
|
|
|
for file in out $env_vars; do
|
2017-06-15 13:44:50 +02:00
|
|
|
if [ -f $root/$dir/$file ] && ! cmp -s $root/$dir/$file $file; then
|
2017-02-22 00:26:39 +01:00
|
|
|
if [ $failed -eq 0 ]; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${red}$indent%s${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
failed=1
|
2015-12-15 09:13:04 +01:00
|
|
|
fi
|
2017-02-22 00:26:39 +01:00
|
|
|
show_diff $root/$dir/$file $file
|
|
|
|
fi
|
|
|
|
done
|
2017-06-15 13:44:50 +02:00
|
|
|
if [ $failed -ne 0 ] && [ -f debug ]; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "\n${yellow}debug buffer:${none}\n"
|
2017-02-22 00:26:39 +01:00
|
|
|
cat debug
|
2015-12-12 09:51:48 +01:00
|
|
|
fi
|
2017-02-22 00:26:39 +01:00
|
|
|
fi
|
|
|
|
else # failure expected
|
2017-06-15 13:44:50 +02:00
|
|
|
if [ -f stderr ]; then
|
2017-02-22 00:26:39 +01:00
|
|
|
sed -i -e 's/^[0-9]*:[0-9]*: //g' stderr
|
|
|
|
if [ -s error ] && ! cmp -s error stderr; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${yellow}$indent%s${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
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
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${red}$indent%s${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
echo "$indent Expected failure, but Kakoune returned 0"
|
|
|
|
failed=1
|
2015-12-12 09:51:48 +01:00
|
|
|
fi
|
2014-10-12 13:27:22 +02:00
|
|
|
fi
|
2017-02-22 00:26:39 +01:00
|
|
|
|
|
|
|
if [ $failed -eq 0 ]; then
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${green}$indent%s${none}\n" "$name"
|
2017-02-22 00:26:39 +01:00
|
|
|
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
|
2014-10-12 13:27:22 +02:00
|
|
|
else
|
2017-02-22 00:26:39 +01:00
|
|
|
color=$green
|
2014-10-12 13:27:22 +02:00
|
|
|
fi
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "\n${color}Summary: %s tests, %s failures${none}\n" $number_tests $number_failures
|
2014-12-13 14:11:38 +01:00
|
|
|
exit $number_failures
|
2014-06-30 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Utility ├─────────────────────────────────────────────────────────────────────
|
|
|
|
|
2016-04-25 23:17:42 +02:00
|
|
|
show_diff() {
|
2016-05-10 10:38:47 +02:00
|
|
|
diff -u $1 $2 | while IFS='' read -r line; do
|
2016-12-17 11:36:00 +01:00
|
|
|
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
|
2019-03-07 18:06:27 +01:00
|
|
|
printf "${color}%s${none}\n" "$line"
|
2016-04-25 23:17:42 +02:00
|
|
|
done
|
|
|
|
}
|
2014-06-30 12:22:50 +02:00
|
|
|
|
2019-10-04 04:09:51 +02:00
|
|
|
finished_commands() {
|
|
|
|
printf %s 'eval -client client0 %{
|
2021-07-20 14:06:57 +02:00
|
|
|
eval -buffer *debug* write -force debug
|
2019-10-04 04:09:51 +02:00
|
|
|
'
|
|
|
|
for env_var in $env_vars; do
|
2023-03-13 21:39:32 +01:00
|
|
|
case $env_var in
|
|
|
|
kak_quoted_*) printf 'echo -to-file %s -end-of-line -quoting shell -- %s\n' "$env_var" "%val{${env_var##kak_quoted_}}" ;;
|
|
|
|
kak_*) printf 'echo -to-file %s -end-of-line -- %s\n' "$env_var" "%val{${env_var##kak_}}" ;;
|
|
|
|
esac
|
2019-10-04 04:09:51 +02:00
|
|
|
done
|
2023-03-13 21:39:32 +01:00
|
|
|
printf %s '
|
2021-07-20 14:06:57 +02:00
|
|
|
write -force out
|
2019-10-04 04:09:51 +02:00
|
|
|
quit!
|
|
|
|
}
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Script Assertions ├───────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
ui_in() {
|
|
|
|
printf '%s\n' "$1" >&3
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_out() {
|
|
|
|
while [ $# -ne 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-ignore)
|
|
|
|
shift
|
|
|
|
skip_count="$1"
|
|
|
|
while [ $skip_count -gt 0 ]; do
|
|
|
|
read -r event <&4
|
|
|
|
skip_count=$(( skip_count - 1 ))
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
read -r event <&4
|
2020-04-27 05:35:02 +02:00
|
|
|
if [ ! "$1" = "$event" ]; then
|
|
|
|
if [ $failed -eq 0 ]; then
|
|
|
|
printf "${red}$indent%s${none}\n" "$name"
|
|
|
|
fi
|
2019-11-24 07:57:32 +01:00
|
|
|
printf "${indent} ${red}- %s\n${indent} ${green}+ %s${none}\n" "$1" "$event"
|
2019-10-04 04:09:51 +02:00
|
|
|
failed=1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-02-22 00:26:39 +01:00
|
|
|
main "$@"
|