regardless of $cur beginning with ' or not"), because this is failing
tests:
FAIL: completing f a\'b/ should return i
FAIL: completing f a\"b/ should return i
FAIL: f a\$b/ should show completions
FAIL: f a\\b/ should show completions
FAIL: completing f2 a\'b/ should return i
FAIL: completing f2 a\"b/ should return i
FAIL: f2 a\$b/ should show completions
FAIL: f2 a\\b/ should show completions
- Fix _filedir to check for availability of COMP_WORDS (_filedir runs from
within a completion instead of the command line) when doing a `complete -p
${COMP_WORDS[0]'
- Fix _filedir usage comment
- Enhanced _filedir tests
- Added _filedir test "completing with filter '.e1' should show completions"
This solves the following problems:
- now one function call suffices instead of two (_get_cword; _get_pword) if
subsequent words need to be retrieved. Also more than two words can be
retrieved at once, e.g.: _get_comp_words_by_ref cur prev prev2 prev3
Also this prevents passing of `wordbreakchars' to differ in calls to
`_get_cword' and `_get_pword', e.g.: _get_comp_words_by_ref -n : cur prev
- passing by reference, no subshell call necessary anymore
- _get_pword now also takes into account the cursor position
Added testsuite proc `assert_no_output()'
Word of caution:
The passing-arguments-by-ref system in bash doesn't work if the new variable is
also declared local. For example:
t() {
local a
# ...
eval $1=b
}
a=c; t a; echo $a # Outputs "c", should be "b"
# Variable "a" is 'forbidden'
To make name collissions like this less likely to happen, but make the real
function still use readable variables, I've wrapped the `*_by_ref'
functions within an additional layer using variables prefixed with double
underscores (__). For example:
_t() {
# Readable variables can still be used here
local a
# ...
eval $1=b
}
t() {
local __a
_t __a
eval $1=\$__a
}
a=c; t a; echo $a # Outputs "b"
# Variable "__a" is 'forbidden'
Now only more obfuscated variables (starting with double prefix (__)) are
forbidden to use.
The linefeed between the final "d" and "}" seems to be significant for
these versions of sed. And they are quite anal about comments, so
move them outside of the sed statement here.
Directories `a\b' and `a*b' are now created run-time on a
non-Cygwin/Windows system only. Tests concerning these directories will
also be run only on a non-Cygwin/Windows system.
(Alioth #312191)
On bash-3, completing a b c: with COMP_WORDBREAKS -= : would result in the
current word being bc: (Alioth #312190)
Added unit test, run via:
./run unit/_get_cword.exp
This fixes completing filenames containing single quote (') on bash-4.
Also added emulation of `-o filenames' to _filedir.
Added tests for _filedir.
Fixed array assignment within __reassemble_comp_words_by_ref().
The COMP_ settings of the last test of _count_args() were falling through to
the first test of _get_cword(), causing it to fail.
Unset COMP_ variables within the unit tests setup & teardown.
Fixed last test at `_count_args.exp' by solving conflicting settings of
COMP_CWORD and COMP_POINT.
Steps to reproduce the problem:
$ ./runUnit _count_args.exp _get_cword.exp
...
Running ./unit/_count_args.exp ...
Running ./unit/_get_cword.exp ...
ERROR Unexpected output from bash command "_get_cword should run without errors":
bash: $index: substring expression < 0
...
If a word is made up of multiple word separator characters:
$ a b::<TAB> # CWORDS are: a, b, and :: (correct)
__reassemble_comp_words_by_ref() couldn't handle this. It assumed CWORDS were:
$ a b::<TAB> # CWORDS: a, b, : and : (but they're not)
Added test case for this. To run the automated tests:
./runUnit _get_cword.exp
Actually enhanced __get_cword3 to _get_cword, and removed __get_cword4.
__get_cword4 could handle chars to exclude from COMP_WORDBREAKS, but
failed with partial quoted arguments (e.g. "a 'b c|", | = cursor
position). This was no problem till bash-4.0.35, because bash < 4.0.35
also returned partial quoted arguments incorrectly. See also:
http://www.mail-archive.com/bug-bash@gnu.org/msg06094.html
Now that bash-4.0.35 returns quoted arguments ok, __get_cword3 is
enhanced to also handle chars to exclude from COMP_WORDBREAKS. Because
__get_cword3 also handles partial quoted arguments correctly, this makes
__get_cword3 suitable for bash-4 as well.
Code in `unit_start()' and `completion_start()' is merged and put central in
lib/library.exp:
- start_bash()
- source_bash_completion()
- init_tcl_bash_globals()
Global string variable `bash_versinfo_0' is replaced with list variable
`BASH_VERSINFO'.
Expands only tilde (~), if first char, in variable.
This function displays bash's capabilities of passing a variable by
reference (variable indirection) which allows us to avoid using a
subshell. As far as I can see it works surprisingly well?
To run the automated test:
./runUnit __expand_tilde_by_ref.exp
Also fixed some testsuite issues regarding list splitting.
- Added code comments to _get_cword, __get_cword3 & __get_cword4
- (testsuite) Added tests for _get_cword
- (testsuite) Bugfixes assert_bash_exec() && match_items()
Bash-4 splits COMP_WORDS using characters from COMP_WORDBREAKS, but has
a bug where quoted words are also splitted, see:
http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html
__get_cword3 is used for bash-2/3 and __get_cword4 is used for bash-4.
__get_cword4 handles well temporarily disabling of COMP_WORDBREAK
characters, but fails quoted words (a 'b c) and subshells (a $(b c).
See the expected failures when running the automated tests.
__get_cword3 does a better job of returning quoted words.
To run the automated tests on bash-3/4:
$ ./runUnit _get_cword.exp [--tool_exec <path to bash-3/4 binary>]
These are the tests (| = cursor position):
1. a b| should return b
2. a | should return nothing
3. a b|c should return b
4. a b\ c| should return b\ c
5. a 'b c| should return 'b c
6. a "b c| should return "b c
7. a b:c| should return c
8. a b:c| with WORDBREAKS -= : should return b:c
9. a -n| should return -n
Tests 5 & 6 yield "expected failures", see bugreport:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474094 . At a first glance
this bugreport contains useful ideas, so anyone willing to try to make tests 5 &
6 pass, be sure to have a look there first.
To run the automated tests:
$ cd test && ./runUnit _get_cword.exp
See also bugreport Alioth #311614.
Added tests for the awk script processing IP numbers. To run the tests:
cd test
./runUnit _known_hosts_real.exp
./runCompletion ssh.exp scp.exp sftp.exp
Quote sed output ("\1") retrieving "GlobalKnownHostsFile/UserKnownHostsFile" to
prevent bash globbing of special characters, e.g. '*'.
Added unit test "Config file containing star (*) should work".
Added test library function `assert_bash_list()'.
To run unit tests:
cd test && ./runUnit _known_hosts_real.exp
`_known_hosts_real' will add hosts from HOSTFILE (compgen -A hostname), unless
`COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
To run the unit tests:
$ cd test && ./runUnit _known_hosts_real.exp
Fixed `_known_hosts_real' to allow for multiple patterns in ssh config, e.g.:
Host foo.example.net bar.example.net
IFS was set to just newline (\n), whereas `compgen -W' relies on IFS
being space-tab-newline ( \t\n) to expand hostnames which are separated
by whitespace.
Tests are updated as well (added host `jar' to config). To run the tests:
./runUnit _known_hosts_real.exp