Skip to content

Commit ea1cfa1

Browse files
committed
_xinetd_services: look up from $BASHCOMP_XINETDDIR, add some unit tests
1 parent 014b3f2 commit ea1cfa1

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
11661166
#
11671167
_xinetd_services()
11681168
{
1169-
local xinetddir=/etc/xinetd.d
1169+
local xinetddir=${BASHCOMP_XINETDDIR:-/etc/xinetd.d}
11701170
if [[ -d $xinetddir ]]; then
11711171
local IFS=$' \t\n' reset=$(shopt -p nullglob); shopt -s nullglob
11721172
local -a svcs=( $(printf '%s\n' $xinetddir/!($_backup_glob)) )

test/t/unit/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ EXTRA_DIST = \
1313
test_unit_parse_usage.py \
1414
test_unit_quote.py \
1515
test_unit_tilde.py \
16-
test_unit_variables.py
16+
test_unit_variables.py \
17+
test_unit_xinetd_services.py
1718

1819
all:
1920

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec
4+
5+
6+
@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=")
7+
class TestUnitXinetdServices:
8+
def test_direct(self, bash):
9+
assert_bash_exec(bash, "_xinetd_services >/dev/null")
10+
11+
def test_env_non_pollution(self, bash):
12+
"""Test environment non-pollution, detected at teardown."""
13+
assert_bash_exec(bash, "foo() { _xinetd_services; }; foo; unset foo")
14+
15+
def test_basic(self, bash):
16+
output = assert_bash_exec(
17+
bash,
18+
"foo() { local BASHCOMP_XINETDDIR=$PWD/shared/bin;unset COMPREPLY; "
19+
'_xinetd_services; printf "%s\\n" "${COMPREPLY[@]}"; }; foo; unset foo',
20+
want_output=True,
21+
)
22+
assert sorted(output.split()) == ["arp", "ifconfig"]

0 commit comments

Comments
 (0)