From c70c1ecb3178492757cfde95f931b7c434db3174 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Fri, 5 Feb 2010 14:35:45 +0100 Subject: (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 --- test/completion/perldoc.exp | 4 +--- test/generate | 4 +--- test/lib/library.exp | 35 +++++++++++++++++++++++++++++++++++ 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 < "$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} -- cgit v1.2.1