summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreddy Vulto <fvulto@gmail.com>2010-02-05 14:35:45 +0100
committerFreddy Vulto <fvulto@gmail.com>2010-02-05 14:35:45 +0100
commitc70c1ecb3178492757cfde95f931b7c434db3174 (patch)
treed9fe081c1f74bb1cb8feb3d239be0dd74c0101eb
parent8aca9ab62d6e1e6881cf423fe27d2d71767f9b1a (diff)
downloadbash-completion-c70c1ecb3178492757cfde95f931b7c434db3174.tar.gz
(testsuite) Added helper functions
- assert_source_completions() - is_bash_completion_installed_for() This allows for cleaner invocation of tests in `lib/completions/'. For example, `completion/perldoc.exp' now just contains: assert_source_completions perldoc Skeleton test files for a command can be generated with: $ ./generate <command>
-rw-r--r--test/completion/perldoc.exp4
-rwxr-xr-xtest/generate4
-rw-r--r--test/lib/library.exp35
3 files changed, 37 insertions, 6 deletions
diff --git a/test/completion/perldoc.exp b/test/completion/perldoc.exp
index e06e594f..d0d49b1a 100644
--- a/test/completion/perldoc.exp
+++ b/test/completion/perldoc.exp
@@ -1,3 +1 @@
-if {[assert_bash_type perl]} {
- source "lib/completions/perldoc.exp"
-}; # if
+assert_source_completions perldoc
diff --git a/test/generate b/test/generate
index 5c184d56..aa282a2c 100755
--- a/test/generate
+++ b/test/generate
@@ -14,9 +14,7 @@ generate_test_completion() {
#if [ ! -f "$path" ]; then
# No, file doesn't exist; generate file
cat <<EXPECT > "$path"
-if {[assert_bash_type $1]} {
- source "lib/completions/$1.exp"
-}; # if
+assert_source_completions $1
EXPECT
#fi
} # generate_test_completion()
diff --git a/test/lib/library.exp b/test/lib/library.exp
index cb0b9c2a..387b40b7 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -451,6 +451,23 @@ proc assert_no_complete {{cmd} {test ""}} {
}; # assert_no_complete()
+# Source/run file with additional tests if completion for the specified command
+# is installed in bash.
+# @param string $command Command to check completion availability for.
+# @param string $file (optional) File to source/run. Default is
+# "lib/completions/$cmd.exp".
+proc assert_source_completions {command {file ""}} {
+ if {[is_bash_completion_installed_for $command]} {
+ if {[string length $file] == 0} {
+ set file "lib/completions/$command.exp"
+ }
+ source $file
+ } else {
+ untested $command
+ }
+}; # assert_source_completions()
+
+
# Sort list.
# `exec sort' is used instead of `lsort' to achieve exactly the
# same sort order as in bash.
@@ -534,6 +551,24 @@ proc init_tcl_bash_globals {} {
}; # init_tcl_bash_globals()
+# Check whether completion is installed for the specified command by executing
+# `complete -p ...' in bash.
+# @param string $command Command to check completion availability for.
+# @return boolean True (1) if completion is installed, False (0) if not.
+proc is_bash_completion_installed_for {command} {
+ set test "$command should have completion installed in bash"
+ set cmd "complete -p $command &> /dev/null && echo -n 0 || echo -n 1"
+ send "$cmd\r"
+ expect "$cmd\r\n"
+ expect {
+ -ex 0 { set result true }
+ -ex 1 { set result false }
+ }
+ expect "/@"
+ return $result
+}; # is_bash_completion_installed_for()
+
+
# Detect if test suite is running under Cygwin/Windows
proc is_cygwin {} {
expr {[string first [string tolower [exec uname -s]] cygwin] >= 0}