mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-22 19:03:35 +00:00
saner assertions for multiline output
This commit is contained in:
parent
497911d6c0
commit
b8504ed2a9
4 changed files with 42 additions and 29 deletions
|
@ -41,8 +41,7 @@ else
|
|||
exit 1
|
||||
fi"
|
||||
run rbenv-completions hello happy world
|
||||
assert_success
|
||||
assert_line 0 "happy"
|
||||
assert_line 1 "world"
|
||||
refute_line 2
|
||||
assert_success "\
|
||||
happy
|
||||
world"
|
||||
}
|
||||
|
|
|
@ -22,10 +22,9 @@ create_executable() {
|
|||
|
||||
rbenv-rehash
|
||||
run rbenv-completions exec
|
||||
assert_success
|
||||
assert_line 0 "rake"
|
||||
assert_line 1 "ruby"
|
||||
refute_line 2
|
||||
assert_success "\
|
||||
rake
|
||||
ruby"
|
||||
}
|
||||
|
||||
@test "supports hook path with spaces" {
|
||||
|
@ -45,20 +44,19 @@ create_executable() {
|
|||
echo \$0
|
||||
while [[ \$# -gt 0 ]]; do
|
||||
# hack to avoid bash builtin echo which can't output '-e'
|
||||
cat <<<\"\$1\"
|
||||
printf \"%s\\n\" \"\$1\"
|
||||
shift 1
|
||||
done
|
||||
"
|
||||
done"
|
||||
|
||||
run rbenv-exec ruby -w -e "puts 'hello world'" -- extra args
|
||||
assert_line 0 "${RBENV_ROOT}/versions/2.0/bin/ruby"
|
||||
assert_line 1 "-w"
|
||||
assert_line 2 "-e"
|
||||
assert_line 3 "puts 'hello world'"
|
||||
assert_line 4 "--"
|
||||
assert_line 5 "extra"
|
||||
assert_line 6 "args"
|
||||
refute_line 7
|
||||
assert_success "\
|
||||
${RBENV_ROOT}/versions/2.0/bin/ruby
|
||||
-w
|
||||
-e
|
||||
puts 'hello world'
|
||||
--
|
||||
extra
|
||||
args"
|
||||
}
|
||||
|
||||
@test "supports ruby -S <cmd>" {
|
||||
|
|
|
@ -22,10 +22,10 @@ create_hook() {
|
|||
create_hook "$path2" exec "bueno.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_line 0 "${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash"
|
||||
assert_line 1 "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash"
|
||||
assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash"
|
||||
assert_success "\
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
|
||||
${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash"
|
||||
}
|
||||
|
||||
@test "supports hook paths with spaces" {
|
||||
|
@ -35,9 +35,9 @@ create_hook() {
|
|||
create_hook "$path2" exec "ahoy.bash"
|
||||
|
||||
RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
|
||||
assert_success
|
||||
assert_line 0 "${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash"
|
||||
assert_line 1 "${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash"
|
||||
assert_success "\
|
||||
${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
|
||||
${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash"
|
||||
}
|
||||
|
||||
@test "resolves relative paths" {
|
||||
|
|
|
@ -26,7 +26,7 @@ assert_success() {
|
|||
if [ "$status" -ne 0 ]; then
|
||||
flunk "command failed with exit status $status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output "$1"
|
||||
assert_output_lines "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ assert_failure() {
|
|||
if [ "$status" -eq 0 ]; then
|
||||
flunk "expected failed exit status"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
assert_output "$1"
|
||||
assert_output_lines "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -50,10 +50,25 @@ assert_output() {
|
|||
assert_equal "$1" "$output"
|
||||
}
|
||||
|
||||
# compares lines with leading whitespace trimmed
|
||||
assert_output_lines() {
|
||||
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() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
assert_equal "$2" "${lines[$1]}"
|
||||
else
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then return 0; fi
|
||||
done
|
||||
|
@ -63,11 +78,12 @@ assert_line() {
|
|||
|
||||
refute_line() {
|
||||
if [ "$1" -ge 0 ] 2>/dev/null; then
|
||||
num_lines="${#lines[@]}"
|
||||
local num_lines="${#lines[@]}"
|
||||
if [ "$1" -lt "$num_lines" ]; then
|
||||
flunk "output has $num_lines lines"
|
||||
fi
|
||||
else
|
||||
local line
|
||||
for line in "${lines[@]}"; do
|
||||
if [ "$line" = "$1" ]; then
|
||||
flunk "expected to not find line \`$line'"
|
||||
|
|
Loading…
Reference in a new issue