From c1dcd0ed7860c45c4d205f4a7bdbaadf86d543a9 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 22 Feb 2012 09:19:04 +0100 Subject: [PATCH] test-lib: Also check completion exit code. The completion may unexpectedly abort somewhere. Additionally, reformat the failure messages (don't prepend a "*", this should be reserved to mark the individual test runs) and use "compreply" instead of "output", so that it's already clear from the diff output that the completion is being tested. --- tests/test-lib.sh | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 8947e38..3e56af3 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -305,7 +305,7 @@ $cmp_output" else cmp_output=$(test_cmp expect output) test_failure_ "$2" "$3" " -* expected exit code $1, actual ${eval_ret}${cmp_output:+ +expected exit code $1, actual ${eval_ret}${cmp_output:+ }${cmp_output}" fi fi @@ -324,7 +324,7 @@ test_expect_code () { test_ok_ "$2" else test_failure_ "$2" "$3" " -* expected exit code $1, actual ${eval_ret}" +expected exit code $1, actual ${eval_ret}" fi fi echo >&3 "" @@ -658,24 +658,28 @@ test_todo_completion () { source "$TEST_DIRECTORY/../todo_completion" _todo - - IFS=$'\n' - printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect - printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > output - IFS=$SAVEIFS - - if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] + ret=$? + if [ "$ret" = 0 ] then - if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + IFS=$'\n' + printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect + printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > compreply + IFS=$SAVEIFS + + if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] then - test_ok_ "$description" + if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + then + test_ok_ "$description" + else + test_failure_ "$description" "$(test_cmp expect compreply)" + fi else - test_failure_ "$description" "Differing completion(s): -$(test_cmp expect output)" + test_failure_ "$description" "expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: +$(test_cmp expect compreply)" fi else - test_failure_ "$description" "Expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: -$(test_cmp expect output)" + test_failure_ "$description" "expected completions, actual exit code $ret" fi fi echo >&3 ""