-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(_comp_abspath): add some unit tests
- Loading branch information
1 parent
6b75d64
commit 01e1ae5
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |