summaryrefslogtreecommitdiff
path: root/test/lib/completions/chown.exp
blob: 480f6743d1838a255a2f8601803eb3c7976cd10a (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
proc setup {} {
    save_env
}; # setup()

proc teardown {} {
    assert_env_unmodified
}; # teardown()


setup


assert_complete_any "chown "
sync_after_int


# All the tests use the root:root user and group. They're assumed to exist.
set fulluser "root"
set fullgroup "root"

# Partial username is assumed to be unambiguous.
set partuser "roo"
set partgroup "roo"

# Skip tests if root:root not available or if roo:roo matches multiple
# users/groups
#
# compgen -A is used because it's a bash builtin and available everywhere.
# The || true part prevents exec from throwing an exception if nothing is
# found.
if {[exec bash -c "compgen -A user $partuser || true" | wc -l] > 1 ||
    [exec bash -c "compgen -A user $fulluser || true" | wc -l] != 1 ||
    [exec bash -c "compgen -A group $partgroup || true" | wc -l] > 1 ||
    [exec bash -c "compgen -A group $fullgroup || true" | wc -l] != 1} {
    untested "Not running complex chown tests."
} else {
    assert_complete $fulluser "chown $partuser"
    sync_after_int

    assert_complete $fulluser:$fullgroup "chown $fulluser:$partgroup"
    sync_after_int

    # One slash should work correctly (doubled here for tcl).
    assert_complete $fulluser\\:$fullgroup "chown $fulluser\\:$partgroup"
    sync_after_int

    foreach prefix {
        "funky\\ user:" "funky\\ user\\:" "funky.user:" "funky\\.user:" "fu\\ nky.user\\:"
        "f\\ o\\ o\\.\\bar:" "foo\\_b\\ a\\.r\\ :"
    } {
        set test "Check preserve special chars in $prefix$partgroup<TAB>"
        #assert_complete_into "chown $prefix$partgroup" "chown $prefix$fullgroup " $test
        assert_complete $prefix$fullgroup "chown $prefix$partgroup" $test
        sync_after_int
    }

    # Check that we give up in degenerate cases instead of spewing various junk.

    assert_no_complete "chown $fulluser\\\\:$partgroup"
    sync_after_int

    assert_no_complete "chown $fulluser\\\\\\:$partgroup"
    sync_after_int

    assert_no_complete "chown $fulluser\\\\\\\\:$partgroup"
    sync_after_int

    # Colons in user/groupnames are not usually allowed.
    assert_no_complete "chown foo:bar:$partgroup"
    sync_after_int
}


teardown