Add testing of todo_completion.

Before adding any more features to todo_completion, I feel like I need test coverage, so this is a first stab at testing the completion results, via a new test function test_todo_completion.
Some basic tests showcase the capabilities.

Note: test-lib.sh now uses arrays, therefore all tests must use /bin/bash, not /bin/sh to avoid errors when sourcing test-lib. For consistency with todo.sh, we should have used Bash everywhere, anyway. Also note that t2000-multiline.sh needs some more quoting to avoid "Bash: ambiguous redirect" errors.
This commit is contained in:
Ingo Karkat
2012-02-21 14:16:23 +01:00
parent 46afb7f46a
commit 3b90d09b27
32 changed files with 126 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 2005 Junio C Hamano
#
@@ -632,6 +632,55 @@ EOF
exit 0
}
test_todo_completion () {
test "$#" = 3 ||
error "bug in the test script: not 3 parameters to test_todo_completion"
if ! test_skip "$@"
then
description=$1
expected=$3
if [ "${2: -1}" = ' ' ]
then
offset=0
say >&3 "expecting completions after: '$2'"
else
offset=1
say >&3 "expecting context completions for: '$2'"
fi
SAVEIFS=$IFS
IFS=' ' set -- $2
COMP_WORDS=("$@")
COMP_CWORD=$(($# - $offset))
IFS=' ' set -- $expected
EXPECT=("$@")
source "$TEST_DIRECTORY/../todo_completion"
_todo
IFS=$'\n'
printf '%s\n' "${EXPECT[*]}" > expect
printf '%s\n' "${COMPREPLY[*]}" > output
IFS=$SAVEIFS
if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ]
then
if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ]
then
test_ok_ "$description"
else
test_failure_ "$description" "Differing completion(s):
$(test_cmp expect output)"
fi
else
test_failure_ "$description" "Expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}:
$(test_cmp expect output)"
fi
fi
echo >&3 ""
}
test_init_todo "$test"
# Use -P to resolve symlinks in our working directory so that the pwd
# in subprocesses equals our $PWD (for pathname comparisons).