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
|
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_cwd(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_parent(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")
|