From 4259efb5c4a9e6471db959ae5125ac5bf8358e07 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sat, 3 Oct 2009 08:34:14 +0200 Subject: [PATCH 1/8] (doc) Added sample cron.sh for test suite --- doc/testing.txt | 117 +++++++++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/doc/testing.txt b/doc/testing.txt index b54779a1..88afa1d5 100644 --- a/doc/testing.txt +++ b/doc/testing.txt @@ -82,18 +82,55 @@ The test suite requires a connected terminal (tty). When invoked via cron, no t can't read "multipass_name": no such variable --------------------------------------------- -To run the tests successfully via cron, connect a terminal by redirecting stdin from a tty, e.g. /dev/tty50: +To run the tests successfully via cron, connect a terminal by redirecting +stdin from a tty, e.g. /dev/tty40. (In Linux, you can press alt-Fx or +ctrl-alt-Fx to switch the console from /dev/tty1 to tty7. There are many more +/dev/tty* which are not accessed via function keys. To be safe, use a tty +greater than tty7) + ---------------------- -./runUnit < /dev/tty50 +./runUnit < /dev/tty40 ---------------------- -If the process doesn't run as root, root will have to change the owner and -permissions of the tty. +If the process doesn't run as root (recommended), root will have to change the +owner and permissions of the tty: +------------------------- +sudo chmod o+r /dev/tty40 +------------------------- -In Linux, you can press alt-Fx or ctrl-alt-Fx to switch the console from -/dev/tty1 to tty7. There are many more /dev/tty* which are not accessed via -function keys. To be safe, use a tty greater than tty7? +To start the test at 01:00, set the crontab to this: +* 1 * * * cd bash-completion/test && ./cron.sh < /dev/tty40 + +Here's an example batch file `cron.sh`, to be put in the bash-completion `test` +directory. This batch file only e-mails the output of each test-run if the +test-run fails. + +[source,bash] +--------------------------------------------------------------------- +#!/bin/sh + +set -e # Exit if simple command fails +set -u # Error if variable is undefined + +LOG=/tmp/bash-completion.log~ + + # Retrieve latest sources +git pull + + # Run tests on bash-3 + +./runUnit > $LOG || cat $LOG +./runCompletion > $LOG || cat $LOG + + # Run tests on bash-4 + +./runUnit --outdir log/bash-4 --tool_exec /opt/bash-4.0/bin/bash > $LOG || cat $LOG +./runCompletion --outdir log/bash-4 --tool_exec /opt/bash-4.0/bin/bash > $LOG || cat $LOG + + # Clean up log file +[ -f $LOG ] && rm $LOG +--------------------------------------------------------------------- Specifying bash binary ~~~~~~~~~~~~~~~~~~~~~~ @@ -124,12 +161,12 @@ Let's consider this real-life example where an ssh completion bug is fixed. Fir ---------------------------------- $ ./runCompletion ... - === completion Summary === + === completion Summary === -# of expected passes 283 -# of unexpected failures 8 -# of unresolved testcases 2 -# of unsupported tests 47 +# of expected passes 283 +# of unexpected failures 8 +# of unresolved testcases 2 +# of unsupported tests 47 ---------------------------------- Take a look in `log/completion.log` to find out which specific command is failing. @@ -151,10 +188,10 @@ In this case it appears `ssh.exp` is causing the problem. Isolate the `ssh` tes ---------------------------------- $ ./runCompletion ssh.exp --debug ... - === completion Summary === + === completion Summary === -# of expected passes 1 -# of unresolved testcases 1 +# of expected passes 1 +# of unresolved testcases 1 ---------------------------------- Now we can have a detailed look in `dbg.log` to find out what's going wrong. Open `dbg.log` and search for `UNRESOLVED` (or `FAIL` if that's what you're looking for): @@ -203,10 +240,10 @@ Running the test reveals we still have an unresolved test: ---------------------------------- $ ./runCompletion ssh.exp --debug ... - === completion Summary === + === completion Summary === -# of expected passes 1 -# of unresolved testcases 1 +# of expected passes 1 +# of unresolved testcases 1 ---------------------------------- But if now look into the log file `dbg.log` we can see the completion only returns commands starting with 'ls' but fails to match our regular expression which also expects the hostname `ls_known_host': @@ -229,9 +266,9 @@ until the test shows: ---------------------------------- $ ./runCompletion ssh.exp ... - === completion Summary === + === completion Summary === -# of expected passes 2 +# of expected passes 2 ---------------------------------- Fixing a unit test @@ -241,10 +278,10 @@ Now let's consider a unit test failure. First you're triggered by unsuccessful ---------------------------------- $ ./runUnit ... - === unit Summary === + === unit Summary === -# of expected passes 1 -# of unexpected failures 1 +# of expected passes 1 +# of unexpected failures 1 ---------------------------------- Take a look in `log/unit.log` to find out which specific command is failing. @@ -266,10 +303,10 @@ In this case it appears `_known_hosts_real.exp` is causing the problem. Isolate ---------------------------------- $ ./runUnit _known_hosts_real.exp --debug ... - === completion Summary === + === completion Summary === -# of expected passes 1 -# of unexpected failures 1 +# of expected passes 1 +# of unexpected failures 1 ---------------------------------- Now, if we haven't already figured out the problem, we can have a detailed look in `dbg.log` to find out what's going wrong. Open `dbg.log` and search for `UNRESOLVED` (or `FAIL` if that's what you're looking for): @@ -364,13 +401,13 @@ Setting up bash once within `completion_start()` has the speed advantage that ba .What happens when install tests are run? ---- - | runtest --tool install - V - +----+----+ - | DejaGnu | - +----+----+ - | - V + | runtest --tool install + V + +----+----+ + | DejaGnu | + +----+----+ + | + V +------------+---------------+ | (file: config/default.exp) | +------------+---------------+ @@ -385,13 +422,13 @@ Setting up bash once within `completion_start()` has the speed advantage that ba .What happens when unit tests are run? ---- - | runtest --tool unit - V - +----+----+ - | DejaGnu | - +----+----+ - | - V + | runtest --tool unit + V + +----+----+ + | DejaGnu | + +----+----+ + | + V +----------+-----------+ | - | | (file: lib/unit.exp) | From 9c53f0d6e6a481a615018ec11e5b5e99634d17f8 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sat, 3 Oct 2009 09:39:55 +0200 Subject: [PATCH 2/8] (testsuite) Added empty directories to git Empty directories are ignored by git. By putting an empty .gitignore in the directory, the directory can be added to git. --- test/fixtures/evince/foo/.gitignore | 0 test/fixtures/kdvi/foo/.gitignore | 0 test/fixtures/kpdf/foo/.gitignore | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/fixtures/evince/foo/.gitignore create mode 100644 test/fixtures/kdvi/foo/.gitignore create mode 100644 test/fixtures/kpdf/foo/.gitignore diff --git a/test/fixtures/evince/foo/.gitignore b/test/fixtures/evince/foo/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/kdvi/foo/.gitignore b/test/fixtures/kdvi/foo/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/kpdf/foo/.gitignore b/test/fixtures/kpdf/foo/.gitignore new file mode 100644 index 00000000..e69de29b From 18081e0d866819aab805ed55bd0c6605cb0d8ea7 Mon Sep 17 00:00:00 2001 From: David Paleino Date: Sat, 3 Oct 2009 15:42:46 +0200 Subject: [PATCH 3/8] Updating changelog timestamp, freezing for 1.1 --- CHANGES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 9ccf6359..1d7fbb15 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -bash-completion (1.x) +bash-completion (1.1) [ David Paleino ] * Permit .gz files concatenation (Debian: #514377) @@ -182,7 +182,7 @@ bash-completion (1.x) * Fix leaking $muttcmd from mutt completion * Fix completing multiple hosts (Debian: #535585) - -- David Paleino Thu, 18 Jun 2009 13:12:36 +0200 + -- David Paleino Sat, 03 Oct 2009 15:41:49 +0200 bash-completion (1.0) From d3187b6f351034f5317b78a9bab60dff7e707b17 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sat, 3 Oct 2009 23:23:48 +0200 Subject: [PATCH 4/8] Bugfix completing scp/sftp/ssh -F '' on bash-4 Use ${COMP_LINE:0:$COMP_POINT} instead of ${COMP_WORDS[@]} when searching for -F configfile in scp/sftp/ssh. This fixes a bug under bash-4 where completing: scp -F 'spaced conf' causes `dequote' to yield errors: bash: eval: line 1: unexpected EOF while looking for matching `'' bash: eval: line 2: syntax error: unexpected end of file The bug occurs because of a bug in bash-4.0, where quoted words are split unintended, see: http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html Also, using ${COMP_LINE:0:$COMP_POINT} is an improvement, because it takes the current cursor position into account. --- contrib/ssh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/ssh b/contrib/ssh index 2070c23e..4cb331b4 100644 --- a/contrib/ssh +++ b/contrib/ssh @@ -83,7 +83,7 @@ _ssh() -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${COMP_LINE:0:$COMP_POINT}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -138,7 +138,7 @@ _sftp() -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${COMP_LINE:0:$COMP_POINT}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -196,7 +196,7 @@ _scp() prefix=-F else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${COMP_LINE:0:$COMP_POINT}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then From 8455b7ef38b151ef081cad873171eb4ee1faa20f Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sat, 3 Oct 2009 23:27:40 +0200 Subject: [PATCH 5/8] Fix comment --- bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index eb6d15ed..3cacea74 100644 --- a/bash_completion +++ b/bash_completion @@ -367,7 +367,7 @@ __get_cword4() cur=${cur:$word_start} printf "%s" "$cur" -} # _get_cword4() +} # __get_cword4() # This function performs file and directory completion. It's better than From 5177db1a589983236558c37d7b411afe2c37c226 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sun, 4 Oct 2009 18:08:33 +0200 Subject: [PATCH 6/8] Revert commit d3187b6f3 Reverting yesterdays commit d3187b6f3 (Bugfix completing scp/sftp/ssh -F '' on bash-4), which said: set -- "${COMP_LINE:0:$COMP_POINT}" The problem with the line above is that it needs to be unquoted for `set' in order to break up COMP_LINE into separate arguments: set -- ${COMP_LINE:0:$COMP_POINT} But this will yield error "unexpected EOF while looking for matching `''" if COMP_LINE is containing unbalanced single/double quotes, e.g.: eval set -- scp -F 'config --- contrib/ssh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/ssh b/contrib/ssh index 4cb331b4..2070c23e 100644 --- a/contrib/ssh +++ b/contrib/ssh @@ -83,7 +83,7 @@ _ssh() -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_LINE:0:$COMP_POINT}" + set -- "${COMP_WORDS[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -138,7 +138,7 @@ _sftp() -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' argument - set -- "${COMP_LINE:0:$COMP_POINT}" + set -- "${COMP_WORDS[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -196,7 +196,7 @@ _scp() prefix=-F else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_LINE:0:$COMP_POINT}" + set -- "${COMP_WORDS[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then From 1be84710d2ac941ef9dee13f3dd9cd28ca6c5ba6 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sun, 4 Oct 2009 18:14:16 +0200 Subject: [PATCH 7/8] Silence completing scp/sftp/ssh -F '' on bash-4 This fixes a bug under bash-4 where completing: scp -F 'spaced conf' causes `dequote' to yield errors: bash: eval: line 1: unexpected EOF while looking for matching `'' bash: eval: line 2: syntax error: unexpected end of file The bug occurs because of a bug in bash-4.0, where quoted words are split unintended, see: http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html Workaround is now to silence `dequote' in case of errors and wait for bash-4 to be fixed... --- bash_completion | 2 +- test/lib/completions/scp.exp | 19 ++++++++++++++++++- test/lib/completions/sftp.exp | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bash_completion b/bash_completion index 3cacea74..41636faa 100644 --- a/bash_completion +++ b/bash_completion @@ -229,7 +229,7 @@ quote_readline() # This function shell-dequotes the argument dequote() { - eval echo "$1" + eval echo "$1" 2> /dev/null } # Get the word to complete. diff --git a/test/lib/completions/scp.exp b/test/lib/completions/scp.exp index d16741a2..5388383e 100644 --- a/test/lib/completions/scp.exp +++ b/test/lib/completions/scp.exp @@ -95,7 +95,24 @@ lappend expected doo: gee: hus: ike: jar: # Append local filenames lappend expected config known_hosts "spaced\\\\ \\\\ conf" set dir fixtures/scp -assert_complete_dir $expected "scp -F 'spaced conf' " $dir +#assert_complete_dir $expected "scp -F 'spaced conf' " $dir +set prompt "/$dir/@" +assert_bash_exec "cd $dir" "" $prompt +set cmd "scp -F 'spaced conf' " +send "$cmd\t" +expect -ex "$cmd\r\n" +if {[match_items $expected $test]} { + expect { + -re $prompt { pass "$test" } + -re eof { unresolved "eof" } + }; # expect +} else { + # Expected failure (known bug) because of bash-4 bug in quoted words: + # http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html + if {$bash_versinfo_0 >= 4} {xfail "$test"} {fail "$test"} +}; # if +sync_after_int $prompt +assert_bash_exec "cd \$TESTDIR" sync_after_int diff --git a/test/lib/completions/sftp.exp b/test/lib/completions/sftp.exp index 7cd89c0c..59faaabf 100644 --- a/test/lib/completions/sftp.exp +++ b/test/lib/completions/sftp.exp @@ -48,8 +48,8 @@ set expected [get_hosts] # Hosts `gee', `hus' and `jar' are defined in "./fixtures/scp/spaced conf" # Hosts `doo' and `ike' are defined in ./fixtures/scp/known_hosts lappend expected doo gee hus ike jar -set dir fixtures/scp -assert_complete_dir $expected "sftp -F 'spaced conf' " $dir +set dir fixtures/sftp +assert_complete_dir $expected "sftp -F spaced\\ \\ conf " $dir sync_after_int From bb47efd9b6d5717434d4d85c4a31bcd6787def97 Mon Sep 17 00:00:00 2001 From: Freddy Vulto Date: Sun, 4 Oct 2009 18:18:29 +0200 Subject: [PATCH 8/8] (testsuite) Allow trailing space on one completion Within `match_items', if only one completion is generated, an (optional) trailing space is allowed, because -o nospace might not be in effect. --- test/lib/library.exp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib/library.exp b/test/lib/library.exp index 4ca6b96c..05259d30 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -383,7 +383,8 @@ proc match_items {items test {size 20}} { }; # for if {[llength $items] == 1} { expect { - -re "^$expected$" { set result true } + # NOTE: The optional space ( ?) depends on whether -o nospace is active + -re "^$expected ?$" { set result true } "\r\n" { set result false; break } default { set result false; break } timeout { set result false; break }