File: test_unit_abspath.py

package info (click to toggle)
bash-completion 1%3A2.16.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,424 kB
  • sloc: python: 11,241; makefile: 2,471; sh: 934; perl: 85; awk: 55; xml: 29; ansic: 7; java: 5; ruby: 2
file content (193 lines) | stat: -rw-r--r-- 5,355 bytes parent folder | download
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(
    cmd=None, cwd="shared", ignore_env=r"^\+declare -f __tester$"
)
class TestUnitAbsPath:
    @pytest.fixture
    def functions(self, bash):
        assert_bash_exec(
            bash,
            (
                "__tester() { "
                "local REPLY; "
                '_comp_abspath "$1"; '
                'printf %s "$REPLY"; '
                "}"
            ),
        )

    def test_non_pollution(self, bash):
        """Test environment non-pollution, detected at teardown."""
        assert_bash_exec(
            bash,
            "foo() { local REPLY=; _comp_abspath bar; }; foo; unset -f foo",
            want_output=None,
        )

    def test_absolute(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /foo/bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/foo/bar"

    def test_relative(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester foo/bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip().endswith("/shared/foo/bar")

    def test_cwd1(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester ./foo/./bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip().endswith("/shared/foo/bar")

    def test_cwd2(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /.",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/"

    def test_cwd3(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /foo/.",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/foo"

    def test_cwd4(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /././.",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/"

    def test_parent1(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester ../shared/foo/bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip().endswith(
            "/shared/foo/bar"
        ) and not output.strip().endswith("../shared/foo/bar")

    def test_parent2(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /foo/..",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/"

    def test_parent3(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /..",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/"

    def test_parent4(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /../foo/bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/foo/bar"

    def test_parent5(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /../../foo/bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/foo/bar"

    def test_parent6(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /foo/../bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/bar"

    def test_parent7(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /foo/../../bar",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/bar"

    def test_parent8(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /dir1/dir2/dir3/../dir4/../../foo",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/dir1/foo"

    def test_parent9(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester //dir1/dir2///../foo",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/dir1/foo"

    def test_parent10(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /dir1/dir2/dir3/..",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/dir1/dir2"

    def test_parent11(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /dir1/dir2/dir3/../..",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/dir1"

    def test_parent12(self, bash, functions):
        output = assert_bash_exec(
            bash,
            "__tester /dir1/dir2/dir3/../../../..",
            want_output=True,
            want_newline=False,
        )
        assert output.strip() == "/"