1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 23:34:12 +03:00
kakoune/test/run

139 lines
3.4 KiB
Plaintext
Raw Normal View History

2014-06-30 14:22:50 +04:00
#!/bin/sh
# Main ├────────────────────────────────────────────────────────────────────────
main() {
number_tests=0
number_failures=0
dirs="$@"
test=$(pwd)
work=$(mktemp --directory)
cp -R . $work
trap "rm -R $work" EXIT
2014-06-30 14:22:50 +04:00
for dir in $(find $dirs -type d); do
cd $test/$dir;
test_files=$(find * -name out -o -name selections -o -name state)
cd $work/$dir;
indent="$(repeat ' ' $(pwd | sed "s|$test||" | tr -d -c / | awk '{ print length }'))"
name=$(basename $PWD)
if ! exists cmd; then
echo "$indent$name"
else
number_tests=$(($number_tests + 1))
touch in; cp in out
kak_commands="
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!
"
kak out -n -e "$kak_commands"
IFS=$'\n'
for expect in $test_files; do
if cmp -s $test/$dir/$expect $expect; then
echo "$indent$name" | colorize green normal
else
number_failures=$(($number_failures + 1))
echo "$indent$name" | colorize red normal
echo
IFS=$'\n'
for line in $(diff -u $test/$dir/$expect $expect); do
IFS=¬
first_character=$(echo "$line" | cut -b 1)
color=$(match $first_character + green - red @ magenta none)
echo "$line" | colorize $color normal
done
echo
echo "debug buffer:" | colorize yellow normal
cat debug
echo
fi
done
fi
2014-06-30 14:22:50 +04:00
done
if expr $number_failures > 0; then
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
}
# Utility ├─────────────────────────────────────────────────────────────────────
match() {
expression="$1";
shift
while [ $# > 0 ]; do
pattern="$1"
shift
value="$1"
next="$1"
default_value="$pattern"
if [ -z "$next" ]; then
2014-06-30 14:22:50 +04:00
echo $default_value
return 1
fi
if [ "$expression" = "$pattern" ]; then
echo "$value"
2014-06-30 14:22:50 +04:00
return 0
fi
2014-06-30 14:22:50 +04:00
shift
done
}
repeat() {
text=$1
count=${2:-0}
echo $(yes $text | head -n $count | join)
2014-06-30 14:22:50 +04:00
}
join() {
tr -d "\n"
2014-06-30 14:22:50 +04:00
}
exists() {
test -e $@
}
get_ansi_code() {
color_name=${1:-none}
style_name=${2:-none}
color='none 00
red 31
green 32
yellow 33
magenta 35'
style='none 00
bold 01'
color_nr=$(echo "$color" | awk "/$color_name/ { print \$2 }")
style_nr=$(echo "$style" | awk "/$style_name/ { print \$2 }")
echo '\e[STYLE_NR;COLOR_NRm' | sed s/COLOR_NR/$color_nr/';'s/STYLE_NR/$style_nr/
2014-06-30 14:22:50 +04:00
}
colorize() {
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 14:22:50 +04:00
}
main $@