Skip to content

Commit

Permalink
test: port compgen and quote tests to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed May 3, 2019
1 parent 32e8b93 commit 3752208
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 102 deletions.
1 change: 1 addition & 0 deletions test/t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ EXTRA_DIST = \
test_clone_member.py \
test_co.py \
test_compare.py \
test_compgen.py \
test_complete.py \
test_composite.py \
test_config_list.py \
Expand Down
4 changes: 2 additions & 2 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ def load_completion_for(bash: pexpect.spawn, cmd: str) -> bool:


def assert_bash_exec(
bash: pexpect.spawn, cmd: str, want_output: bool = False
bash: pexpect.spawn, cmd: str, want_output: bool = False, want_newline=True
) -> str:

# Send command
bash.sendline(cmd)
bash.expect_exact(cmd)

# Find prompt, output is before it
bash.expect_exact("\r\n" + PS1)
bash.expect_exact("%s%s" % ("\r\n" if want_newline else "", PS1))
output = bash.before

# Retrieve exit status
Expand Down
7 changes: 7 additions & 0 deletions test/t/test_compgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


class TestCompgen:
@pytest.mark.complete(r"compgen -f a\'b/", cwd="compgen")
def test_1(self, completion):
assert not completion
1 change: 1 addition & 0 deletions test/t/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ EXTRA_DIST = \
test_unit_longopt.py \
test_unit_parse_help.py \
test_unit_parse_usage.py \
test_unit_quote.py \
test_unit_tilde.py

all:
Expand Down
36 changes: 36 additions & 0 deletions test/t/unit/test_unit_quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from conftest import assert_bash_exec, TestUnitBase


@pytest.mark.bashcomp(cmd=None)
class TestUnitQuote(TestUnitBase):
def test_1(self, bash):
output = assert_bash_exec(
bash, 'quote "a b"', want_output=True, want_newline=False
)
assert output.strip() == "'a b'"

def test_2(self, bash):
output = assert_bash_exec(
bash, 'quote "a b"', want_output=True, want_newline=False
)
assert output.strip() == "'a b'"

def test_3(self, bash):
output = assert_bash_exec(
bash, 'quote " a "', want_output=True, want_newline=False
)
assert output.strip() == "' a '"

def test_4(self, bash):
output = assert_bash_exec(
bash, "quote \"a'b'c\"", want_output=True, want_newline=False
)
assert output.strip() == r"'a'\''b'\''c'"

def test_5(self, bash):
output = assert_bash_exec(
bash, 'quote "a\'"', want_output=True, want_newline=False
)
assert output.strip() == r"'a'\'''"
35 changes: 0 additions & 35 deletions test/unit/compgen.exp

This file was deleted.

65 changes: 0 additions & 65 deletions test/unit/quote.exp

This file was deleted.

0 comments on commit 3752208

Please sign in to comment.