[Bash-completion-commits] [SCM] bash-completion branch, master, updated. c70c1ecb3178492757cfde95f931b7c434db3174
Freddy Vulto
fvulto at gmail.com
Fri Feb 5 13:36:08 UTC 2010
The following commit has been merged in the master branch:
commit c70c1ecb3178492757cfde95f931b7c434db3174
Author: Freddy Vulto <fvulto at gmail.com>
Date: Fri Feb 5 14:35:45 2010 +0100
(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>
diff --git a/test/completion/perldoc.exp b/test/completion/perldoc.exp
index e06e594..d0d49b1 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 5c184d5..aa282a2 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 cb0b9c2..387b40b 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}
--
bash-completion
More information about the Bash-completion-commits
mailing list