64 Commits

Author SHA1 Message Date
Ville Skyttä
6589a0d61b Drop support for bash < 4.1, clean up no longer needed low hanging cruft. 2011-04-21 12:20:59 +03:00
Freddy Vulto
68e9a8e6eb (testsuite) Add -unsorted option to _get_hosts()
_known_hosts_real tests were failing after commit 81794a9:

   FAIL: Hosts should be put in COMPREPLY
   FAIL: Hosts should have username prefix and colon suffix

This is because tcl's get_hosts() is now doing a unique sort, but bash
_known_hosts_real() IS returning duplicates relying on bash's compgen/complete
to remove the duplicates).  Fixed by calling _get_hosts -unsorted.
2011-03-27 23:12:14 +02:00
Freddy Vulto
7cd17ada11 Fix __reassemble_comp_words_by_ref() unquoted pattern removal
Commit 8227e76 was failing on these `chown' tests in bash-4.1:

    FAIL: Check preserve special chars in funky\ user:Debia<TAB>
    FAIL: Check preserve special chars in funky\.user:Debia<TAB>
    FAIL: Check preserve special chars in fu\ nky.user:Debia<TAB>
    FAIL: Check preserve special chars in f\ o\ o\.\bar:Debia<TAB>
    FAIL: Check preserve special chars in foo\_b\ a\.r\ :Debia<TAB>

because a removal pattern is expanded:

    $ a=\\b
    $ w=\\
    $ echo ${a#$w}    # Doesn't work
    \b
    $ echo ${a#"$w"}  # Ok
    b
2011-03-27 22:08:55 +02:00
Freddy Vulto
8227e76e09 Improve __reassemble_comp_words_by_ref() (Alioth #313057)
Prohibit word creation of characters if they're excluded from
$COMP_WORDBREAKS.  For example, with ':' included in $COMP_WORDBREAKS,
'a b:' should split to 'b' and ':'.  With ':' excluded from
$COMP_WORDBREAKS, 'a b:' should split to 'b:', NOT 'b' and ':'.
2011-03-24 00:00:58 +01:00
Freddy Vulto
11da957e45 (testsuite) `match_items()' matches on bash-prompt
Also made `match_items()' more strict about matching
space/newline/prompt after the last item.

Added options to match_items():
- end-newline
- end-prompt
- end-space
and transferred them to other functions.

Function `assert_complete()' now has a `-nospace' option to explicitly
disallow a space after a completion...

Function `assert_bash_list()' now expects a single item to be followed
by a newline.
2010-11-17 23:36:58 +01:00
Freddy Vulto
bc0bf2815c (testsuite) Uncomment testcases 2010-11-16 23:21:05 +01:00
Freddy Vulto
69f9c7c77e (testsuite) Fix _count_args tests to output newline
assert_bash_list() expects a newline terminated list

Plus small fixes to assert_bash_list_dir()
2010-11-16 23:06:13 +01:00
Freddy Vulto
c86b336769 (testuite) Fix tests to run with autotools' make distcheck
File locations are prefixed with `$::srcdir' so that `make distcheck' can
execute the test suite using a relative path.

The current working directory is removed from the test-suite-bash-prompt.

Furthermore, no more dynamic creation of files in dir $::srcdir/fixtures since
this dir is read-only during `make distcheck'.  Instead create dynamic files in
$TESTDIR/tmp

The test suite uses these "directory" variables

   tcl            bash          description
   ------------   -----------   ------------------------------------
   $::srcdir      $SRCDIR       where `fixtures' reside, relative
   $::srcdirabs   $SRCDIRABS    where `fixtures' reside, absolute
   $::TESTDIR     $TESTDIR      where `runtest' is invoked, absolute
2010-11-12 23:35:36 +01:00
Freddy Vulto
83bcd69557 (testsuite) Fix _parse_help for LANG=POSIX
Steps to reproduce the problem:

    $ LANG=POSIX ./run unit/_parse_help.exp
    ...
    Running ./unit/_parse_help.exp ...
    FAIL: short + long
    FAIL: short + long, slash separated

Cause:
When comparing list items, `assert_bash_list()' expects the real list to be
sorted, whereas the output of `_parse_help' is unsorted.
These particular two tests were failing because they suffered the
following LANG-dependant sort-difference:

    $ cat t.txt
    -m
    --n
    $ LANG=en_US.UTF-8 sort t.txt
    -m
    --n
    $ LANG=POSIX sort t.txt
    --n
    -m

Solution:
Made to default for `assert_bash_list' more-intuitive: unsorted, and added an
option `-sort' to explicitly enable sorting.

I felt uncomfortable adding yet another optional argument, so I seized this
opportunity to move subsequent optional arguments to single optional arguments.
E.g.:

    assert_bash_list {expected cmd {test ""} {prompt /@} {size 20}} {

has now become:

    # ...
    # @param list $args  Options:
    #     -nosort         Compare list unsorted.  Default is sorted
    #     -prompt         Bash prompt.  Default is `/@'
    #     -chunk-size N   Compare list N items at a time.  Default
    #                     is 20.
    assert_bash_list {expected cmd test {args {}}

(and the `test' argument has become mandatory).
2010-10-31 17:51:14 +01:00
Freddy Vulto
50dd6c7ac6 (testsuite) Test for expect-5.44 to prevent segfault
Modified test title
2010-10-31 07:53:15 +01:00
Freddy Vulto
20f7d5c1d2 (testsuite) Improve _filedir unicode test (Alioth #312477) 2010-10-26 22:41:01 +02:00
Freddy Vulto
37f51b9df2 (testsuite) Removed changing locale within 'expect'
Changing the locale within an `expect' session might cause bash to exit.
See: http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg02265.html
2010-10-18 22:29:59 +02:00
Ville Skyttä
96c6416309 Make _parse_help() work with slash separated options. 2010-10-11 00:39:50 +03:00
Ville Skyttä
95399f638c Fix false posives for non-option words in _parse_help (Alioth: #312750, Stephen Gildea). 2010-10-11 00:01:51 +03:00
Freddy Vulto
dff4241998 (testsuite) Fix _filedir test for "compgen -f" hack
One test was failing on bash-3
2010-10-09 22:12:51 +02:00
Freddy Vulto
e8d84b3004 Bugfix __reassemble_comp_words_by_ref
a b:c |<TAB> (with |=cursor) did not return `b:c' as `prev' on bash-4.1
(Alioth #312740)
2010-10-05 21:39:58 +02:00
Ville Skyttä
1da64f602a More known hosts IPv6 completion fixes, thanks to Yoshinori KUNIGA.
https://bugzilla.redhat.com/show_bug.cgi?id=630658#c4
2010-10-04 21:31:03 +03:00
Ville Skyttä
9341a1131c Fix known hosts completion for IPv6 addresses whose last 16 bits are digits (Alioth: #312695, RedHat: #630658). 2010-09-28 18:24:35 +03:00
Ville Skyttä
7f5c64e580 (testsuite) Add some [host]:port cases to known hosts related tests. 2010-09-28 17:59:31 +03:00
Ville Skyttä
c183a585b2 Match uppercased versions of _filedir and _filedir_xspec arguments too.
This provides a bit of case insensivity to file extension matching,
allowing for example _filedir foo to match both *.foo and *.FOO.  Note
that this is not real case insensivity; mixed case extensions like
*.FOO.gz are not matched by _filedir foo.gz so those need to be
handled like before this change.
2010-09-19 12:12:06 +03:00
Freddy Vulto
ccbf141e13 Fix tilde (~) completion with _filedir
This fixes tilde completion when doing for instance `ls ~<TAB>'.  See
also: Alioth #312613.

Added _tilde() helper function.

Contrary to _expand() and __expand_tilde_by_ref(), _tilde() also leaves the
tilde (~) intact.  Replacement of the tilde has been a complaint in other
bugreports, especially since plain bash completion (without bash-completion
installed) doesn't expand the tilde when doing a `ls ~<TAB>'.

To run the tests:

    ./run completion/ls.exp
    ./run unit/_tilde.exp
2010-06-30 23:28:31 +02:00
Freddy Vulto
51b3e20ebc (testsuite) Drop ending block comments
Instead of writing `}; # if', write just `}' as was discussed here:

    http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01815.html
2010-06-18 17:21:38 +02:00
Freddy Vulto
94372b2aa6 Merge branch 'use-_get_comp_words_by_ref' 2010-06-10 23:51:30 +02:00
Freddy Vulto
a8dd58cfa9 Added _upvars' and _upvar'.
These helper methods aid in passing variables by reference.
2010-06-09 22:37:02 +02:00
Freddy Vulto
3d4941fa96 (testsuite) Add test case for _filedir with directory containing multibyte character.
See also: http://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01942.html
2010-04-10 12:13:33 +02:00
Freddy Vulto
bdca37a7bf Improve _get_comp_words_by_ref to return words' and cword'
Usage: _get_comp_words_by_ref [OPTIONS] [VARNAMES]
Available VARNAMES:
    cur         Return cur within varname "cur"
    prev        Return prev within varname "prev"
    words       Return words within varname "words"
    cword       Return cword within varname "cword"

Available OPTIONS:
    -n EXCLUDE  Characters out of $COMP_WORDBREAKS which should NOT be
                considered word breaks. This is useful for things like scp
                where we want to return host:path and not only path, so we
                would pass the colon (:) as -n option in this case.  Bash-3
                doesn't do word splitting, so this ensures we get the same
                word on both bash-3 and bash-4.
    -c VARNAME  Return cur within specified VARNAME
    -p VARNAME  Return prev within specified VARNAME
    -w VARNAME  Return words within specified VARNAME
    -i VARNAME  Return words within specified VARNAME

Example usage:

   $ _get_comp_words_by_ref -n : cur prev
2010-03-14 11:07:13 +01:00
Freddy Vulto
caaf58859a Undo commit 00560a88 ("_filedir: bash > 4 has the same behaviour
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"
2010-03-12 13:41:53 +01:00
Crestez Dan Leonard
ebdd9cefdc Merge branch 'space-fix': Fix tests when BASH_COMPLETION or TESTDIR contain
spaces.

Conflicts:
	CHANGES
2010-02-09 15:45:40 +02:00
Freddy Vulto
2cd91420d2 Merge branch 'fvu' 2010-02-07 15:21:44 +01:00
Freddy Vulto
b529cee550 Added _get_comp_words_by_ref()
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.
2010-02-07 15:18:58 +01:00
Crestez Dan Leonard
2ad9001556 Add a find_unique_completion_pair proc.
Given a list of items this proc finds a (part, full) pair so that when
completing from $part $full will be the only option.
2010-02-03 14:08:55 +02:00
Crestez Dan Leonard
c3bb4416d7 Fixed tests when BASH_COMPLETION or TESTDIR contain spaces. 2010-02-02 11:16:29 +02:00
Ville Skyttä
77dee3a323 (testsuite) FreeBSD and Solaris sed compatibility fixes.
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.
2010-01-03 23:49:19 +02:00
Freddy Vulto
3f0bfbc5ae Fix __reassemble_comp_words_by_ref()
Completing "a b " returned cur=b instead of cur=nothing if a wordbreak
character was specified.
2009-12-31 11:12:15 +01:00
Freddy Vulto
f321c377af (testsuite) Delete directory fixtures/_filedir/a\b
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)
2009-12-30 14:48:17 +01:00
Freddy Vulto
3251038c9d Fix __reassemble_comp_words_by_ref()
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
2009-12-30 09:43:16 +01:00
Freddy Vulto
c9c98da36e Fixed `quote_readline'.
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().
2009-12-24 10:00:29 +01:00
Freddy Vulto
359d242a49 (testsuite) Unset COMP_ variables at setup()
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
    ...
2009-12-12 12:36:38 +01:00
Freddy Vulto
736fa43e9f (testsuite) Fix comment 2009-12-12 12:08:07 +01:00
Ville Skyttä
b8ffa2dc48 Add some unit tests for _count_args. 2009-12-11 00:14:02 +02:00
Freddy Vulto
b1e58b1a0e Fix __reassemble_comp_words_by_ref()
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
2009-12-10 21:28:24 +01:00
Freddy Vulto
08c5878483 Merged __get_cword3 & __get_cword4 to _get_cword
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.
2009-12-06 23:16:31 +01:00
Freddy Vulto
8a70568066 (testsuite) Centralized test start functions
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'.
2009-12-05 14:53:47 +01:00
Freddy Vulto
eb860b7b9f Added helper function __expand_tilde_by_ref()
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.
2009-12-02 22:38:30 +01:00
Freddy Vulto
a07b5c5ffd Fix expanding quoted tilde in _known_hosts_real.
- Added unit test "Files starting with tilde (~) should work" to
  unit/_known_hosts_real.exp
2009-11-29 14:42:42 +01:00
Freddy Vulto
0209fbde2c (testsuite) Detailed _known_hosts_real test for consecutive spaces 2009-11-28 17:35:01 +01:00
Freddy Vulto
a55d311ae2 (testsuite) Moved unsetting COMPREPLY 2009-10-31 08:32:58 +01:00
Freddy Vulto
9eb0ee2851 (test suite) Added global var `bash_versinfo_0'
This variable was introduced by unit/_get_cword.exp but is now upgraded
to a global var.
2009-10-02 16:39:11 +02:00
Freddy Vulto
b66425e8cf (testsuite) Remove test with non-portable filenames
Files containing a star (*) aren't support on FAT, thus Cygwin.
Closes Alioth #311979.
2009-09-25 20:28:00 +02:00
Freddy Vulto
f733e71e1f Split _get_cword into bash-3/4 versions
- 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>]
2009-09-20 14:11:26 +02:00