Skip to content

Commit

Permalink
test(_comp_abspath): add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored and akinomyoga committed Apr 17, 2023
1 parent 6b75d64 commit 01e1ae5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/t/unit/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXTRA_DIST = \
test_unit_abspath.py \
test_unit_command_offset.py \
test_unit_count_args.py \
test_unit_deprecate_func.py \
Expand Down
67 changes: 67 additions & 0 deletions test/t/unit/test_unit_abspath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 ret; "
'_comp_abspath "$1"; '
'printf %s "$ret"; '
"}"
),
)

def test_non_pollution(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(
bash,
"foo() { local ret=; _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")

0 comments on commit 01e1ae5

Please sign in to comment.