summaryrefslogtreecommitdiff
path: root/test/unit/_filedir.exp
blob: 1de49504966f5ca359033ea12272e897f18be62a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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', `a*b', and `a\b' only when not running on
    # Cygwin/Windows (`"', `*', or `\' aren't allowed in filenames there)
    if {! [is_cygwin]} {
        # Create directory `a"b'
        assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\"b ] && mkdir a\"b && touch a\"b/d || true)}
        # Create directory `a*b'
        assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\*b ] && mkdir a\*b && touch a\*b/j || true)}
        # Create directory `a\b'
        assert_bash_exec {(cd $TESTDIR/tmp && [ ! -d a\\b ] && mkdir a\\b && touch a\\b/g || true)}
    }
}


proc teardown {} {
    if {! [is_cygwin]} {
        assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\"b/d && rmdir a\"b/ || true)}
        assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\\b/g && rmdir a\\b/ || true)}
        assert_bash_exec {(cd $TESTDIR/tmp && rm -- a\*b/j && rmdir a\*b/ || true)}
    }
    assert_bash_exec {unset COMPREPLY cur}
    assert_bash_exec {unset -f _f}
    assert_bash_exec {complete -r f}
    assert_env_unmodified {
        /OLDPWD/d
        /OLD_CTYPE/d
    }
}


setup


foreach name {f f2} {

    set test "completing $name a\\\$b/ should return h"
    if {[info exists ::env(CI)] && [info exists ::env(DIST)] && $::env(DIST) == "centos6"} {
        xfail $test
    } else {
        set cmd "$name a\\\$b/"
        assert_complete_dir h $cmd "$::srcdir/fixtures/_filedir" $test
        sync_after_int
    }

    if {! [is_cygwin]} {  # Illegal characters in file/dir names
        set test "completing $name a\\\"b/ should return d"; #"
        set cmd "$name a\\\"b/"; #"
        assert_complete_dir d $cmd "$TESTDIR/tmp" $test
        sync_after_int

        set test "completing $name a\\\\b/ should return g"
        set cmd "$name a\\\\b/"
        assert_complete_dir g $cmd "$TESTDIR/tmp" $test
        sync_after_int
    }

    if {! [is_cygwin]} {  # Illegal characters in file/dir names
        set cmd "$name 'a\"b/"; #"
        assert_complete_dir {d'} $cmd "$TESTDIR/tmp"
        sync_after_int

        set cmd "$name '$TESTDIR/tmp/a\\b/"
        assert_complete_dir {g'} $cmd "$TESTDIR/tmp"
        sync_after_int
    }

    if {! [is_cygwin]} {  # Illegal characters in file/dir names
        set cmd "$name \"a\\\"b/"; #"
        assert_complete_dir {d"} $cmd "$TESTDIR/tmp"; #"
        sync_after_int
    }

    if {[info exists ::env(CI)] && [info exists ::env(DIST)] && $::env(DIST) == "centos6"} {
        xfail "$name \"a\\\$b/ should show completions"
    } else {
        set cmd "$name \"a\\\$b/"; #"
        assert_complete_dir {h"} $cmd "$::srcdir/fixtures/_filedir"; #"
        sync_after_int
    }

    set cmd "$name \"a\\b/"; #"
    assert_complete_dir "\b\b\bb/e\\\"" $cmd "$::srcdir/fixtures/_filedir"
    sync_after_int

    set cmd "$name \"a\\\\b/"; #"
    assert_complete_dir {g"} $cmd "$TESTDIR/tmp"; #"
    sync_after_int

    set cmd "$name \\\[x"
    assert_complete_dir {\[x\]} $cmd "$::srcdir/fixtures/_filedir/brackets"
    sync_after_int

}; # foreach

set test "completing f aé should return g"
# Execute this test only with LC_CTYPE matching *UTF-8*
# See also: http://www.mail-archive.com/bash-completion-devel\
#           @lists.alioth.debian.org/msg02265.html
# Don't execute this test on expect-5.44 cause it will segfault
# See also: Alioth #312792
if {
    [string first "UTF-8" $::LC_CTYPE] != -1 &&
    [string first 5.44 [exp_version]] != 0
} {
    assert_complete_dir g "f aé/" "$::srcdir/fixtures/_filedir"
} else {
    unsupported "$test"
}
sync_after_int


teardown