Skip to content

Commit cb3f942

Browse files
committed
Improve test output
1 parent f05c2c4 commit cb3f942

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

tests/completion-bundle/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ _TEST_BINARIES=(ruby bundle rails)
99

1010
cd "$RAILS_TEST_APP_DIR"
1111

12+
print-binary-versions
13+
1214
begin-test 'should offer basic commands'
1315
(
1416
test-completion bundle ''
@@ -39,3 +41,5 @@ begin-test 'should trigger completion for subcommands: rails'
3941
reject install
4042
)
4143
end-test
44+
45+
end-test-suite

tests/completion-gem/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ source "$(dirname "$0")/../../completion-gem"
55
_TEST_FN=__gem
66
_TEST_BINARIES=(ruby gem)
77

8+
begin-test-suite
9+
810
begin-test 'should suggest options'
911
(
1012
test-completion gem -
@@ -82,3 +84,5 @@ begin-test 'after unpack should suggest local .gem files'
8284
rm -f foo.rb foo.gem foo.gemspec
8385
)
8486
end-test
87+
88+
end-test-suite

tests/completion-jruby/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ source "$(dirname "$0")/../../completion-jruby"
55
_TEST_FN=__jruby
66
_TEST_BINARIES=(jruby)
77

8+
begin-test-suite
9+
810
begin-test 'should provide (limited) funcitonality when completion-ruby is not present'
911
(
1012
test-completion jruby -
@@ -34,3 +36,5 @@ begin-test "after --disable should suggest features"
3436
expect did_you_mean gems rubyopt
3537
)
3638
end-test
39+
40+
end-test-suite

tests/completion-rails/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ source "$(dirname "$0")/../../completion-rails"
55
_TEST_FN=__rails
66
_TEST_BINARIES=(ruby rails)
77

8+
begin-test-suite
9+
810
begin-test 'when outside of a Rails project, should offer the command `new`'
911
(
1012
test-completion rails ''
@@ -36,3 +38,5 @@ begin-test 'completion should work in subdirectories'
3638
expect controller generator helper model
3739
)
3840
end-test
41+
42+
end-test-suite

tests/completion-rake/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ _TEST_BINARIES=(ruby rake rails)
88

99
cd "$RAILS_TEST_APP_DIR"
1010

11+
begin-test-suite
12+
1113
begin-test 'should offer commands from the Rakefile'
1214
(
1315
test-completion rake ''
@@ -32,3 +34,5 @@ begin-test 'should suggest options'
3234
expect --backtrace= '--help ' '--version '
3335
)
3436
end-test
37+
38+
end-test-suite

tests/completion-ruby/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ source "$(dirname "$0")/../../completion-ruby"
55
_TEST_FN=__ruby
66
_TEST_BINARIES=(ruby)
77

8+
begin-test-suite
9+
810
begin-test 'should suggest options'
911
(
1012
test-completion ruby -
@@ -18,3 +20,5 @@ begin-test 'after -S should suggest commands from PATH'
1820
expect bundle rake
1921
)
2022
end-test
23+
24+
end-test-suite

tests/test-utils

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@
44
# This builtin only works in real completions, so stub it for the tests
55
compopt() { true; }
66

7+
begin-test-suite() {
8+
print-binary-versions
9+
echo
10+
}
11+
12+
end-test-suite() {
13+
true
14+
}
15+
716
begin-test() {
817
echo "TEST: $1"
918
}
1019

1120
end-test() {
1221
local status=$?
1322
if [[ $status -eq 0 ]]; then
14-
echo 'PASS'
23+
echo ' PASS'
1524
echo
1625
else
1726
if [[ -n $_TEST_BINARIES ]]; then
1827
echo
19-
local bin
20-
for bin in "${_TEST_BINARIES[@]}"; do
21-
"$bin" --version
22-
done
28+
print-binary-versions
2329
fi
2430
exit $status
2531
fi
2632
}
2733

2834
test-completion() {
29-
print-array 'RUNNING TEST: ' "$@"
30-
_COMPLETION_TEST=($@)
35+
_COMPLETION_TEST=($@⇥)
36+
print-array ' INPUT:' "${_COMPLETION_TEST[@]}"
3137
COMP_WORDS=($@)
3238
COMP_CWORD=$(($# - 1))
3339
COMP_LINE="$*"
@@ -36,35 +42,35 @@ test-completion() {
3642
}
3743

3844
expect() {
39-
print-array 'EXPECTED RESULT: ' "$@"
45+
print-array ' EXPECTED RESULT:' "$@"
4046
local word
4147
for word in "$@"; do
4248
if ! [[ " ${COMPREPLY[@]} " =~ " $word " ]]; then
43-
echo 'Completion failed!'
44-
print-array ' Command: ' "${_COMPLETION_TEST[@]}"
45-
print-array ' Output: ' "${COMPREPLY[@]}"
46-
echo " Missing: $(printf "%q" "$word")"
49+
echo ' Expectation failed!'
50+
print-array ' Output:' "${COMPREPLY[@]}"
51+
if [[ -n $COMPREPLY ]]; then
52+
echo " Missing: $(printf "%q" "$word")"
53+
fi
4754
exit 1
4855
fi >&2
4956
done
5057
}
5158

5259
reject() {
53-
print-array 'SHOULD NOT INCLUDE: ' "$@"
60+
print-array ' SHOULD NOT INCLUDE:' "$@"
5461
local word
5562
for word in "$@"; do
5663
if [[ " ${COMPREPLY[@]} " =~ " $word " ]]; then
57-
echo 'Completion failed!'
58-
print-array ' Command: ' "${_COMPLETION_TEST[@]}"
59-
print-array ' Output: ' "${COMPREPLY[@]}"
60-
echo " Unexpected: $(printf "%q" "$word")"
64+
echo ' Expectation failed!'
65+
print-array ' Output:' "${COMPREPLY[@]}"
66+
echo " Unexpected: $(printf "%q" "$word")"
6167
exit 1
6268
fi >&2
6369
done
6470
}
6571

6672
print-array() {
67-
echo -n "$1"
73+
printf '%-22s' "$1"
6874
if [[ $# -eq 1 ]]; then
6975
echo ' (empty)'
7076
return
@@ -75,3 +81,11 @@ print-array() {
7581
done
7682
echo
7783
}
84+
85+
print-binary-versions() {
86+
echo 'Versions:'
87+
local bin
88+
for bin in "${_TEST_BINARIES[@]}"; do
89+
"$bin" --version || echo "`$bin --version` failed with status $?" >&2
90+
done
91+
}

0 commit comments

Comments
 (0)