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
|
|
|
|
dirs="$@"
|
|
|
|
test=$(pwd)
|
|
|
|
work=$(mktemp --directory)
|
|
|
|
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-10-27 14:19:23 +01:00
|
|
|
test_files=$(find * -name out -o -name selections -o -name state)
|
2014-10-12 13:27:22 +02:00
|
|
|
cd $work/$dir;
|
2014-10-27 14:19:23 +01:00
|
|
|
indent="$(repeat ' ' $(pwd | sed "s|$test||" | tr -d -c / | awk '{ print length }'))"
|
|
|
|
name=$(basename $PWD)
|
2014-10-12 13:27:22 +02:00
|
|
|
if ! exists cmd; then
|
|
|
|
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 %{
|
|
|
|
exec '%s%[(](.+?)[)]<ret>i<del><del><esc>a<backspace><c-u><esc>'
|
|
|
|
} \
|
|
|
|
catch %{
|
|
|
|
exec gg
|
|
|
|
}
|
|
|
|
exec '$(<cmd)'
|
|
|
|
eval -buffer *debug* write debug
|
|
|
|
nop %sh{ IFS==
|
|
|
|
echo \"\$kak_selections\" > selections
|
|
|
|
echo \"\$kak_selections_desc\" > state
|
|
|
|
}
|
|
|
|
write out
|
|
|
|
quit!
|
|
|
|
"
|
2014-10-27 14:19:23 +01:00
|
|
|
kak out -n -e "$kak_commands"
|
2014-10-12 13:27:22 +02:00
|
|
|
IFS=$'\n'
|
|
|
|
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
|
|
|
|
IFS=$'\n'
|
2014-10-27 14:19:23 +01:00
|
|
|
for line in $(diff -u $test/$dir/$expect $expect); do
|
2014-10-12 13:27:22 +02:00
|
|
|
IFS=¬
|
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
|
|
|
repeat() {
|
2014-10-27 14:19:23 +01:00
|
|
|
text=$1
|
|
|
|
count=${2:-0}
|
|
|
|
echo $(yes $text | head -n $count | join)
|
2014-06-30 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
join() {
|
2014-10-27 14:19:23 +01:00
|
|
|
tr -d "\n"
|
2014-06-30 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exists() {
|
|
|
|
test -e $@
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
color='none 00
|
2014-10-12 13:27:22 +02:00
|
|
|
red 31
|
|
|
|
green 32
|
|
|
|
yellow 33
|
|
|
|
magenta 35'
|
2014-10-27 14:19:23 +01:00
|
|
|
style='none 00
|
2014-10-12 13:27:22 +02:00
|
|
|
bold 01'
|
2014-10-27 14:19:23 +01:00
|
|
|
color_nr=$(echo "$color" | awk "/$color_name/ { print \$2 }")
|
|
|
|
style_nr=$(echo "$style" | awk "/$style_name/ { print \$2 }")
|
2014-10-12 13:27:22 +02:00
|
|
|
echo '\e[STYLE_NR;COLOR_NRm' | sed s/COLOR_NR/$color_nr/';'s/STYLE_NR/$style_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}
|
|
|
|
printf "$(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none)\n"
|
2014-06-30 12:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main $@
|