summaryrefslogtreecommitdiffstats
path: root/test/t
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/t/conftest.py12
-rw-r--r--test/t/test_curl.py4
-rw-r--r--test/t/test_ip.py34
-rw-r--r--test/t/test_java.py2
-rw-r--r--test/t/test_perldoc.py6
-rw-r--r--test/t/unit/Makefile.am3
-rw-r--r--test/t/unit/test_unit_compgen.py5
-rw-r--r--test/t/unit/test_unit_compgen_available_interfaces.py25
-rw-r--r--test/t/unit/test_unit_load.py130
-rw-r--r--test/t/unit/test_unit_load_completion.py94
10 files changed, 211 insertions, 104 deletions
diff --git a/test/t/conftest.py b/test/t/conftest.py
index 874ef1c..cb279cc 100644
--- a/test/t/conftest.py
+++ b/test/t/conftest.py
@@ -601,9 +601,9 @@ class bash_env_saved:
def _unprotect_variable(self, varname: str):
if varname not in self.saved_variables:
- self.saved_variables[
- varname
- ] = bash_env_saved.saved_state.ChangesDetected
+ self.saved_variables[varname] = (
+ bash_env_saved.saved_state.ChangesDetected
+ )
self._copy_variable(
varname, "%s_OLDVAR_%s" % (self.prefix, varname)
)
@@ -695,9 +695,9 @@ class bash_env_saved:
def save_variable(self, varname: str):
self._unprotect_variable(varname)
- self.saved_variables[
- varname
- ] = bash_env_saved.saved_state.ChangesIgnored
+ self.saved_variables[varname] = (
+ bash_env_saved.saved_state.ChangesIgnored
+ )
# TODO: We may restore the "export" attribute as well though it is
# not currently tested in "diff_env"
diff --git a/test/t/test_curl.py b/test/t/test_curl.py
index 07050e9..2b86997 100644
--- a/test/t/test_curl.py
+++ b/test/t/test_curl.py
@@ -27,6 +27,10 @@ class TestCurl:
assert completion == "d/"
assert not completion.endswith(" ")
+ @pytest.mark.complete("curl --proto-default ", require_cmd=True)
+ def test_proto_default(self, completion):
+ assert completion
+
@pytest.mark.complete("curl --dont-fail-in-unset-mode")
def test_unknown_option(self, completion):
# Just see that it does not error out
diff --git a/test/t/test_ip.py b/test/t/test_ip.py
index 0be088c..552015d 100644
--- a/test/t/test_ip.py
+++ b/test/t/test_ip.py
@@ -15,6 +15,23 @@ class TestIp:
assert completion
@pytest.mark.complete(
+ "ip stats show group ",
+ require_cmd=True,
+ skipif="ip stats help 2>/dev/null; (( $? != 255 ))",
+ )
+ def test_stats(self, completion):
+ # "link" was one of the first groups added, should always be there
+ assert "link" in completion
+
+ @pytest.mark.complete(
+ "ip neigh show nud ",
+ require_cmd=True,
+ skipif="ip neigh help 2>&1 | grep 'STATE :=' > /dev/null; (( $? != 0 ))",
+ )
+ def test_neigh_state(self, completion):
+ assert "stale" in completion
+
+ @pytest.mark.complete(
"ip monitor ",
require_cmd=True,
skipif="ip monitor help 2>/dev/null; (( $? != 255 ))",
@@ -23,6 +40,23 @@ class TestIp:
assert "neigh" in completion
assert "all" in completion
+ @pytest.mark.complete("ip netconf ")
+ def test_netconf(self, completion):
+ assert "show" in completion
+
+ @pytest.mark.complete("ip link property add ")
+ def test_link_property(self, completion):
+ assert "altname" in completion
+ assert "dev" in completion
+
+ @pytest.mark.complete(
+ "ip addr show type ",
+ require_cmd=True,
+ skipif="ip link help 2>/dev/null; (( $? != 255 ))",
+ )
+ def test_addr_type(self, completion):
+ assert "bridge" in completion
+
@pytest.mark.complete("ip -", require_cmd=True)
def test_options(self, completion):
assert "-family" in completion
diff --git a/test/t/test_java.py b/test/t/test_java.py
index 03f1520..407438b 100644
--- a/test/t/test_java.py
+++ b/test/t/test_java.py
@@ -1,6 +1,6 @@
import pytest
-from conftest import is_bash_type, assert_bash_exec, bash_env_saved
+from conftest import assert_bash_exec, bash_env_saved, is_bash_type
@pytest.mark.bashcomp(
diff --git a/test/t/test_perldoc.py b/test/t/test_perldoc.py
index 282f824..a5b36d7 100644
--- a/test/t/test_perldoc.py
+++ b/test/t/test_perldoc.py
@@ -9,7 +9,11 @@ class TestPerldoc:
assert "fixtures/" not in completion # Our fixtures/ dir
assert not [x for x in completion if "File::File::" in x]
- @pytest.mark.complete("perldoc -", require_cmd=True)
+ @pytest.mark.complete(
+ "perldoc -",
+ require_cmd=True,
+ skipif="! perldoc -V &>/dev/null",
+ )
def test_2(self, completion):
assert completion
diff --git a/test/t/unit/Makefile.am b/test/t/unit/Makefile.am
index 54722de..5a1eb47 100644
--- a/test/t/unit/Makefile.am
+++ b/test/t/unit/Makefile.am
@@ -2,7 +2,9 @@ EXTRA_DIST = \
test_unit_abspath.py \
test_unit_command_offset.py \
test_unit_compgen.py \
+ test_unit_compgen_available_interfaces.py \
test_unit_compgen_commands.py \
+ test_unit_compgen_split.py \
test_unit_count_args.py \
test_unit_delimited.py \
test_unit_deprecate_func.py \
@@ -18,6 +20,7 @@ EXTRA_DIST = \
test_unit_initialize.py \
test_unit_ip_addresses.py \
test_unit_known_hosts.py \
+ test_unit_load.py \
test_unit_longopt.py \
test_unit_looks_like_path.py \
test_unit_parse_help.py \
diff --git a/test/t/unit/test_unit_compgen.py b/test/t/unit/test_unit_compgen.py
index cfdec8e..fb04d74 100644
--- a/test/t/unit/test_unit_compgen.py
+++ b/test/t/unit/test_unit_compgen.py
@@ -1,7 +1,8 @@
-import pytest
import re
-from conftest import assert_bash_exec, bash_env_saved, assert_complete
+import pytest
+
+from conftest import assert_bash_exec, assert_complete, bash_env_saved
@pytest.mark.bashcomp(cmd=None)
diff --git a/test/t/unit/test_unit_compgen_available_interfaces.py b/test/t/unit/test_unit_compgen_available_interfaces.py
new file mode 100644
index 0000000..5e93100
--- /dev/null
+++ b/test/t/unit/test_unit_compgen_available_interfaces.py
@@ -0,0 +1,25 @@
+import pytest
+
+from conftest import assert_bash_exec
+
+
+@pytest.mark.bashcomp(cmd=None)
+class TestUtilCompgenAvailableInterfaces:
+ @pytest.fixture
+ def functions(self, bash):
+ assert_bash_exec(
+ bash,
+ "_comp__test_dump() { ((${#arr[@]})) && printf '<%s>' \"${arr[@]}\"; echo; }",
+ )
+ assert_bash_exec(
+ bash,
+ '_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }',
+ )
+
+ def test_1_trailing_colons(self, bash, functions):
+ output = assert_bash_exec(
+ bash,
+ "_comp__test_compgen available_interfaces",
+ want_output=True,
+ )
+ assert ":" not in output.strip()
diff --git a/test/t/unit/test_unit_load.py b/test/t/unit/test_unit_load.py
new file mode 100644
index 0000000..3515703
--- /dev/null
+++ b/test/t/unit/test_unit_load.py
@@ -0,0 +1,130 @@
+import os
+
+import pytest
+
+from conftest import assert_bash_exec, bash_env_saved, prepare_fixture_dir
+
+
+@pytest.mark.bashcomp(cmd=None, cwd="_comp_load")
+class TestCompLoad:
+ @pytest.fixture
+ def fixture_dir(self, request, bash):
+ """Construct the fixture directory in a temporary directory.
+
+ Some of the tests use specific setups of symbolic links. However, if
+ we put the symbolic links in the static fixture directory, Automake
+ resolves them for tarballs. As a result, the tests fail when the files
+ are extracted from the tarballs. There does not seem to be any option
+ to change the behavior of Automake.
+
+ We instead manually set up all symbolic links needed for the tests
+ here. The other normal files and directories are statically included
+ in the repository as "/test/fixtures/_comp_load". We first copy the
+ statically included files and directories to a temporary directory and
+ set up symbolic links.
+ """
+
+ tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])
+ assert_bash_exec(bash, "cp -R %s/* %s/" % (os.getcwd(), tmpdir))
+ assert_bash_exec(bash, "mkdir -p %s/bin" % tmpdir)
+ assert_bash_exec(
+ bash, "ln -sf ../prefix1/bin/cmd1 %s/bin/cmd1" % tmpdir
+ )
+ assert_bash_exec(
+ bash, "ln -sf ../prefix1/sbin/cmd2 %s/bin/cmd2" % tmpdir
+ )
+ return str(tmpdir)
+
+ def test_userdir_1(self, bash, fixture_dir):
+ with bash_env_saved(bash) as bash_env:
+ bash_env.chdir(fixture_dir)
+ bash_env.write_variable(
+ "BASH_COMPLETION_USER_DIR",
+ "$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR",
+ quote=False,
+ )
+ bash_env.write_variable(
+ "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False
+ )
+ output = assert_bash_exec(
+ bash, "_comp_load cmd1", want_output=True
+ )
+ assert output.strip() == "cmd1: sourced from userdir1"
+ output = assert_bash_exec(
+ bash, "_comp_load cmd2", want_output=True
+ )
+ assert output.strip() == "cmd2: sourced from userdir2"
+
+ def test_PATH_1(self, bash, fixture_dir):
+ with bash_env_saved(bash) as bash_env:
+ bash_env.chdir(fixture_dir)
+ bash_env.write_variable(
+ "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False
+ )
+ output = assert_bash_exec(
+ bash, "_comp_load cmd1", want_output=True
+ )
+ assert output.strip() == "cmd1: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, "_comp_load cmd2", want_output=True
+ )
+ assert output.strip() == "cmd2: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, "complete -p cmd2", want_output=True
+ )
+ assert " cmd2" in output
+ output = assert_bash_exec(
+ bash, 'complete -p "$PWD/prefix1/sbin/cmd2"', want_output=True
+ )
+ assert "/prefix1/sbin/cmd2" in output
+
+ def test_cmd_path_1(self, bash, fixture_dir):
+ with bash_env_saved(bash) as bash_env:
+ bash_env.chdir(fixture_dir)
+ assert_bash_exec(bash, "complete -r cmd1 || :", want_output=None)
+ output = assert_bash_exec(
+ bash, "_comp_load prefix1/bin/cmd1", want_output=True
+ )
+ assert output.strip() == "cmd1: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, 'complete -p "$PWD/prefix1/bin/cmd1"', want_output=True
+ )
+ assert "/prefix1/bin/cmd1" in output
+ assert_bash_exec(bash, "! complete -p cmd1", want_output=None)
+ output = assert_bash_exec(
+ bash, "_comp_load prefix1/sbin/cmd2", want_output=True
+ )
+ assert output.strip() == "cmd2: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, "_comp_load bin/cmd1", want_output=True
+ )
+ assert output.strip() == "cmd1: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, "_comp_load bin/cmd2", want_output=True
+ )
+ assert output.strip() == "cmd2: sourced from prefix1"
+
+ def test_cmd_path_2(self, bash, fixture_dir):
+ with bash_env_saved(bash) as bash_env:
+ bash_env.chdir(fixture_dir)
+ bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False)
+ output = assert_bash_exec(
+ bash, "_comp_load cmd1", want_output=True
+ )
+ assert output.strip() == "cmd1: sourced from prefix1"
+ output = assert_bash_exec(
+ bash, "_comp_load cmd2", want_output=True
+ )
+ assert output.strip() == "cmd2: sourced from prefix1"
+
+ def test_cmd_intree_precedence(self, bash, fixture_dir):
+ """
+ Test in-tree, i.e. completions/$cmd relative to the main script
+ has precedence over location derived from PATH.
+ """
+ with bash_env_saved(bash) as bash_env:
+ bash_env.chdir(fixture_dir)
+ bash_env.write_variable("PATH", "$PWD/prefix1/bin", quote=False)
+ # The in-tree `sh` completion should be loaded here,
+ # and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.
+ assert_bash_exec(bash, "_comp_load sh", want_output=False)
diff --git a/test/t/unit/test_unit_load_completion.py b/test/t/unit/test_unit_load_completion.py
deleted file mode 100644
index 6272e5b..0000000
--- a/test/t/unit/test_unit_load_completion.py
+++ /dev/null
@@ -1,94 +0,0 @@
-import pytest
-
-from conftest import assert_bash_exec, bash_env_saved
-
-
-@pytest.mark.bashcomp(cmd=None, cwd="_comp_load")
-class TestLoadCompletion:
- def test_userdir_1(self, bash):
- with bash_env_saved(bash) as bash_env:
- bash_env.write_variable(
- "BASH_COMPLETION_USER_DIR",
- "$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR",
- quote=False,
- )
- bash_env.write_variable(
- "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False
- )
- output = assert_bash_exec(
- bash, "_comp_load cmd1", want_output=True
- )
- assert output.strip() == "cmd1: sourced from userdir1"
- output = assert_bash_exec(
- bash, "_comp_load cmd2", want_output=True
- )
- assert output.strip() == "cmd2: sourced from userdir2"
-
- def test_PATH_1(self, bash):
- with bash_env_saved(bash) as bash_env:
- bash_env.write_variable(
- "PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False
- )
- output = assert_bash_exec(
- bash, "_comp_load cmd1", want_output=True
- )
- assert output.strip() == "cmd1: sourced from prefix1"
- output = assert_bash_exec(
- bash, "_comp_load cmd2", want_output=True
- )
- assert output.strip() == "cmd2: sourced from prefix1"
- output = assert_bash_exec(
- bash, "complete -p cmd2", want_output=True
- )
- assert " cmd2" in output
- output = assert_bash_exec(
- bash, 'complete -p "$PWD/prefix1/sbin/cmd2"', want_output=True
- )
- assert "/prefix1/sbin/cmd2" in output
-
- def test_cmd_path_1(self, bash):
- assert_bash_exec(bash, "complete -r cmd1 || :", want_output=None)
- output = assert_bash_exec(
- bash, "_comp_load prefix1/bin/cmd1", want_output=True
- )
- assert output.strip() == "cmd1: sourced from prefix1"
- output = assert_bash_exec(
- bash, 'complete -p "$PWD/prefix1/bin/cmd1"', want_output=True
- )
- assert "/prefix1/bin/cmd1" in output
- assert_bash_exec(bash, "! complete -p cmd1", want_output=None)
- output = assert_bash_exec(
- bash, "_comp_load prefix1/sbin/cmd2", want_output=True
- )
- assert output.strip() == "cmd2: sourced from prefix1"
- output = assert_bash_exec(
- bash, "_comp_load bin/cmd1", want_output=True
- )
- assert output.strip() == "cmd1: sourced from prefix1"
- output = assert_bash_exec(
- bash, "_comp_load bin/cmd2", want_output=True
- )
- assert output.strip() == "cmd2: sourced from prefix1"
-
- def test_cmd_path_2(self, bash):
- with bash_env_saved(bash) as bash_env:
- bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False)
- output = assert_bash_exec(
- bash, "_comp_load cmd1", want_output=True
- )
- assert output.strip() == "cmd1: sourced from prefix1"
- output = assert_bash_exec(
- bash, "_comp_load cmd2", want_output=True
- )
- assert output.strip() == "cmd2: sourced from prefix1"
-
- def test_cmd_intree_precedence(self, bash):
- """
- Test in-tree, i.e. completions/$cmd relative to the main script
- has precedence over location derived from PATH.
- """
- with bash_env_saved(bash) as bash_env:
- bash_env.write_variable("PATH", "$PWD/prefix1/bin", quote=False)
- # The in-tree `sh` completion should be loaded here,
- # and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.
- assert_bash_exec(bash, "_comp_load sh", want_output=False)