Skip to content

Commit

Permalink
test/__expand_tilde_by_ref: port remaining test cases to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 10, 2020
1 parent 322420d commit d258b3c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 66 deletions.
40 changes: 39 additions & 1 deletion test/t/unit/test_unit_expand_tilde_by_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
@pytest.mark.bashcomp(cmd=None, ignore_env=r"^[+-]var=")
class TestUnitExpandTildeByRef:
@pytest.fixture(scope="class")
def user_home(self, bash):
user = assert_bash_exec(
bash, 'id -un 2>/dev/null || echo "$USER"', want_output=True
).strip()
home = assert_bash_exec(bash, 'echo "$HOME"', want_output=True).strip()
return (user, home)

def test_1(self, bash):
assert_bash_exec(bash, "__expand_tilde_by_ref >/dev/null")

Expand All @@ -14,3 +22,33 @@ def test_2(self, bash):
bash,
'_x() { local aa="~"; __expand_tilde_by_ref aa; }; _x; unset _x',
)

@pytest.mark.parametrize("plain_tilde", (True, False))
@pytest.mark.parametrize(
"suffix_expanded",
(
("", True),
("/foo", True),
(r"/\$HOME", True),
("/a b", True),
("/*", True),
(";echo hello", False),
("/a;echo hello", True),
),
)
def test_expand(self, bash, user_home, plain_tilde, suffix_expanded):
user, home = user_home
suffix, expanded = suffix_expanded
if plain_tilde:
user = ""
if not suffix or not expanded:
home = "~"
elif not expanded:
home = "~%s" % user
output = assert_bash_exec(
bash,
r'var="~%s%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"'
% (user, suffix),
want_output=True,
)
assert output.strip() == "%s%s" % (home, suffix.replace(r"\$", "$"),)
65 changes: 0 additions & 65 deletions test/unit/__expand_tilde_by_ref.exp

This file was deleted.

0 comments on commit d258b3c

Please sign in to comment.