File: test_java.py

package info (click to toggle)
bash-completion 1%3A2.16.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,424 kB
  • sloc: python: 11,241; makefile: 2,471; sh: 934; perl: 85; awk: 55; xml: 29; ansic: 7; java: 5; ruby: 2
file content (100 lines) | stat: -rw-r--r-- 3,497 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pytest

from conftest import assert_bash_exec, bash_env_saved, is_bash_type


@pytest.mark.bashcomp(
    pre_cmds=("CLASSPATH=$PWD/java/a:$PWD/java/bashcomp.jar",)
)
class TestJava:
    @pytest.fixture(scope="class")
    def can_list_jar(self, bash):
        return (
            is_bash_type(bash, "zipinfo")
            or is_bash_type(bash, "unzip")
            or is_bash_type(bash, "jar")
        )

    @pytest.mark.complete("java -", require_cmd=True)
    def test_1(self, completion):
        assert completion

    @pytest.mark.complete("java ", cwd="java")
    def test_2(self, completion, can_list_jar):
        if can_list_jar:
            assert (
                completion
                == "JEP330.java a/ b bashcomp.jarred c. toplevel".split()
            )
        else:
            assert completion == "JEP330.java a/ b c.".split()

    @pytest.mark.complete("java -classpath bashcomp.jar ", cwd="java")
    def test_3(self, completion, can_list_jar):
        if can_list_jar:
            assert (
                completion == "JEP330.java a/ bashcomp.jarred toplevel".split()
            )
        else:
            assert completion == "JEP330.java a/".split()

    @pytest.mark.complete("java -cp bashcomp.jar:a/c ", cwd="java")
    def test_4(self, completion, can_list_jar):
        if can_list_jar:
            assert (
                completion
                == "JEP330.java a/ bashcomp.jarred d toplevel".split()
            )
        else:
            assert completion == "JEP330.java a/ d".split()

    @pytest.mark.complete("java -cp '' ", cwd="java")
    def test_5(self, completion):
        assert completion == "JEP330.java a/".split()

    @pytest.mark.complete("java -jar ", cwd="java")
    def test_6(self, completion):
        assert completion == "a/ bashcomp.jar bashcomp.war".split()

    @pytest.mark.complete("javadoc -sourcepath java/a:java/a/c ")
    def test_sourcepath_1(self, completion):
        """sourcepath should be split by `:`"""
        assert completion == "c"

    @pytest.mark.complete("javadoc -sourcepath java/?:java/x ")
    def test_sourcepath_2(self, completion):
        """pathname expansion should not happen after splitting the argument by
        `:`"""
        assert not completion

    @pytest.mark.complete("javadoc -sourcepath java/a ")
    def test_packages_1(self, completion):
        assert completion == "c"

    @pytest.mark.complete("javadoc -sourcepath java/a x")
    def test_packages_2(self, completion):
        assert not completion

    @pytest.mark.complete(
        "javadoc -sourcepath java/a x", shopt=dict(failglob=True)
    )
    def test_packages_3(self, completion):
        assert not completion

    @pytest.mark.complete("javadoc -sourcepath java/a ", env=dict(IFS="a"))
    def test_packages_4(self, completion):
        assert completion == "c"

    def test_packages_5(self, bash):
        """_comp_cmd_java__packages should not modify the outerscope `cur`"""
        with bash_env_saved(bash) as bash_env:
            bash_env.write_variable("cur", "a.b.c")
            assert_bash_exec(
                bash,
                "_comp_test_f() { local cword=3 words=(javadoc -sourcepath java/a a.b.c); COMPREPLY+=(); _comp_cmd_java__packages; }; _comp_test_f",
            )

    @pytest.mark.complete("javadoc -sourcepath java a.")
    def test_packages_6(self, completion):
        """A period in package names should not be converted to slash."""
        assert completion == "c"