summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrestez Dan Leonard <cdleonard@gmail.com>2010-03-07 19:10:31 +0200
committerCrestez Dan Leonard <cdleonard@gmail.com>2010-03-07 19:10:31 +0200
commit2ca9db0a60ff83e7d3544c5c6ed78f0dcee5db20 (patch)
tree17f36dbf175fca0cf8cff4c543548bc4f415b8b1
parent4743f397597cc093421ade2b4f24d5a2bd35a0b4 (diff)
parent0f49bb1e3ca0074e81f106184854efd30dac2b8a (diff)
downloadbash-completion-2ca9db0a60ff83e7d3544c5c6ed78f0dcee5db20.tar.gz
Merge commit '0f49' into expect-fixes
-rw-r--r--CHANGES4
-rw-r--r--test/.gitignore1
-rw-r--r--test/lib/completion.exp9
-rw-r--r--test/lib/library.exp42
-rw-r--r--test/lib/unit.exp10
-rwxr-xr-xtest/run81
-rwxr-xr-xtest/runCompletion2
-rwxr-xr-xtest/runUnit2
8 files changed, 111 insertions, 40 deletions
diff --git a/CHANGES b/CHANGES
index 1ce2fccd..88339dae 100644
--- a/CHANGES
+++ b/CHANGES
@@ -72,6 +72,10 @@ bash-completion (2.x)
* Fix chown test crashing on systems with no root group (Alioth: #312306).
* Fixed tests when BASH_COMPLETION or TESTDIR contain spaces.
* Fix mount handling of escapes (Alioth: #311410, Launchpad: #219971).
+ * Cleanup scripts to run tests. Make runUnit and runCompletion use test/run.
+ Make it possible to run tests from any directory.
+ * Add a --debug-xtrace option to test/run using BASH_XTRACEFD from bash-4.1.
+ * Add a --timeout option to test/run to override the default expect timeout.
[ Raphaƫl Droz ]
* Add xsltproc completion (Alioth: #311843).
diff --git a/test/.gitignore b/test/.gitignore
index 42e178f2..0a099fdb 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,2 @@
dbg.log
+xtrace.log
diff --git a/test/lib/completion.exp b/test/lib/completion.exp
index 18ece7ff..ea2a3d8d 100644
--- a/test/lib/completion.exp
+++ b/test/lib/completion.exp
@@ -2,16 +2,13 @@ source ${srcdir}/lib/library.exp
proc completion_exit {} {
- # Exit bash
send "\rexit\r"
-}; # completion_exit()
+}
proc completion_start {} {
- start_bash
- source_bash_completion
- init_tcl_bash_globals
-}; # completion_start()
+ start_interactive_test
+}
proc completion_version {} {
diff --git a/test/lib/library.exp b/test/lib/library.exp
index a294cf66..97bede3b 100644
--- a/test/lib/library.exp
+++ b/test/lib/library.exp
@@ -829,6 +829,48 @@ proc start_bash {} {
}; # start_bash()
+# Redirect xtrace output to a file.
+#
+# 'set -x' can be very useful for debugging but by default it writes to
+# stderr. Bash 4.1 has a feature to redirect this output to a random FD.
+#
+# This function uses file descriptor 6. This will break if any completion
+# tries to use the same descriptor.
+proc init_bash_xtrace {{fname xtrace.log}} {
+ global BASH_VERSINFO
+ if {([lindex $BASH_VERSINFO 0] == 4 && [lindex $BASH_VERSINFO 1] < 1) ||
+ [lindex $BASH_VERSINFO 0] < 4} {
+ note "BASH_XTRACEFD not available in this version; no xtrace.log"
+ return
+ }
+ verbose "Enabling bash xtrace output to '$fname'"
+ assert_bash_exec "exec 6>'$fname'"
+ assert_bash_exec "BASH_XTRACEFD=6"
+ assert_bash_exec "set -o xtrace"
+}
+
+
+# Setup test environment
+#
+# Common initialization for unit and completion tests.
+proc start_interactive_test {} {
+ start_bash
+ source_bash_completion
+ init_tcl_bash_globals
+
+ global OPT_BASH_XTRACE
+ if {[info exists OPT_BASH_XTRACE]} {
+ init_bash_xtrace
+ }
+ global OPT_TIMEOUT
+ if {[info exists OPT_TIMEOUT]} {
+ global timeout
+ verbose "Changing default expect timeout from $timeout to $OPT_TIMEOUT"
+ set timeout $OPT_TIMEOUT
+ }
+}
+
+
# Interrupt completion and sync with prompt.
# Send signals QUIT & INT.
#
diff --git a/test/lib/unit.exp b/test/lib/unit.exp
index c413c5ab..de870332 100644
--- a/test/lib/unit.exp
+++ b/test/lib/unit.exp
@@ -2,16 +2,14 @@ source lib/library.exp
proc unit_exit {} {
- # Exit bash
+ # Exit bash
send "\rexit\r"
-}; # unit_exit()
+}
proc unit_start {} {
- start_bash
- source_bash_completion
- init_tcl_bash_globals
-}; # unit_start()
+ start_interactive_test
+}
proc unit_version {} {
diff --git a/test/run b/test/run
index 408c33ac..cdb1145a 100755
--- a/test/run
+++ b/test/run
@@ -1,31 +1,60 @@
#!/bin/bash
-# Run test of specified tool.
-# The first directory of the first file (first argument ending with .exp) is
-# used as the `tool' specification.
-# Usage: ./run [FILE]...
-# Example run: ./run unit/_get_cword.exp unit/compgen.exp
-
-
-# Process arguments
-# @param $1 Name of variable to return `tool' name
-# @param $2 Name of variable to return processed arguments
-# @param $@ Arguments to process
-process_args() {
- local arg
- for arg in "${@:3}"; do
- case "$arg" in
- completion/*.exp|unit/*.exp)
- [[ ${!1} ]] || printf -v $1 "${arg%%/*}"
- eval $2[\${#$2[@]}]=\""${arg#*/}"\"
- ;;
- *)
- eval $2[\${#$2[@]}]=\""$arg"\"
- esac
- done
+
+
+# Print some helpful messages.
+usage() {
+ echo "Run bash-completion tests"
+ echo
+ echo "The 'tool' is determined automatically from filenames."
+ echo "Unrecognized options are passed through to dejagnu by default."
+ echo
+ echo "Interesting options:"
+ echo " --tool_exec= Test against a different bash executable."
+ echo " --debug Create a dbg.log in the test directory with detailed expect match information."
+ echo " --timeout Change expect timeout from the default of 10 seconds."
+ echo " --debug-xtrace Create an xtrace.log in the test directory with set -x output. Requires bash 4.1."
+ echo
+ echo "Example run: ./run unit/_get_cword.exp unit/compgen.exp"
+}
+
+
+# Try to set the tool variable; or fail if trying to set different values.
+set_tool() {
+ if [[ $tool ]]; then
+ if [[ $tool != $1 ]]; then
+ echo "Tool spec mismatch ('$tool' and '$1'). See --usage."
+ exit 1
+ fi
+ else
+ tool=$1
+ fi
}
+
+cd "${BASH_SOURCE[0]%/*}"
+
+
+# Loop over the arguments.
args=()
-process_args tool args "$@"
-runtest --outdir log --tool $tool "${args[@]}"
+while [[ $# > 0 ]]; do
+ case "$1" in
+ --help|--usage) usage; exit 1;;
+ --debug-xtrace) args+=(OPT_BASH_XTRACE=1);;
+ --timeout) shift; timeout=$1;;
+ --timeout=*) timeout=${1/--timeout=};;
+ --tool=*) set_tool "${1#/--tool=}";;
+ --tool) shift; set_tool "$1";;
+ */completion/*.exp|*/unit/*.exp)
+ arg=${1%/*}
+ set_tool "${arg##*/}"
+ args+=("${1##*/}")
+ ;;
+ *) args+=("$1")
+ esac
+ shift
+done
-unset -v args tool
+[[ -n $timeout ]] && args+=("OPT_TIMEOUT=$timeout")
+[[ -z $tool ]] && { echo "Must specify tool somehow"; exit 1; }
+
+runtest --outdir log --tool $tool "${args[@]}"
diff --git a/test/runCompletion b/test/runCompletion
index 862adeaa..10abc7d1 100755
--- a/test/runCompletion
+++ b/test/runCompletion
@@ -4,4 +4,4 @@
# isn't initialized at that point (i.e. output of `expect' is shown on
# stdout - `open_logs' hasn't run yet?). And running code from a library
# file isn't probably a good idea either.
-runtest --outdir log --tool completion $*
+"${BASH_SOURCE[0]%/*}/run" --tool completion $*
diff --git a/test/runUnit b/test/runUnit
index 14e0be12..d22a20d4 100755
--- a/test/runUnit
+++ b/test/runUnit
@@ -4,4 +4,4 @@
# isn't initialized at that point (i.e. output of `expect' is shown on
# stdout - `open_logs' hasn't run yet?). And running code from a library
# file isn't probably a good idea either.
-runtest --outdir log --tool unit $*
+"${BASH_SOURCE[0]%/*}/run" --tool unit $*