Skip to content

Commit 01e1ae5

Browse files
scopakinomyoga
authored andcommitted
test(_comp_abspath): add some unit tests
1 parent 6b75d64 commit 01e1ae5

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

test/t/unit/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
EXTRA_DIST = \
2+
test_unit_abspath.py \
23
test_unit_command_offset.py \
34
test_unit_count_args.py \
45
test_unit_deprecate_func.py \

test/t/unit/test_unit_abspath.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec
4+
5+
6+
@pytest.mark.bashcomp(
7+
cmd=None, cwd="shared", ignore_env=r"^\+declare -f __tester$"
8+
)
9+
class TestUnitAbsPath:
10+
@pytest.fixture
11+
def functions(self, bash):
12+
assert_bash_exec(
13+
bash,
14+
(
15+
"__tester() { "
16+
"local ret; "
17+
'_comp_abspath "$1"; '
18+
'printf %s "$ret"; '
19+
"}"
20+
),
21+
)
22+
23+
def test_non_pollution(self, bash):
24+
"""Test environment non-pollution, detected at teardown."""
25+
assert_bash_exec(
26+
bash,
27+
"foo() { local ret=; _comp_abspath bar; }; foo; unset -f foo",
28+
want_output=None,
29+
)
30+
31+
def test_absolute(self, bash, functions):
32+
output = assert_bash_exec(
33+
bash,
34+
"__tester /foo/bar",
35+
want_output=True,
36+
want_newline=False,
37+
)
38+
assert output.strip() == "/foo/bar"
39+
40+
def test_relative(self, bash, functions):
41+
output = assert_bash_exec(
42+
bash,
43+
"__tester foo/bar",
44+
want_output=True,
45+
want_newline=False,
46+
)
47+
assert output.strip().endswith("/shared/foo/bar")
48+
49+
def test_cwd(self, bash, functions):
50+
output = assert_bash_exec(
51+
bash,
52+
"__tester ./foo/./bar",
53+
want_output=True,
54+
want_newline=False,
55+
)
56+
assert output.strip().endswith("/shared/foo/bar")
57+
58+
def test_parent(self, bash, functions):
59+
output = assert_bash_exec(
60+
bash,
61+
"__tester ../shared/foo/bar",
62+
want_output=True,
63+
want_newline=False,
64+
)
65+
assert output.strip().endswith(
66+
"/shared/foo/bar"
67+
) and not output.strip().endswith("../shared/foo/bar")

0 commit comments

Comments
 (0)