bash-completion/test/unit/_filedir.exp
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

251 lines
6.2 KiB
Plaintext

proc setup {} {
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _f}
save_env
# Declare bash completion function `_f'
assert_bash_exec { \
_f() { local cur=$(_get_cword); unset COMPREPLY; _filedir; }; \
complete -F _f f \
}
# Declare bash completion function `_f2' with `-o filenames' active.
assert_bash_exec { \
complete -F _f -o filenames f2 \
}
# Create directories `a*b' and `a\b' only when not running on Cygwin/Windows;
# directories containing `*' or `\' aren't allowed on Cygwin/Windows
if {! [is_cygwin]} {
# Create directory `a*b'
assert_bash_exec {(cd fixtures/_filedir && [ ! -d a\*b ] && mkdir a\*b && touch a\*b/j || true)}
# Create directory `a\b'
assert_bash_exec {(cd fixtures/_filedir && [ ! -d a\\b ] && mkdir a\\b && touch a\\b/g || true)}
}; # if
}; # setup()
proc teardown {} {
if {! [is_cygwin]} {
assert_bash_exec {(cd fixtures/_filedir && rm -- a\\b/g && rmdir a\\b/ || true)}
assert_bash_exec {(cd fixtures/_filedir && rm -- a\*b/j && rmdir a\*b/ || true)}
}; # if
assert_bash_exec {unset COMPREPLY cur}
assert_bash_exec {unset -f _f}
assert_bash_exec {complete -r f}
assert_env_unmodified { /OLDPWD/d }
}; # teardown()
setup
set test "_filedir should run without errors"
assert_bash_exec {_filedir > /dev/null} $test
sync_after_int
foreach name {f f2} {
set test "completing $name ab/ should return e"
set cmd "$name ab/"
assert_complete_dir e $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name a\\ b/ should return i"
set cmd "$name a\\ b/"
assert_complete_dir i $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name a\\\'b/ should return i"
set cmd "$name a\\\'b/"
assert_complete_dir c $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name a\\\"b/ should return i"; #"
set cmd "$name a\\\"b/"; #"
assert_complete_dir d $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name a\\\$b/ should return h"
set cmd "$name a\\\$b/"
assert_complete_dir "\b\b\b\b\b$::TESTDIR/fixtures/_filedir/a\\\\\$b/h" $cmd "fixtures/_filedir"
sync_after_int
# Execute these tests only when not running on Cygwin/Windows, because
# directories containing asterisk (*) or backslash (\) aren't allowed on
# Cygwin/Windows
if {! [is_cygwin]} {
set test "completing $name a\\\\b/ should return g"
set cmd "$name a\\\\b/"
assert_complete_dir g $cmd "fixtures/_filedir"
sync_after_int
}; # if
set test "completing $name a\\&b/ should return f"
set cmd "$name a\\&b/"
assert_complete_dir f $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name a\$ should return a\\\$b/"
set cmd "$name a\$"
assert_complete_dir "\b\\\\\$b/" $cmd "fixtures/_filedir"
sync_after_int
# NOTE: Bash versions 4.0.0 up to 4.0.34 contain a bug when completing quoted
# words, so tests within this if aren't executed for these bash versions.
if {! (
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
)} {
set test "completing $name 'ab/ should return e"
set cmd "$name 'ab/"
assert_complete_dir {e'} $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name 'a b/ should return i"
set cmd "$name 'a b/"
assert_complete_dir {i'} $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name 'a\"b/ should return d"; #"
set cmd "$name 'a\"b/"; #"
assert_complete_dir {d'} $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name 'a\$b/ should return h"
set cmd "$name 'a\$b/"
if {[lindex $::BASH_VERSINFO 0] == 4} {
assert_complete_dir {h'} $cmd "fixtures/_filedir"
} else {
assert_complete_dir "\b\b\b\b$::TESTDIR/fixtures/_filedir/a\$b/h'" $cmd "fixtures/_filedir"
}; # if
sync_after_int
# Execute these tests only when not running on Cygwin/Windows, because
# directories containing `*' or `\' aren't allowed on Cygwin/Windows
if {! [is_cygwin]} {
set test "completing $name 'a\\b/ should return g"
set cmd "$name 'a\\b/"
assert_complete_dir {g'} $cmd "fixtures/_filedir"
sync_after_int
}; # if
set test "completing $name 'a&b/ should return f"
set cmd "$name 'a&b/"
assert_complete_dir {f'} $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name \"ab/ should return e"; #"
set cmd "$name \"ab/"; #"
assert_complete_dir {e"} $cmd "fixtures/_filedir"; #"
sync_after_int
set test "completing $name \"a b/ should return i"; #"
set cmd "$name \"a b/"; #"
assert_complete_dir {i"} $cmd "fixtures/_filedir"; #"
sync_after_int
set test "completing $name \"a'b/ should return c"; #"
set cmd "$name \"a'b/"; #"
assert_complete_dir {c"} $cmd "fixtures/_filedir"; #"
sync_after_int
set test "completing $name \"a\\\"b/ should return d"; #"
set cmd "$name \"a\\\"b/"; #"
assert_complete_dir {d"} $cmd "fixtures/_filedir"; #"
sync_after_int
set test "completing $name \"a\\\$b/ should return h"; #"
set cmd "$name \"a\\\$b/"; #"
assert_complete_dir "\b\b\b\b\b$::TESTDIR/fixtures/_filedir/a\\\\\$b/h\\\"" $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name \"a\\b/ should return e"; #"
set cmd "$name \"a\\b/"; #"
assert_complete_dir "\b\b\bb/e\\\"" $cmd "fixtures/_filedir"
sync_after_int
set test "completing $name \"a\\\\b/ should return g"; #"
set cmd "$name \"a\\\\b/"; #"
assert_complete_dir {g"} $cmd "fixtures/_filedir"; #"
sync_after_int
set test "completing $name \"a&b/ should return f"; #"
set cmd "$name \"a&b/"; #"
assert_complete_dir {f"} $cmd "fixtures/_filedir"; #"
sync_after_int
}; # if
}; # for
teardown