(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>
This commit is contained in:
parent
8aca9ab62d
commit
c70c1ecb31
@ -1,3 +1 @@
|
||||
if {[assert_bash_type perl]} {
|
||||
source "lib/completions/perldoc.exp"
|
||||
}; # if
|
||||
assert_source_completions perldoc
|
||||
|
@ -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()
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user