summaryrefslogtreecommitdiff
path: root/test/lib/completions/tar.exp
blob: 75434e948c22958f1c6675611adc175c6c167882 (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
125
126
127
128
129
130
131
132
proc setup {} {
    save_env
}

proc teardown {} {
    assert_env_unmodified {
        /OLDPWD=/d
        /declare -f _tar/d
    }
}

setup

# Detect whether system's tar is GNU tar
set cmd "tar --version"
send "$cmd\r"
expect "^$cmd\r\n"
expect {
    -re "GNU\[^\n\]*\n" {
        set tar_version gnu
    }
    -re ".*\n" {
        set tar_version unknown
    }
}
sync_after_int


set test "old option: list escaped chars"
assert_complete_dir "a/b\\'c/" "tar tf escape.tar a/b\\\'" $::srcdir/fixtures/tar $test
sync_after_int

# TODO: "tar tf escape.tar a/b"

set test "check that any completion done"
assert_complete_any "tar "
sync_after_int

# Use bsdtar as the it completes to only 'zc zt zx' ('tar' can be GNU tar and it
# can would have more options)
set test "old option: mode is not on first place"
assert_complete {zc zt zx} "bsdtar z" $test
sync_after_int

set test "old option: test 'f' when mode is not as a first option"
assert_complete_dir "dir/ dir2/" "tar zfc " $::srcdir/fixtures/tar
sync_after_int

set test "old option: creating archive and 'f' option"
assert_complete_dir "dir/ dir2/" "tar cf " $::srcdir/fixtures/tar
sync_after_int

set test "old option: archive listing"
assert_complete_dir "dir/fileA dir/fileB dir/fileC" "tar tf archive.tar.xz dir/file" $::srcdir/fixtures/tar
sync_after_int

set test "old option: check _second_ option in \"old\" argument"
assert_complete_dir "dir/ dir2/" "bsdtar cbfvv NOT_EXISTS " $::srcdir/fixtures/tar
sync_after_int

set test "old option: create and members"
assert_complete_dir "dir/ dir2/ archive.tar.xz escape.tar" "tar cTfvv NOT_EXISTS DONT_CREATE.tar " $::srcdir/fixtures/tar
sync_after_int

set test "old option: extract and archive"
assert_complete_dir "dir/ dir2/ archive.tar.xz escape.tar" "tar xvf " $::srcdir/fixtures/tar
sync_after_int

if { "$tar_version" == "gnu" } {
    set test "check short options"
    assert_complete_any "tar -c"
    sync_after_int

    set test "mode not as a first option"
    assert_complete_dir "dir/ dir2/" "tar -zcf " $::srcdir/fixtures/tar
    sync_after_int

    # Only directories should be completed.
    set test "check that we do not suggest re-writing existing archive"
    assert_complete_dir "dir/ dir2/" "tar -cf " $::srcdir/fixtures/tar
    sync_after_int

    set test "check --file option"
    assert_complete_dir "dir/ dir2/" "tar -c --file " $::srcdir/fixtures/tar
    sync_after_int

    set test "check --file option #2"
    assert_complete_dir "dir/ dir2/" "tar -cvv --file " $::srcdir/fixtures/tar
    sync_after_int

    set test "archive listing"
    assert_complete_dir "dir/fileA dir/fileB dir/fileC" "tar -tf archive.tar.xz dir/file" $::srcdir/fixtures/tar
    sync_after_int

    set test "archive listing with --file"
    assert_complete_dir "dir/fileA dir/fileB dir/fileC" "tar -t --file archive.tar.xz dir/file" $::srcdir/fixtures/tar
    sync_after_int

    # Some random options should work:
    set test "test random tar's long option #1"
    assert_complete "--blocking-factor= --block-number" "tar --block" $test
    sync_after_int

    set test "test random tar's long option #2"
    assert_complete "--add-file=" "tar --add-fil" $test -nospace
    sync_after_int

    set test "test random tar's long option #3"
    assert_complete "--posix" "tar -cf /dev/null --posi" $test
    sync_after_int

    # --owner
    set users [exec bash -c "compgen -A user"]
    set test "test --owner option"
    assert_complete $users "tar --owner=" $test
    sync_after_int

    # --group
    set groups [exec bash -c "compgen -A group"]
    set test "test --group option"
    assert_complete $groups "tar --group=" $test
    sync_after_int

    # use -b for this as -b is still not handled by tar's completion
    set test "short opt -XXXb <TAB> (arg required)"
    assert_no_complete "tar -cvvfb " $test
    sync_after_int

    # TODO: how to test that 'tar -cf<TAB>' completes to 'tar -cf '
}

teardown