|
| 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