undo assert_output_lines in tests

It was a dumb idea and it wasn't even implemented perfectly.
This commit is contained in:
Mislav Marohnić 2013-04-06 14:10:44 +02:00
parent 969af1567a
commit 7fc5f46bbb
8 changed files with 67 additions and 58 deletions

View file

@ -38,7 +38,9 @@ else
exit 1 exit 1
fi" fi"
run rbenv-completions hello happy world run rbenv-completions hello happy world
assert_success "\ assert_success
happy assert_output <<OUT
world" happy
world
OUT
} }

View file

@ -27,9 +27,11 @@ create_executable() {
rbenv-rehash rbenv-rehash
run rbenv-completions exec run rbenv-completions exec
assert_success "\ assert_success
rake assert_output <<OUT
ruby" rake
ruby
OUT
} }
@test "supports hook path with spaces" { @test "supports hook path with spaces" {
@ -50,19 +52,20 @@ create_executable() {
echo \$0 echo \$0
for arg; do for arg; do
# hack to avoid bash builtin echo which can't output '-e' # hack to avoid bash builtin echo which can't output '-e'
printf "%s\\n" "\$arg" printf " %s\\n" "\$arg"
done done
SH SH
run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args run rbenv-exec ruby -w "/path to/ruby script.rb" -- extra args
assert_success "\ assert_success
${RBENV_ROOT}/versions/2.0/bin/ruby assert_output <<OUT
${RBENV_ROOT}/versions/2.0/bin/ruby
-w -w
-e /path to/ruby script.rb
puts 'hello world'
-- --
extra extra
args" args
OUT
} }
@test "supports ruby -S <cmd>" { @test "supports ruby -S <cmd>" {
@ -85,9 +88,10 @@ else
fi fi
SH SH
create_executable "rake" "\ create_executable "rake" <<SH
#!/usr/bin/env ruby #!/usr/bin/env ruby
echo hello rake" echo hello rake
SH
rbenv-rehash rbenv-rehash
run ruby -S rake run ruby -S rake

View file

@ -22,10 +22,12 @@ create_hook() {
create_hook "$path2" exec "bueno.bash" create_hook "$path2" exec "bueno.bash"
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
assert_success "\ assert_success
${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash assert_output <<OUT
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash ${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" ${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash
OUT
} }
@test "supports hook paths with spaces" { @test "supports hook paths with spaces" {
@ -35,9 +37,11 @@ create_hook() {
create_hook "$path2" exec "ahoy.bash" create_hook "$path2" exec "ahoy.bash"
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
assert_success "\ assert_success
${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash assert_output <<OUT
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash" ${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
OUT
} }
@test "resolves relative paths" { @test "resolves relative paths" {

View file

@ -45,8 +45,10 @@ create_executable() {
assert_success "" assert_success ""
run ls "${RBENV_ROOT}/shims" run ls "${RBENV_ROOT}/shims"
assert_success "\ assert_success
rake assert_output <<OUT
rspec rake
ruby" rspec
ruby
OUT
} }

View file

@ -22,9 +22,11 @@ load test_helper
@test "shell change invalid version" { @test "shell change invalid version" {
run rbenv-sh-shell 1.2.3 run rbenv-sh-shell 1.2.3
assert_failure "\ assert_failure
rbenv: version \`1.2.3' not installed assert_output <<SH
return 1" rbenv: version \`1.2.3' not installed
return 1
SH
} }
@test "shell change version" { @test "shell change version" {

View file

@ -26,7 +26,7 @@ assert_success() {
if [ "$status" -ne 0 ]; then if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status" flunk "command failed with exit status $status"
elif [ "$#" -gt 0 ]; then elif [ "$#" -gt 0 ]; then
assert_output_lines "$1" assert_output "$1"
fi fi
} }
@ -34,7 +34,7 @@ assert_failure() {
if [ "$status" -eq 0 ]; then if [ "$status" -eq 0 ]; then
flunk "expected failed exit status" flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then elif [ "$#" -gt 0 ]; then
assert_output_lines "$1" assert_output "$1"
fi fi
} }
@ -47,21 +47,11 @@ assert_equal() {
} }
assert_output() { assert_output() {
assert_equal "$1" "$output" local expected
} if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
# compares lines with leading whitespace trimmed fi
assert_output_lines() { assert_equal "$expected" "$output"
local -a expected
IFS=$'\n' expected=($1)
for (( i=0; i < ${#expected[@]}; i++ )); do
local wants="${expected[$i]}"
local got="${lines[$i]}"
assert_equal \
"${wants#"${wants%%[![:space:]]*}"}" \
"${got#"${got%%[![:space:]]*}"}"
done
assert_equal "${expected[$i]}" "${lines[$i]}"
} }
assert_line() { assert_line() {

View file

@ -16,9 +16,11 @@ create_executable() {
create_executable "2.0" "rspec" create_executable "2.0" "rspec"
run rbenv-whence ruby run rbenv-whence ruby
assert_success "\ assert_success
1.8 assert_output <<OUT
2.0" 1.8
2.0
OUT
run rbenv-whence rake run rbenv-whence rake
assert_success "1.8" assert_success "1.8"

View file

@ -49,9 +49,12 @@ create_executable() {
create_executable "2.0" "rspec" create_executable "2.0" "rspec"
RBENV_VERSION=1.8 run rbenv-which rspec RBENV_VERSION=1.8 run rbenv-which rspec
assert_failure "\ assert_failure
rbenv: rspec: command not found assert_output <<OUT
The \`rspec' command exists in these Ruby versions: rbenv: rspec: command not found
The \`rspec' command exists in these Ruby versions:
1.9 1.9
2.0" 2.0
OUT
} }