Skip to content

Commit

Permalink
test: Convert some more test cases to pytest+pexpect
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 11, 2018
1 parent 416fc05 commit c85516b
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 161 deletions.
9 changes: 9 additions & 0 deletions test/t/unit/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
EXTRA_DIST = \
test_count_args.py \
test_expand.py \
test_expand_tilde_by_ref.py \
test_filedir.py \
test_get_comp_words_by_ref.py \
test_get_cword.py \
test_init_completion.py \
test_ip_addresses.py \
test_parse_help.py \
test_tilde.py \

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

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+args=")
class TestUnitCountArgs(object):

def test_1(self, bash):
assert_bash_exec(bash, "_count_args >/dev/null")
15 changes: 15 additions & 0 deletions test/t/unit/test_expand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
class TestUnitExpand(object):

def test_1(self, bash):
assert_bash_exec(bash, "_expand >/dev/null")

def test_2(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(
bash, 'foo() { _expand; }; foo; unset foo')
16 changes: 16 additions & 0 deletions test/t/unit/test_expand_tilde_by_ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
class TestUnitExpandTildeByRef(object):

def test_1(self, bash):
assert_bash_exec(bash, "__expand_tilde_by_ref >/dev/null")

def test_2(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(
bash,
'_x() { local aa="~"; __expand_tilde_by_ref aa; }; _x; unset _x')
10 changes: 10 additions & 0 deletions test/t/unit/test_filedir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=")
class TestUnitFiledir(object):

def test_1(self, bash):
assert_bash_exec(bash, "_filedir >/dev/null")
10 changes: 10 additions & 0 deletions test/t/unit/test_get_comp_words_by_ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+cur=")
class TestUnitGetCompWordsByRef(object):

def test_1(self, bash):
assert_bash_exec(bash, "_get_comp_words_by_ref cur >/dev/null")
10 changes: 10 additions & 0 deletions test/t/unit/test_get_cword.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
class TestUnitGetCword(object):

def test_1(self, bash):
assert_bash_exec(bash, "_get_cword >/dev/null")
13 changes: 13 additions & 0 deletions test/t/unit/test_init_completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=")
class TestUnitInitCompletion(object):

def test_1(self, bash):
"""Test environment non-pollution, detected at teardown."""
assert_bash_exec(
bash, 'foo() { local cur prev words cword; _init_completion; }; '
'foo; unset foo')
10 changes: 10 additions & 0 deletions test/t/unit/test_ip_addresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=")
class TestUnitIpAddresses(object):

def test_1(self, bash):
assert_bash_exec(bash, "_ip_addresses")
157 changes: 157 additions & 0 deletions test/t/unit/test_parse_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Based on work by Stephen Gildea, October 2010.

import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+declare -f fn$")
class TestUnitParseHelp(object):

def test_1(self, bash):
assert_bash_exec(bash, "fn() { echo; }")
output = assert_bash_exec(bash, "_parse_help fn")
assert not output

def test_2(self, bash):
assert_bash_exec(bash, "fn() { echo 'no dashes here'; }")
output = assert_bash_exec(bash, "_parse_help fn")
assert not output

def test_3(self, bash):
assert_bash_exec(bash, "fn() { echo 'internal-dash'; }")
output = assert_bash_exec(bash, "_parse_help fn")
assert not output

def test_4(self, bash):
assert_bash_exec(bash, "fn() { echo 'no -leading-dashes'; }")
output = assert_bash_exec(bash, "_parse_help fn")
assert not output

def test_5(self, bash):
assert_bash_exec(bash, "fn() { echo '-one dash'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "-one".split()

def test_6(self, bash):
assert_bash_exec(bash, "fn() { echo ' -space dash'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "-space".split()

def test_7(self, bash):
assert_bash_exec(bash, "fn() { echo '-one -two dashes'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "-one".split()

def test_8(self, bash):
assert_bash_exec(bash, "fn() { echo '-one,-t dashes'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "-one".split()

def test_9(self, bash):
assert_bash_exec(bash, "fn() { echo '-one dash-inside'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "-one".split()

def test_10(self, bash):
"""Test value not included in completion."""
assert_bash_exec(bash, "fn() { echo '--long-arg=value'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--long-arg=".split()

def test_11(self, bash):
"""Test -value not seen as option."""
assert_bash_exec(bash, "fn() { echo '--long-arg=-value'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--long-arg=".split()

def test_12(self, bash):
assert_bash_exec(bash, "fn() { echo '--long-arg=-value,--opt2=val'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--long-arg=".split()

def test_13(self, bash):
assert_bash_exec(bash, "fn() { echo '-m,--mirror'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--mirror".split()

def test_14(self, bash):
assert_bash_exec(bash, "fn() { echo '-T/--upload-file'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--upload-file".split()

def test_15(self, bash):
assert_bash_exec(bash, "fn() { echo '-T|--upload-file'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--upload-file".split()

def test_16(self, bash):
assert_bash_exec(bash, "fn() { echo '-f, -F, --foo'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo".split()

def test_17(self, bash):
assert_bash_exec(bash, "fn() { echo '--foo[=bar]'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo".split()

def test_18(self, bash):
assert_bash_exec(bash, "fn() { echo '--foo=<bar>'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo=".split()

def test_19(self, bash):
assert_bash_exec(bash, "fn() { echo '--foo={bar,quux}'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo=".split()

def test_20(self, bash):
assert_bash_exec(bash, "fn() { echo '--[no]foo'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo --nofoo".split()

def test_21(self, bash):
assert_bash_exec(bash, "fn() { echo '--[no-]bar[=quux]'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--bar --no-bar".split()

def test_22(self, bash):
assert_bash_exec(bash, "fn() { echo '--[no-]bar=quux'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--bar= --no-bar=".split()

def test_23(self, bash):
assert_bash_exec(bash, "fn() { echo '--[dont-]foo'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo --dont-foo".split()

def test_24(self, bash):
assert_bash_exec(bash, "fn() { echo '-[dont]x --[dont]yy'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--yy --dontyy".split()

def test_25(self, bash):
assert_bash_exec(bash, "fn() { echo '-f FOO, --foo=FOO'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo=".split()

def test_26(self, bash):
assert_bash_exec(bash, "fn() { echo '-f [FOO], --foo[=FOO]'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo".split()

def test_27(self, bash):
assert_bash_exec(bash, "fn() { echo '--foo.'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo".split()

def test_28(self, bash):
assert_bash_exec(bash, "fn() { echo '-f or --foo'; }")
output = assert_bash_exec(bash, "_parse_help fn", want_output=True)
assert output.split() == "--foo".split()

def test_29(self, bash):
"""Test parsing from stdin."""
output = assert_bash_exec(
bash, "echo '-f or --foo' | _parse_help -", want_output=True)
assert output.split() == "--foo".split()
9 changes: 0 additions & 9 deletions test/unit/__expand_tilde_by_ref.exp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ proc teardown {} {
setup home user


set test "function should run without errors"
assert_bash_exec {__expand_tilde_by_ref > /dev/null} $test
sync_after_int

set test "function should not pollute environment"
# NOTE: A possible environment pollution is detected by assert_env_modified() in teardown()
assert_bash_exec {foo() { local aa="~"; __expand_tilde_by_ref aa; }; foo; unset foo} $test
sync_after_int

set test "~user should return $home"
set cmd [format {var="~%s"; __expand_tilde_by_ref var; printf "%%s\n" "$var"} $user]
assert_bash_list "$home" $cmd $test
Expand Down
4 changes: 0 additions & 4 deletions test/unit/_count_args.exp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ proc teardown {} {
setup


set test "_count_args should run without errors"
assert_bash_exec {_count_args > /dev/null} $test
sync_after_int

set test "a b| should set args to 1"; # | = cursor position
set cmd {COMP_WORDS=(a b); COMP_CWORD=1; COMP_LINE='a b'; COMP_POINT=3; _count_args; echo $args}
assert_bash_list 1 $cmd $test
Expand Down
9 changes: 0 additions & 9 deletions test/unit/_expand.exp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ proc teardown {} {
setup home user


set test "function should run without errors"
assert_bash_exec {_expand > /dev/null} $test
sync_after_int

set test "function should not pollute environment"
# NOTE: A possible environment pollution is detected by assert_env_modified() in teardown()
assert_bash_exec {foo() { _expand; }; foo; unset foo} $test
sync_after_int

set test "~$user should set $home to COMPREPLY"
set cmd [format {cur="~%s" ; _expand ; printf "%%s\n" "$COMPREPLY"} $user]
assert_bash_list "$home" $cmd $test
Expand Down
4 changes: 0 additions & 4 deletions test/unit/_filedir.exp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ proc teardown {} {
setup


set test "_filedir should run without errors"
assert_bash_exec {_filedir > /dev/null} $test
sync_after_int

foreach name {f f2} {

set test "completing $name ab/ should return e"
Expand Down
4 changes: 0 additions & 4 deletions test/unit/_get_comp_words_by_ref.exp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ proc teardown {} {
setup


set test "_get_comp_words_by_ref should run without errors"
assert_bash_exec {_get_comp_words_by_ref cur > /dev/null} $test
sync_after_int

# See also ./lib/completions/alias.exp. Here `_get_cword' is actually tested
# by moving the cursor left into the current word.

Expand Down
4 changes: 0 additions & 4 deletions test/unit/_get_cword.exp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ proc teardown {} {
setup


set test "_get_cword should run without errors"
assert_bash_exec {_get_cword > /dev/null} $test
sync_after_int

# See also ./lib/completions/alias.exp. Here `_get_cword' is actually tested
# by moving the cursor left into the current word.

Expand Down
5 changes: 0 additions & 5 deletions test/unit/_init_completion.exp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ proc teardown {} {
setup


set test "function should not pollute environment"
# NOTE: A possible environment pollution is detected by assert_env_modified() in teardown()
assert_bash_exec {foo() { local cur prev words cword; _init_completion; }; foo; unset foo} $test
sync_after_int

set test "|a"; # | = cursor position
set cmd {COMP_WORDS=(a); COMP_CWORD=0; COMP_LINE='a'; COMP_POINT=0; _init_completion; echo "$cur $prev"}
assert_bash_list {" "} $cmd $test
Expand Down
4 changes: 0 additions & 4 deletions test/unit/_ip_addresses.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ setup
# TODO: add/robustify conditions on expected failures or unsupported setups
# ...so that there's no need for junk like CI/DIST special-casing

set test "_ip_addresses should run without errors"
assert_bash_exec {_ip_addresses} $test
sync_after_int

set test "_ip_addresses -a should complete ip addresses"
assert_complete_any "iaa "
sync_after_int
Expand Down
Loading

0 comments on commit c85516b

Please sign in to comment.