diff options
| author | Alex Leferry 2 <alexherbo2@gmail.com> | 2014-06-30 12:22:50 +0200 |
|---|---|---|
| committer | Alex Leferry 2 <alexherbo2@gmail.com> | 2014-06-30 12:22:50 +0200 |
| commit | d20d43bf3622fc4bb416cf2ca95d5cf0c4c88fcf (patch) | |
| tree | 42173f19891a452bdf10b8b7769a457068ecbb7a /test/run | |
| parent | 7aa78d726a54fa57a8dc5ed973ab0b30eeba6bf3 (diff) | |
add testing framework
Diffstat (limited to 'test/run')
| -rwxr-xr-x | test/run | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/run b/test/run new file mode 100755 index 00000000..93cfc9eb --- /dev/null +++ b/test/run @@ -0,0 +1,111 @@ +#!/bin/sh + +# Main ├──────────────────────────────────────────────────────────────────────── + +main() { number_tests=0 number_failures=0 + dirs=$@ + test=$(pwd) + work=$(mktemp --directory) + cp --recursive . $work + trap "rm --recursive $work" EXIT + for dir in $(find $dirs -type d); do + cd $test/$dir; test_files=$(find * | egrep 'out|selections|state') + cd $work/$dir; { IFS=¬ + indent=$(repeat ' ' $(pwd | sed "s|$test||" | tr --delete --complement / | awk '{ print length }')) + name=$(basename $PWD) + ! exists cmd && { + echo $indent$name + } || { nop=$((number_tests++)) + touch in; cp in out + kak_commands="set global autoreload yes + try %{ + source rc + } + try %{ + exec '%s%[(](.+?)[)]<ret>i<del><del><esc>a<backspace><esc>' + } \ + catch %{ + exec gg + } + exec '$(<cmd)' + nop %sh{ IFS== + echo \"\$kak_selections\" > selections + echo \"\$kak_selections_desc\" > state + } + write out; quit! + " + kak out -n -e $kak_commands + for expect in $test_files; do + cmp --quiet $test/$dir/$expect $expect && { + echo "$indent$name" | colorize green normal + } || { nop=$((number_failures++)) + echo "$indent$name" | colorize red normal + echo + IFS=$'\n' + for line in $(diff --unified $test/$dir/$expect $expect); do IFS=¬ + first_character=$(head --bytes 1 <<< $line) + color=$(match $first_character + green - red @ magenta none) + colorize $color normal <<< $line + done + echo + } + done + } + } + done + (( $number_failures > 0 )) && color=red || + color=green + echo + echo Resume: + echo $number_tests tests, $number_failures failures | colorize $color normal +} + +# Utility ├───────────────────────────────────────────────────────────────────── + +match() { + expression=$1; shift + while [[ $@ ]]; do + pattern=$1; shift; value=$1 next=$1 default_value=$pattern + [[ $next ]] || { + echo $default_value + return 1 + } + [[ $expression = $pattern ]] && { + echo $value + return 0 + } + shift + done +} + +repeat() { text=$1 count=${2:-0} + echo $(yes $text | head --lines $count | join) +} + +join() { + tr --delete "\n" +} + +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=$(awk "/$color_name/ { print \$2 }" <<< $color) + style_nr=$(awk "/$style_name/ { print \$2 }" <<< $style) + sed s/COLOR_NR/$color_nr/';'s/STYLE_NR/$style_nr/ <<< '\e[STYLE_NR;COLOR_NRm' +} + +colorize() { text=$(cat) color_name=${1:-none} style_name=${2:-none} + echo -e $(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none) +} + + +main $@ |
