Skip to content

Commit 9e82abf

Browse files
committed
test(_realcommand): add some test cases
1 parent 1d2aac1 commit 9e82abf

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/t/unit/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EXTRA_DIST = \
2222
test_unit_pnames.py \
2323
test_unit_quote.py \
2424
test_unit_quote_compgen.py \
25+
test_unit_realcommand.py \
2526
test_unit_split.py \
2627
test_unit_tilde.py \
2728
test_unit_unlocal.py \
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec, bash_env_saved
4+
5+
6+
@pytest.mark.bashcomp(cmd=None, cwd="shared", ignore_env=r"^\+COMPREPLY=")
7+
class TestUnitRealCommand:
8+
def test_non_pollution(self, bash):
9+
"""Test environment non-pollution, detected at teardown."""
10+
assert_bash_exec(
11+
bash,
12+
"foo() { local cur=; _realcommand bar; }; foo; unset -f foo",
13+
want_output=None,
14+
)
15+
16+
def test_basename(self, bash):
17+
with bash_env_saved(bash) as bash_env:
18+
bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False)
19+
output = assert_bash_exec(
20+
bash,
21+
"_realcommand arp",
22+
want_output=True,
23+
)
24+
assert output.strip().endswith("/shared/bin/arp")
25+
26+
def test_basename_nonexistent(self, bash):
27+
filename = "non-existent-file-for-bash-completion-tests"
28+
skipif = "! type -P %s" % filename
29+
try:
30+
assert_bash_exec(bash, skipif, want_output=None)
31+
except AssertionError:
32+
pytest.skipif(skipif)
33+
output = assert_bash_exec(
34+
bash,
35+
"! _realcommand %s" % filename,
36+
want_output=False,
37+
)
38+
assert output.strip() == ""
39+
40+
def test_relative(self, bash):
41+
output = assert_bash_exec(
42+
bash,
43+
"_realcommand bin/arp",
44+
want_output=True,
45+
)
46+
assert output.strip().endswith("/shared/bin/arp")
47+
48+
def test_relative_nonexistent(self, bash):
49+
output = assert_bash_exec(
50+
bash,
51+
"! _realcommand bin/non-existent",
52+
want_output=False,
53+
)
54+
assert output.strip() == ""
55+
56+
def test_absolute(self, bash):
57+
output = assert_bash_exec(
58+
bash,
59+
'_realcommand "$PWD/bin/arp"',
60+
want_output=True,
61+
)
62+
assert output.strip().endswith("/shared/bin/arp")
63+
64+
def test_absolute_nonexistent(self, bash):
65+
output = assert_bash_exec(
66+
bash,
67+
'! _realcommand "$PWD/bin/non-existent"',
68+
want_output=False,
69+
)
70+
assert output.strip() == ""

0 commit comments

Comments
 (0)