2014-06-30 12:22:50 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Main ├────────────────────────────────────────────────────────────────────────
|
|
|
|
|
2014-10-12 13:27:22 +02:00
|
|
|
main() {
|
2014-10-27 14:19:23 +01:00
|
|
|
number_tests=0
|
|
|
|
number_failures=0
|
2014-12-11 14:43:10 +01:00
|
|
|
dirs="${@:-.}"
|
2014-10-27 14:19:23 +01:00
|
|
|
test=$(pwd)
|
2014-12-10 20:26:51 +01:00
|
|
|
work=$(mktemp -d /tmp/kak-tests.XXXXXXXX)
|
2014-10-27 14:19:23 +01:00
|
|
|
cp -R . $work
|
|
|
|
trap "rm -R $work" EXIT
|
2014-06-30 12:22:50 +02:00
|
|
|
for dir in $(find $dirs -type d); do
|
2014-10-12 13:27:22 +02:00
|
|
|
cd $test/$dir;
|
2014-12-11 14:43:10 +01:00
|
|
|
test_files=$(ls out selections state 2>/dev/null)
|
2014-10-12 13:27:22 +02:00
|
|
|
cd $work/$dir;
|
2014-10-29 00:28:10 +01:00
|
|
|
indent="$(echo "${dir}/" | sed "s|[^/]*/\+| |g")"
|
2014-10-27 14:19:23 +01:00
|
|
|
name=$(basename $PWD)
|
2014-10-29 00:28:10 +01:00
|
|
|
if ! test -e cmd; then
|
2014-10-12 13:27:22 +02:00
|
|
|
echo "$indent$name"
|
|
|
|
else
|
2014-10-27 14:19:23 +01:00
|
|
|
number_tests=$(($number_tests + 1))
|
2014-10-12 13:27:22 +02:00
|
|
|
touch in; cp in out
|
2014-10-27 14:19:23 +01:00
|
|
|
kak_commands="
|
2014-10-12 13:27:22 +02:00
|
|
|
set global autoreload yes
|
|
|
|
try %{
|
|
|
|
source rc
|
|
|
|
}
|
|
|
|
try %{
|
2014-11-22 22:19:27 +01:00
|
|
|
exec '%s%\(\K[^)]+<ret><c-s>ld<a-t>(hHdi<c-u><esc><c-o>'
|
2014-10-12 13:27:22 +02:00
|
|
|
} \
|
|
|
|
catch %{
|
|
|
|
exec gg
|
|
|
|
}
|
2014-10-29 00:28:10 +01:00
|
|
|
exec '$(cat cmd)'
|
2014-10-12 13:27:22 +02:00
|
|
|
eval -buffer *debug* write debug
|
|
|
|
nop %sh{ IFS==
|
|
|
|
echo \"\$kak_selections\" > selections
|
|
|
|
echo \"\$kak_selections_desc\" > state
|
|
|
|
}
|
|
|
|
write out
|
|
|
|
quit!
|
|
|
|
"
|
2014-11-21 14:57:28 +01:00
|
|
|
${test}/../src/kak out -n -e "$kak_commands"
|
2014-10-12 13:27:22 +02:00
|
|
|
for expect in $test_files; do
|
2014-10-27 14:19:23 +01:00
|
|
|
if cmp -s $test/$dir/$expect $expect; then
|
2014-10-12 13:27:22 +02:00
|
|
|
echo "$indent$name" | colorize green normal
|
|
|
|
else
|
2014-10-27 14:19:23 +01:00
|
|
|
number_failures=$(($number_failures + 1))
|
2014-10-12 13:27:22 +02:00
|
|
|
echo "$indent$name" | colorize red normal
|
|
|
|
echo
|
2014-10-29 00:28:10 +01:00
|
|
|
diff -u $test/$dir/$expect $expect | while read -r line; do
|
2014-10-27 14:19:23 +01:00
|
|
|
first_character=$(echo "$line" | cut -b 1)
|
|
|
|
color=$(match $first_character + green - red @ magenta none)
|
2014-10-12 13:27:22 +02:00
|
|
|
echo "$line" | colorize $color normal
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo "debug buffer:" | colorize yellow normal
|
|
|
|
cat debug
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2014-06-30 12:22:50 +02:00
|
|
|
done
|
2014-10-27 14:19:23 +01:00
|
|
|
if expr $number_failures > 0; then
|
2014-10-12 13:27:22 +02:00
|
|
|
color=red
|
|
|
|
else
|
|
|
|
color=green
|
|
|
|
fi
|
2014-06-30 12:22:50 +02:00
|
|
|
echo
|
|
|
|
echo Resume:
|
|
|
|
echo $number_tests tests, $number_failures failures | colorize $color normal
|
|
|
|
}
|
|
|
|
|
|
|
|
# Utility ├─────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
match() {
|
2014-10-12 13:27:22 +02:00
|
|
|
expression="$1";
|
|
|
|
shift
|
2014-10-27 14:19:23 +01:00
|
|
|
while [ $# > 0 ]; do
|
|
|
|
pattern="$1"
|
2014-10-12 13:27:22 +02:00
|
|
|
shift
|
2014-10-27 14:19:23 +01:00
|
|
|
value="$1"
|
|
|
|
next="$1"
|
|
|
|
default_value="$pattern"
|
|
|
|
if [ -z "$next" ]; then
|
2014-06-30 12:22:50 +02:00
|
|
|
echo $default_value
|
|
|
|
return 1
|
2014-10-12 13:27:22 +02:00
|
|
|
fi
|
2014-10-27 14:19:23 +01:00
|
|
|
if [ "$expression" = "$pattern" ]; then
|
2014-10-12 13:27:22 +02:00
|
|
|
echo "$value"
|
2014-06-30 12:22:50 +02:00
|
|
|
return 0
|
2014-10-12 13:27:22 +02:00
|
|
|
fi
|
2014-06-30 12:22:50 +02:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-10-12 13:27:22 +02:00
|
|
|
get_ansi_code() {
|
2014-10-27 14:19:23 +01:00
|
|
|
color_name=${1:-none}
|
|
|
|
style_name=${2:-none}
|
2014-10-29 00:28:10 +01: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 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
2014-10-12 13:27:22 +02:00
|
|
|
colorize() {
|
2014-10-27 14:19:23 +01:00
|
|
|
text=$(cat)
|
|
|
|
color_name=${1:-none}
|
|
|
|
style_name=${2:-none}
|
2014-10-29 00:28:10 +01:00
|
|
|
echo "$(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none)"
|
2014-06-30 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main $@
|