add testing framework
This commit is contained in:
parent
7aa78d726a
commit
d20d43bf36
28
test/README.asciidoc
Normal file
28
test/README.asciidoc
Normal 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 test’s expected output and the actual output.
|
1
test/compose/inline-sort/cmd
Normal file
1
test/compose/inline-sort/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-i>bs<space><ret>c<ret><esc><a-i>b|sort<ret><a-j>
|
1
test/compose/inline-sort/in
Normal file
1
test/compose/inline-sort/in
Normal file
|
@ -0,0 +1 @@
|
|||
(e d c b a)
|
1
test/compose/inline-sort/out
Normal file
1
test/compose/inline-sort/out
Normal file
|
@ -0,0 +1 @@
|
|||
(a b c d e)
|
111
test/run
Executable file
111
test/run
Executable 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
1
test/unit/APPEND/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
APPEND
|
1
test/unit/APPEND/in
Normal file
1
test/unit/APPEND/in
Normal file
|
@ -0,0 +1 @@
|
|||
A
|
1
test/unit/APPEND/out
Normal file
1
test/unit/APPEND/out
Normal file
|
@ -0,0 +1 @@
|
|||
APPEND
|
1
test/unit/DOWN/cmd
Normal file
1
test/unit/DOWN/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
J
|
2
test/unit/DOWN/in
Normal file
2
test/unit/DOWN/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
%(foo)
|
||||
bar
|
2
test/unit/DOWN/selections
Normal file
2
test/unit/DOWN/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
foo
|
||||
bar
|
1
test/unit/END/WORD/cmd
Normal file
1
test/unit/END/WORD/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}W
|
1
test/unit/END/WORD/in
Normal file
1
test/unit/END/WORD/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(b)ar-baz qux
|
1
test/unit/END/WORD/selections
Normal file
1
test/unit/END/WORD/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar-baz
|
1
test/unit/END/angle/cmd
Normal file
1
test/unit/END/angle/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}a
|
1
test/unit/END/angle/in
Normal file
1
test/unit/END/angle/in
Normal file
|
@ -0,0 +1 @@
|
|||
#include <%(foo)>
|
1
test/unit/END/angle/selections
Normal file
1
test/unit/END/angle/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo>
|
1
test/unit/END/braces/cmd
Normal file
1
test/unit/END/braces/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}B
|
3
test/unit/END/braces/in
Normal file
3
test/unit/END/braces/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"%(foo)": "bar"
|
||||
}
|
2
test/unit/END/braces/selections
Normal file
2
test/unit/END/braces/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
foo"\: "bar"
|
||||
}
|
1
test/unit/END/brackets/cmd
Normal file
1
test/unit/END/brackets/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}r
|
3
test/unit/END/brackets/in
Normal file
3
test/unit/END/brackets/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
[
|
||||
"%(foo)"
|
||||
]
|
2
test/unit/END/brackets/selections
Normal file
2
test/unit/END/brackets/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
foo"
|
||||
]
|
1
test/unit/END/double_quote/cmd
Normal file
1
test/unit/END/double_quote/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}Q
|
1
test/unit/END/double_quote/in
Normal file
1
test/unit/END/double_quote/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo("%(b)ar")
|
1
test/unit/END/double_quote/selections
Normal file
1
test/unit/END/double_quote/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar"
|
1
test/unit/END/grave_quote/cmd
Normal file
1
test/unit/END/grave_quote/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}g
|
1
test/unit/END/grave_quote/in
Normal file
1
test/unit/END/grave_quote/in
Normal file
|
@ -0,0 +1 @@
|
|||
echo `%(f)oo`
|
1
test/unit/END/grave_quote/selections
Normal file
1
test/unit/END/grave_quote/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo`
|
1
test/unit/END/indent/cmd
Normal file
1
test/unit/END/indent/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}i
|
3
test/unit/END/indent/in
Normal file
3
test/unit/END/indent/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
foo(%(b)ar)
|
||||
|
3
test/unit/END/indent/selections
Normal file
3
test/unit/END/indent/selections
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo(bar)
|
||||
|
||||
|
1
test/unit/END/paragraph/cmd
Normal file
1
test/unit/END/paragraph/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}p
|
8
test/unit/END/paragraph/in
Normal file
8
test/unit/END/paragraph/in
Normal file
|
@ -0,0 +1,8 @@
|
|||
a
|
||||
b
|
||||
|
||||
%(c)
|
||||
d
|
||||
|
||||
e
|
||||
f
|
4
test/unit/END/paragraph/selections
Normal file
4
test/unit/END/paragraph/selections
Normal file
|
@ -0,0 +1,4 @@
|
|||
c
|
||||
d
|
||||
|
||||
|
1
test/unit/END/parenthesis/cmd
Normal file
1
test/unit/END/parenthesis/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}b
|
1
test/unit/END/parenthesis/in
Normal file
1
test/unit/END/parenthesis/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo(%(b)ar)
|
1
test/unit/END/parenthesis/selections
Normal file
1
test/unit/END/parenthesis/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar)
|
1
test/unit/END/sentence/cmd
Normal file
1
test/unit/END/sentence/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}s
|
6
test/unit/END/sentence/in
Normal file
6
test/unit/END/sentence/in
Normal 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.
|
2
test/unit/END/sentence/selections
Normal file
2
test/unit/END/sentence/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua.
|
1
test/unit/END/single_quote/cmd
Normal file
1
test/unit/END/single_quote/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}q
|
1
test/unit/END/single_quote/in
Normal file
1
test/unit/END/single_quote/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo('%(b)ar')
|
1
test/unit/END/single_quote/selections
Normal file
1
test/unit/END/single_quote/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar'
|
1
test/unit/END/word/cmd
Normal file
1
test/unit/END/word/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
}w
|
1
test/unit/END/word/in
Normal file
1
test/unit/END/word/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(b)ar baz
|
1
test/unit/END/word/selections
Normal file
1
test/unit/END/word/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar
|
1
test/unit/FIND-char-backward/cmd
Normal file
1
test/unit/FIND-char-backward/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-F>|
|
1
test/unit/FIND-char-backward/in
Normal file
1
test/unit/FIND-char-backward/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo|%(bar)|baz
|
1
test/unit/FIND-char-backward/selections
Normal file
1
test/unit/FIND-char-backward/selections
Normal file
|
@ -0,0 +1 @@
|
|||
|bar
|
1
test/unit/FIND-char-forward/cmd
Normal file
1
test/unit/FIND-char-forward/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
F|
|
1
test/unit/FIND-char-forward/in
Normal file
1
test/unit/FIND-char-forward/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo|%(bar)|baz
|
1
test/unit/FIND-char-forward/selections
Normal file
1
test/unit/FIND-char-forward/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar|
|
1
test/unit/GOTO/buffer-bottom/cmd
Normal file
1
test/unit/GOTO/buffer-bottom/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
Gj
|
3
test/unit/GOTO/buffer-bottom/in
Normal file
3
test/unit/GOTO/buffer-bottom/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
%(bar)
|
||||
baz
|
2
test/unit/GOTO/buffer-bottom/selections
Normal file
2
test/unit/GOTO/buffer-bottom/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
bar
|
||||
b
|
1
test/unit/GOTO/buffer-end/cmd
Normal file
1
test/unit/GOTO/buffer-end/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
Ge
|
3
test/unit/GOTO/buffer-end/in
Normal file
3
test/unit/GOTO/buffer-end/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
%(bar)
|
||||
baz
|
3
test/unit/GOTO/buffer-end/selections
Normal file
3
test/unit/GOTO/buffer-end/selections
Normal file
|
@ -0,0 +1,3 @@
|
|||
bar
|
||||
baz
|
||||
|
1
test/unit/GOTO/buffer-top/cmd
Normal file
1
test/unit/GOTO/buffer-top/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
Gk
|
3
test/unit/GOTO/buffer-top/in
Normal file
3
test/unit/GOTO/buffer-top/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
%(bar)
|
||||
baz
|
2
test/unit/GOTO/buffer-top/selections
Normal file
2
test/unit/GOTO/buffer-top/selections
Normal file
|
@ -0,0 +1,2 @@
|
|||
foo
|
||||
b
|
1
test/unit/GOTO/last-change/cmd
Normal file
1
test/unit/GOTO/last-change/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
dggG.
|
3
test/unit/GOTO/last-change/in
Normal file
3
test/unit/GOTO/last-change/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
%(bar)
|
||||
baz
|
3
test/unit/GOTO/last-change/selections
Normal file
3
test/unit/GOTO/last-change/selections
Normal file
|
@ -0,0 +1,3 @@
|
|||
foo
|
||||
|
||||
|
1
test/unit/GOTO/line-begin/cmd
Normal file
1
test/unit/GOTO/line-begin/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
Gh
|
1
test/unit/GOTO/line-begin/in
Normal file
1
test/unit/GOTO/line-begin/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(bar) baz
|
1
test/unit/GOTO/line-begin/selections
Normal file
1
test/unit/GOTO/line-begin/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo bar
|
1
test/unit/GOTO/line-end/cmd
Normal file
1
test/unit/GOTO/line-end/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
Gl
|
1
test/unit/GOTO/line-end/in
Normal file
1
test/unit/GOTO/line-end/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(bar) baz
|
1
test/unit/GOTO/line-end/selections
Normal file
1
test/unit/GOTO/line-end/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar baz
|
0
test/unit/GOTO/window-bottom/README
Normal file
0
test/unit/GOTO/window-bottom/README
Normal file
0
test/unit/GOTO/window-center/README
Normal file
0
test/unit/GOTO/window-center/README
Normal file
0
test/unit/GOTO/window-top/README
Normal file
0
test/unit/GOTO/window-top/README
Normal file
1
test/unit/INSERT/cmd
Normal file
1
test/unit/INSERT/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
IINSER
|
1
test/unit/INSERT/in
Normal file
1
test/unit/INSERT/in
Normal file
|
@ -0,0 +1 @@
|
|||
T
|
1
test/unit/INSERT/out
Normal file
1
test/unit/INSERT/out
Normal file
|
@ -0,0 +1 @@
|
|||
INSERT
|
1
test/unit/LEFT/cmd
Normal file
1
test/unit/LEFT/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
H
|
1
test/unit/LEFT/in
Normal file
1
test/unit/LEFT/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(bar)
|
1
test/unit/LEFT/selections
Normal file
1
test/unit/LEFT/selections
Normal file
|
@ -0,0 +1 @@
|
|||
ba
|
1
test/unit/NEXT-WORD/cmd
Normal file
1
test/unit/NEXT-WORD/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-W>
|
1
test/unit/NEXT-WORD/in
Normal file
1
test/unit/NEXT-WORD/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(foo )bar-baz qux
|
1
test/unit/NEXT-WORD/selections
Normal file
1
test/unit/NEXT-WORD/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo bar-baz
|
1
test/unit/NEXT-match/cmd
Normal file
1
test/unit/NEXT-match/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
N
|
1
test/unit/NEXT-match/in
Normal file
1
test/unit/NEXT-match/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(foo) bar
|
1
test/unit/NEXT-match/rc
Normal file
1
test/unit/NEXT-match/rc
Normal file
|
@ -0,0 +1 @@
|
|||
reg / [a-z]+
|
1
test/unit/NEXT-match/selections
Normal file
1
test/unit/NEXT-match/selections
Normal file
|
@ -0,0 +1 @@
|
|||
bar:foo
|
1
test/unit/NEXT-word/cmd
Normal file
1
test/unit/NEXT-word/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
W
|
1
test/unit/NEXT-word/in
Normal file
1
test/unit/NEXT-word/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(foo )bar baz
|
1
test/unit/NEXT-word/selections
Normal file
1
test/unit/NEXT-word/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo bar
|
1
test/unit/PREVIOUS-WORD/cmd
Normal file
1
test/unit/PREVIOUS-WORD/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-B>
|
1
test/unit/PREVIOUS-WORD/in
Normal file
1
test/unit/PREVIOUS-WORD/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(b)ar baz
|
1
test/unit/PREVIOUS-WORD/selections
Normal file
1
test/unit/PREVIOUS-WORD/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo b
|
1
test/unit/PREVIOUS-word/cmd
Normal file
1
test/unit/PREVIOUS-word/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-b>
|
1
test/unit/PREVIOUS-word/in
Normal file
1
test/unit/PREVIOUS-word/in
Normal file
|
@ -0,0 +1 @@
|
|||
foo %(b)ar baz
|
1
test/unit/PREVIOUS-word/selections
Normal file
1
test/unit/PREVIOUS-word/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo
|
1
test/unit/RIGHT/cmd
Normal file
1
test/unit/RIGHT/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
L
|
1
test/unit/RIGHT/in
Normal file
1
test/unit/RIGHT/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(foo) bar
|
1
test/unit/RIGHT/selections
Normal file
1
test/unit/RIGHT/selections
Normal file
|
@ -0,0 +1 @@
|
|||
foo
|
1
test/unit/SEARCH-reverse/cmd
Normal file
1
test/unit/SEARCH-reverse/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-?>[a-z]+<ret>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user