parent
992c74a06d
commit
a482b1f8d8
81
test/run
81
test/run
|
@ -3,26 +3,25 @@
|
||||||
# Main ├────────────────────────────────────────────────────────────────────────
|
# Main ├────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local number_tests=0
|
number_tests=0
|
||||||
local number_failures=0
|
number_failures=0
|
||||||
local dirs=$@
|
dirs="$@"
|
||||||
local test=$(pwd)
|
test=$(pwd)
|
||||||
local work=$(mktemp --directory)
|
work=$(mktemp --directory)
|
||||||
cp --recursive . $work
|
cp -R . $work
|
||||||
trap "rm --recursive $work" EXIT
|
trap "rm -R $work" EXIT
|
||||||
for dir in $(find $dirs -type d); do
|
for dir in $(find $dirs -type d); do
|
||||||
cd $test/$dir;
|
cd $test/$dir;
|
||||||
local test_files=$(find * -name out -o -name selections -o -name state)
|
test_files=$(find * -name out -o -name selections -o -name state)
|
||||||
cd $work/$dir;
|
cd $work/$dir;
|
||||||
IFS=¬
|
indent="$(repeat ' ' $(pwd | sed "s|$test||" | tr -d -c / | awk '{ print length }'))"
|
||||||
local indent=$(repeat ' ' $(pwd | sed "s|$test||" | tr --delete --complement / | awk '{ print length }'))
|
name=$(basename $PWD)
|
||||||
local name=$(basename $PWD)
|
|
||||||
if ! exists cmd; then
|
if ! exists cmd; then
|
||||||
echo "$indent$name"
|
echo "$indent$name"
|
||||||
else
|
else
|
||||||
((number_tests++))
|
number_tests=$(($number_tests + 1))
|
||||||
touch in; cp in out
|
touch in; cp in out
|
||||||
local kak_commands="
|
kak_commands="
|
||||||
set global autoreload yes
|
set global autoreload yes
|
||||||
try %{
|
try %{
|
||||||
source rc
|
source rc
|
||||||
|
@ -42,20 +41,20 @@ main() {
|
||||||
write out
|
write out
|
||||||
quit!
|
quit!
|
||||||
"
|
"
|
||||||
kak out -n -e $kak_commands
|
kak out -n -e "$kak_commands"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for expect in $test_files; do
|
for expect in $test_files; do
|
||||||
if cmp --quiet $test/$dir/$expect $expect; then
|
if cmp -s $test/$dir/$expect $expect; then
|
||||||
echo "$indent$name" | colorize green normal
|
echo "$indent$name" | colorize green normal
|
||||||
else
|
else
|
||||||
((number_failures++))
|
number_failures=$(($number_failures + 1))
|
||||||
echo "$indent$name" | colorize red normal
|
echo "$indent$name" | colorize red normal
|
||||||
echo
|
echo
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for line in $(diff --unified $test/$dir/$expect $expect); do
|
for line in $(diff -u $test/$dir/$expect $expect); do
|
||||||
IFS=¬
|
IFS=¬
|
||||||
local first_character=$(echo "$line" | head --bytes 1)
|
first_character=$(echo "$line" | cut -b 1)
|
||||||
local color=$(match $first_character + green - red @ magenta none)
|
color=$(match $first_character + green - red @ magenta none)
|
||||||
echo "$line" | colorize $color normal
|
echo "$line" | colorize $color normal
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
|
@ -66,7 +65,7 @@ main() {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if (( $number_failures > 0 )); then
|
if expr $number_failures > 0; then
|
||||||
color=red
|
color=red
|
||||||
else
|
else
|
||||||
color=green
|
color=green
|
||||||
|
@ -81,17 +80,17 @@ main() {
|
||||||
match() {
|
match() {
|
||||||
expression="$1";
|
expression="$1";
|
||||||
shift
|
shift
|
||||||
while [[ "$@" ]]; do
|
while [ $# > 0 ]; do
|
||||||
local pattern="$1"
|
pattern="$1"
|
||||||
shift
|
shift
|
||||||
local value="$1"
|
value="$1"
|
||||||
local next="$1"
|
next="$1"
|
||||||
local default_value="$pattern"
|
default_value="$pattern"
|
||||||
if [[ -z "$next" ]]; then
|
if [ -z "$next" ]; then
|
||||||
echo $default_value
|
echo $default_value
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [[ "$expression" = "$pattern" ]]; then
|
if [ "$expression" = "$pattern" ]; then
|
||||||
echo "$value"
|
echo "$value"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -100,13 +99,13 @@ match() {
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
local text=$1
|
text=$1
|
||||||
local count=${2:-0}
|
count=${2:-0}
|
||||||
echo $(yes $text | head --lines $count | join)
|
echo $(yes $text | head -n $count | join)
|
||||||
}
|
}
|
||||||
|
|
||||||
join() {
|
join() {
|
||||||
tr --delete "\n"
|
tr -d "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
|
@ -114,25 +113,25 @@ exists() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_ansi_code() {
|
get_ansi_code() {
|
||||||
local color_name=${1:-none}
|
color_name=${1:-none}
|
||||||
local style_name=${2:-none}
|
style_name=${2:-none}
|
||||||
local color='none 00
|
color='none 00
|
||||||
red 31
|
red 31
|
||||||
green 32
|
green 32
|
||||||
yellow 33
|
yellow 33
|
||||||
magenta 35'
|
magenta 35'
|
||||||
local style='none 00
|
style='none 00
|
||||||
bold 01'
|
bold 01'
|
||||||
local color_nr=$(echo "$color" | awk "/$color_name/ { print \$2 }")
|
color_nr=$(echo "$color" | awk "/$color_name/ { print \$2 }")
|
||||||
local style_nr=$(echo "$style" | awk "/$style_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/
|
echo '\e[STYLE_NR;COLOR_NRm' | sed s/COLOR_NR/$color_nr/';'s/STYLE_NR/$style_nr/
|
||||||
}
|
}
|
||||||
|
|
||||||
colorize() {
|
colorize() {
|
||||||
local text=$(cat)
|
text=$(cat)
|
||||||
local color_name=${1:-none}
|
color_name=${1:-none}
|
||||||
local style_name=${2:-none}
|
style_name=${2:-none}
|
||||||
echo -e "$(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none)"
|
printf "$(get_ansi_code $color_name $style_name)$text$(get_ansi_code none none)\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user