Merge remote-tracking branch 'alexherbo2/testing-framework'

This commit is contained in:
Maxime Coste 2014-10-09 13:26:19 +01:00
commit 7ca095c2b9
472 changed files with 809 additions and 0 deletions

28
test/README.asciidoc Normal file
View File

@ -0,0 +1,28 @@
Regression test
===============
:unified-context-diff: https://en.wikipedia.org/wiki/Diff#Unified_format
Source structure
----------------
----------------------------------------------
.
├── unit
│ └── …
└── compose
└── …
├── cmd → command
├── [in] → start file
├── [out] → end file
├── [selections] → selection contents
├── [state] → selection states
└── [rc] → configuration
----------------------------------------------
Usage
-----
To test, just type +run [test]+ in the +test+ directory.
It will print each passing test. If a test fails, a {unified-context-diff}[unified context diff]
is printed showing the tests expected output and the actual output.

View File

@ -0,0 +1 @@
<a-i>bs<space><ret>c<ret><esc><a-i>b|sort<ret><a-j>

View File

@ -0,0 +1 @@
(e d c b a)

View File

@ -0,0 +1 @@
(a b c d e)

111
test/run Executable file
View File

@ -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 $@

1
test/unit/APPEND/cmd Normal file
View File

@ -0,0 +1 @@
APPEND

1
test/unit/APPEND/in Normal file
View File

@ -0,0 +1 @@
A

1
test/unit/APPEND/out Normal file
View File

@ -0,0 +1 @@
APPEND

1
test/unit/DOWN/cmd Normal file
View File

@ -0,0 +1 @@
J

2
test/unit/DOWN/in Normal file
View File

@ -0,0 +1,2 @@
%(foo)
bar

View File

@ -0,0 +1,2 @@
foo
bar

1
test/unit/END/WORD/cmd Normal file
View File

@ -0,0 +1 @@
}W

1
test/unit/END/WORD/in Normal file
View File

@ -0,0 +1 @@
foo %(b)ar-baz qux

View File

@ -0,0 +1 @@
bar-baz

1
test/unit/END/angle/cmd Normal file
View File

@ -0,0 +1 @@
}a

1
test/unit/END/angle/in Normal file
View File

@ -0,0 +1 @@
#include <%(foo)>

View File

@ -0,0 +1 @@
foo>

1
test/unit/END/braces/cmd Normal file
View File

@ -0,0 +1 @@
}B

3
test/unit/END/braces/in Normal file
View File

@ -0,0 +1,3 @@
{
"%(foo)": "bar"
}

View File

@ -0,0 +1,2 @@
foo"\: "bar"
}

View File

@ -0,0 +1 @@
}r

View File

@ -0,0 +1,3 @@
[
"%(foo)"
]

View File

@ -0,0 +1,2 @@
foo"
]

View File

@ -0,0 +1 @@
}Q

View File

@ -0,0 +1 @@
foo("%(b)ar")

View File

@ -0,0 +1 @@
bar"

View File

@ -0,0 +1 @@
}g

View File

@ -0,0 +1 @@
echo `%(f)oo`

View File

@ -0,0 +1 @@
foo`

1
test/unit/END/indent/cmd Normal file
View File

@ -0,0 +1 @@
}i

3
test/unit/END/indent/in Normal file
View File

@ -0,0 +1,3 @@
foo(%(b)ar)

View File

@ -0,0 +1,3 @@
foo(bar)

View File

@ -0,0 +1 @@
}p

View File

@ -0,0 +1,8 @@
a
b
%(c)
d
e
f

View File

@ -0,0 +1,4 @@
c
d

View File

@ -0,0 +1 @@
}b

View File

@ -0,0 +1 @@
foo(%(b)ar)

View File

@ -0,0 +1 @@
bar)

View File

@ -0,0 +1 @@
}s

View File

@ -0,0 +1,6 @@
%(Lorem ipsum) dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.

View File

@ -0,0 +1,2 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.

View File

@ -0,0 +1 @@
}q

View File

@ -0,0 +1 @@
foo('%(b)ar')

View File

@ -0,0 +1 @@
bar'

1
test/unit/END/word/cmd Normal file
View File

@ -0,0 +1 @@
}w

1
test/unit/END/word/in Normal file
View File

@ -0,0 +1 @@
foo %(b)ar baz

View File

@ -0,0 +1 @@
bar

View File

@ -0,0 +1 @@
<a-F>|

View File

@ -0,0 +1 @@
foo|%(bar)|baz

View File

@ -0,0 +1 @@
|bar

View File

@ -0,0 +1 @@
F|

View File

@ -0,0 +1 @@
foo|%(bar)|baz

View File

@ -0,0 +1 @@
bar|

View File

@ -0,0 +1 @@
Gj

View File

@ -0,0 +1,3 @@
foo
%(bar)
baz

View File

@ -0,0 +1,2 @@
bar
b

View File

@ -0,0 +1 @@
Ge

View File

@ -0,0 +1,3 @@
foo
%(bar)
baz

View File

@ -0,0 +1,3 @@
bar
baz

View File

@ -0,0 +1 @@
Gk

View File

@ -0,0 +1,3 @@
foo
%(bar)
baz

View File

@ -0,0 +1,2 @@
foo
b

View File

@ -0,0 +1 @@
dggG.

View File

@ -0,0 +1,3 @@
foo
%(bar)
baz

View File

@ -0,0 +1,3 @@
foo

View File

@ -0,0 +1 @@
Gh

View File

@ -0,0 +1 @@
foo %(bar) baz

View File

@ -0,0 +1 @@
foo bar

View File

@ -0,0 +1 @@
Gl

View File

@ -0,0 +1 @@
foo %(bar) baz

View File

@ -0,0 +1 @@
bar baz

View File

View File

View File

1
test/unit/INSERT/cmd Normal file
View File

@ -0,0 +1 @@
IINSER

1
test/unit/INSERT/in Normal file
View File

@ -0,0 +1 @@
T

1
test/unit/INSERT/out Normal file
View File

@ -0,0 +1 @@
INSERT

1
test/unit/LEFT/cmd Normal file
View File

@ -0,0 +1 @@
H

1
test/unit/LEFT/in Normal file
View File

@ -0,0 +1 @@
foo %(bar)

View File

@ -0,0 +1 @@
ba

1
test/unit/NEXT-WORD/cmd Normal file
View File

@ -0,0 +1 @@
<a-W>

1
test/unit/NEXT-WORD/in Normal file
View File

@ -0,0 +1 @@
%(foo )bar-baz qux

View File

@ -0,0 +1 @@
foo bar-baz

1
test/unit/NEXT-match/cmd Normal file
View File

@ -0,0 +1 @@
N

1
test/unit/NEXT-match/in Normal file
View File

@ -0,0 +1 @@
%(foo) bar

1
test/unit/NEXT-match/rc Normal file
View File

@ -0,0 +1 @@
reg / [a-z]+

View File

@ -0,0 +1 @@
bar:foo

1
test/unit/NEXT-word/cmd Normal file
View File

@ -0,0 +1 @@
W

1
test/unit/NEXT-word/in Normal file
View File

@ -0,0 +1 @@
%(foo )bar baz

View File

@ -0,0 +1 @@
foo bar

View File

@ -0,0 +1 @@
<a-B>

View File

@ -0,0 +1 @@
foo %(b)ar baz

View File

@ -0,0 +1 @@
foo b

View File

@ -0,0 +1 @@
<a-b>

View File

@ -0,0 +1 @@
foo %(b)ar baz

View File

@ -0,0 +1 @@
foo

1
test/unit/RIGHT/cmd Normal file
View File

@ -0,0 +1 @@
L

1
test/unit/RIGHT/in Normal file
View File

@ -0,0 +1 @@
%(foo) bar

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
<a-?>[a-z]+<ret>

Some files were not shown because too many files have changed in this diff Show More