Skip to content

Commit

Permalink
test: add require_longopt xfail helper, use it
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 13, 2019
1 parent 503143b commit 6d79948
Show file tree
Hide file tree
Showing 42 changed files with 53 additions and 184 deletions.
15 changes: 12 additions & 3 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,18 @@ def completion(request, bash: pexpect.spawn) -> CompletionResult:
return CompletionResult("", [])
for pre_cmd in marker.kwargs.get("pre_cmds", []):
assert_bash_exec(bash, pre_cmd)
if marker.kwargs.get("require_cmd") and not is_bash_type(
bash, getattr(request.cls, "cmd", None)
):
cmd = getattr(request.cls, "cmd", None)
if marker.kwargs.get("require_longopt"):
# longopt completions require both command presence and that it
# responds something useful to --help
if "require_cmd" not in marker.kwargs:
marker.kwargs["require_cmd"] = True
if "xfail" not in marker.kwargs:
marker.kwargs["xfail"] = (
"! %s --help &>/dev/null || "
"! %s --help 2>&1 | command grep -qF -- --help"
) % ((cmd,) * 2)
if marker.kwargs.get("require_cmd") and not is_bash_type(bash, cmd):
pytest.skip("Command not found")
return assert_complete(bash, marker.args[0], **marker.kwargs)

Expand Down
2 changes: 1 addition & 1 deletion test/t/test_awk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestAwk:
def test_1(self, completion):
assert completion

@pytest.mark.complete("awk -", require_cmd=True)
@pytest.mark.complete("awk -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestBase64:
def test_1(self, completion):
assert completion

@pytest.mark.complete("base64 -", require_cmd=True)
@pytest.mark.complete("base64 -", require_longopt=True)
def test_options(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestBc:
@pytest.mark.complete(
"bc --",
require_cmd=True,
xfail=(
"! bc --help &>/dev/null || "
"! bc --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("bc --", require_longopt=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestCat:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cat -", require_cmd=True)
@pytest.mark.complete("cat -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def test_2(self, completion):
"""Should complete dirs only, also when invoked using full path."""
assert completion == ["bar bar.d/", "foo.d/"]

@pytest.mark.complete("chroot -", require_cmd=True)
@pytest.mark.complete("chroot -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestCp:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cp -", require_cmd=True)
@pytest.mark.complete("cp -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestCut:
def test_1(self, completion):
assert completion

@pytest.mark.complete("cut -", require_cmd=True)
@pytest.mark.complete("cut -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestDf:
def test_1(self, completion):
assert completion

@pytest.mark.complete("df -", require_cmd=True)
@pytest.mark.complete("df -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_du.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestDu:
def test_1(self, completion):
assert completion

@pytest.mark.complete("du -", require_cmd=True)
@pytest.mark.complete("du -", require_longopt=True)
def test_options(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestEnv:
@pytest.mark.complete(
"env --",
require_cmd=True,
xfail=(
"! env --help &>/dev/null || "
"! env --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("env --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestExpand:
@pytest.mark.complete(
"expand --",
require_cmd=True,
xfail=(
"! expand --help &>/dev/null || "
"! expand --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("expand --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_fold.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestFold:
@pytest.mark.complete(
"fold --",
require_cmd=True,
xfail=(
"! fold --help &>/dev/null || "
"! fold --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("fold --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@


class TestGrep:
@pytest.mark.complete(
"grep --",
require_cmd=True,
xfail=(
"! grep --help &>/dev/null || "
"! grep --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("grep --", require_longopt=True)
def test_1(self, completion):
assert completion

Expand Down
9 changes: 1 addition & 8 deletions test/t/test_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestHead:
@pytest.mark.complete(
"head --",
require_cmd=True,
xfail=(
"! head --help &>/dev/null || "
"! head --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("head --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_less.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestLess:
@pytest.mark.complete(
"less --",
require_cmd=True,
xfail=(
"! less --help &>/dev/null || "
"! less --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("less --", require_longopt=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_ln.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestLn:
def test_1(self, completion):
assert completion

@pytest.mark.complete("ln -", require_cmd=True)
@pytest.mark.complete("ln -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_md5sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestMd5sum:
def test_1(self, completion):
assert completion

@pytest.mark.complete("md5sum -", require_cmd=True)
@pytest.mark.complete("md5sum -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_mkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def test_3(self, completion):
assert completion.output == "foo"
assert completion == [completion.output]

@pytest.mark.complete("mkdir -", require_cmd=True)
@pytest.mark.complete("mkdir -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_mkfifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestMkfifo:
def test_1(self, completion):
assert completion

@pytest.mark.complete("mkfifo -", require_cmd=True)
@pytest.mark.complete("mkfifo -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_mknod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestMknod:
def test_1(self, completion):
assert completion

@pytest.mark.complete("mknod -", require_cmd=True)
@pytest.mark.complete("mknod -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestMv:
def test_1(self, completion):
assert completion

@pytest.mark.complete("mv -", require_cmd=True)
@pytest.mark.complete("mv -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_netstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestNetstat:
def test_1(self, completion):
assert completion

@pytest.mark.complete("netstat -", require_cmd=True)
@pytest.mark.complete("netstat -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestNl:
def test_1(self, completion):
assert completion

@pytest.mark.complete("nl -", require_cmd=True)
@pytest.mark.complete("nl -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestOd:
def test_1(self, completion):
assert completion

@pytest.mark.complete("od -", require_cmd=True)
@pytest.mark.complete("od -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestPaste:
def test_1(self, completion):
assert completion

@pytest.mark.complete("paste -", require_cmd=True)
@pytest.mark.complete("paste -", require_longopt=True)
def test_options(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestRm:
def test_1(self, completion):
assert completion

@pytest.mark.complete("rm -", require_cmd=True)
@pytest.mark.complete("rm -", require_longopt=True)
def test_options(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestSed:
@pytest.mark.complete(
"sed --",
require_cmd=True,
xfail=(
"! sed --help &>/dev/null || "
"! sed --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("sed --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestSeq:
@pytest.mark.complete(
"seq --",
require_cmd=True,
xfail=(
"! seq --help &>/dev/null || "
"! seq --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("seq --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_sha1sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestSha1sum:
@pytest.mark.complete(
"sha1sum --",
require_cmd=True,
xfail=(
"! sha1sum --help &>/dev/null || "
"! sha1sum --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("sha1sum --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestSort:
@pytest.mark.complete(
"sort --",
require_cmd=True,
xfail=(
"! sort --help &>/dev/null || "
"! sort --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("sort --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestSplit:
@pytest.mark.complete(
"split --",
require_cmd=True,
xfail=(
"! split --help &>/dev/null || "
"! split --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("split --", require_longopt=True)
def test_1(self, completion):
assert completion
2 changes: 1 addition & 1 deletion test/t/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class TestSum:
def test_1(self, completion):
assert completion

@pytest.mark.complete("sum -", require_cmd=True)
@pytest.mark.complete("sum -", require_longopt=True)
def test_options(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_tac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestTac:
@pytest.mark.complete(
"tac --",
require_cmd=True,
xfail=(
"! tac --help &>/dev/null || "
"! tac --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("tac --", require_longopt=True)
def test_1(self, completion):
assert completion
9 changes: 1 addition & 8 deletions test/t/test_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


class TestTail:
@pytest.mark.complete(
"tail --",
require_cmd=True,
xfail=(
"! tail --help &>/dev/null || "
"! tail --help 2>&1 | command grep -qF -- --help"
),
)
@pytest.mark.complete("tail --", require_longopt=True)
def test_1(self, completion):
assert completion
Loading

0 comments on commit 6d79948

Please sign in to comment.