From f9177e52863c400d1b860ecd39eb3cda066075d6 Mon Sep 17 00:00:00 2001 From: Crestez Dan Leonard Date: Sat, 20 Feb 2010 22:53:30 +0200 Subject: (testsuite) Add a --debug-xtrace option to run. Cleanup test/run scripts and add a --debug-xtrace option. --- CHANGES | 3 ++ test/.gitignore | 1 + test/lib/completion.exp | 9 ++---- test/lib/library.exp | 36 +++++++++++++++++++++++ test/lib/unit.exp | 10 +++---- test/run | 77 ++++++++++++++++++++++++++++++++----------------- test/runCompletion | 2 +- test/runUnit | 2 +- 8 files changed, 100 insertions(+), 40 deletions(-) diff --git a/CHANGES b/CHANGES index 1ce2fccd..74f359e7 100644 --- a/CHANGES +++ b/CHANGES @@ -72,6 +72,9 @@ 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. [ 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 4d23b183..c806d9c0 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -829,6 +829,42 @@ 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 + } +} + + # Interrupt completion and sync with prompt. # Send signals QUIT & INT. # @param string $prompt (optional) Bash prompt. Default is "/@" 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..1b2fd12a 100755 --- a/test/run +++ b/test/run @@ -1,31 +1,56 @@ #!/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 " --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);; + --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 +[[ -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 $* -- cgit v1.2.1