bash-completion
bash-completion copied to clipboard
Supports JEP 330 in 'java' autocompletion
JEP 330 allows execution of single-file source code with "java" command as follows:
$ java HelloWorld.java
This commit updates the bash autocompletion to suggest *.java files in addition to precompiled classes.
Thank you for your review! I was able to repro the test failures.
With the new completion rule looking for individual ".java" files, all the directories are now included in the completion results. I'm puzzled for the right fix. Should I include all the sub-directories in the test? That would make these tests fragile.
Example pytest output (with --vv):
________________________________________________________________________________________ TestJava.test_2 _________________________________________________________________________________________
self = <test_java.TestJava object at 0x7df18f94eac8>
completion = <CompletionResult ['7z/', '_filedir/', '_get_cword/', '_known_hosts_real/', '_longopt/', 'acroread/', 'ant/', 'apt-mar...sha256sum/', 'shared/', 'shells/', 'slackware/', 'ssh/', 'ssh-copy-id/', 'tar/', 'toplevel', 'tox/', 'xrandr/', 'xz/']>
can_list_jar = True
@pytest.mark.complete("java ")
def test_2(self, completion, can_list_jar):
if can_list_jar:
> assert completion == "b bashcomp.jarred c. toplevel".split()
E AssertionError: assert <CompletionResult ['7z/', '_filedir/', '_get_cword/', '_known_hosts_real/', '_longopt/', 'acroread/', 'ant/', 'apt-mark/', 'b', 'bashcomp.jarred', 'bsdtar/', 'c.', 'compgen/', 'cvs/', 'dnssec-keygen/', 'dpkg/', 'gdb/', 'htpasswd/', 'info/', 'isql/', 'java/', 'lftp/', 'lilo/', 'make/', 'man/', 'mount/', 'mplayer/', 'mutt/', 'nmap/', 'perl/', 'perldoc/', 'pkgtools/', 'pytest/', 'ri/', 'scp/', 'sftp/', 'sha256sum/', 'shared/', 'shells/', 'slackware/', 'ssh/', 'ssh-copy-id/', 'tar/', 'toplevel', 'tox/', 'xrandr/', 'xz/']> == ['b', 'bashcomp.jarred', 'c.', 'toplevel']
E +<CompletionResult ['7z/', '_filedir/', '_get_cword/', '_known_hosts_real/', '_longopt/', 'acroread/', 'ant/', 'apt-mark/', 'b', 'bashcomp.jarred', 'bsdtar/', 'c.', 'compgen/', 'cvs/', 'dnssec-keygen/', 'dpkg/', 'gdb/', 'htpasswd/', 'info/', 'isql/', 'java/', 'lftp/', 'lilo/', 'make/', 'man/', 'mount/', 'mplayer/', 'mutt/', 'nmap/', 'perl/', 'perldoc/', 'pkgtools/', 'pytest/', 'ri/', 'scp/', 'sftp/', 'sha256sum/', 'shared/', 'shells/', 'slackware/', 'ssh/', 'ssh-copy-id/', 'tar/', 'toplevel', 'tox/', 'xrandr/', 'xz/']>
E -['b', 'bashcomp.jarred', 'c.', 'toplevel']
E Full diff:
E - ['b', 'bashcomp.jarred', 'c.', 'toplevel']
E + <CompletionResult ['7z/', '_filedir/', '_get_cword/', '_known_hosts_real/', '_longopt/', 'acroread/', 'ant/', 'apt-mark/', 'b', 'bashcomp.jarred', 'bsdtar/', 'c.', 'compgen/', 'cvs/', 'dnssec-keygen/', 'dpkg/', 'gdb/', 'htpasswd/', 'info/', 'isql/', 'java/', 'lftp/', 'lilo/', 'make/', 'man/', 'mount/', 'mplayer/', 'mutt/', 'nmap/', 'perl/', 'perldoc/', 'pkgtools/', 'pytest/', 'ri/', 'scp/', 'sftp/', 'sha256sum/', 'shared/', 'shells/', 'slackware/', 'ssh/', 'ssh-copy-id/', 'tar/', 'toplevel', 'tox/', 'xrandr/', 'xz/']>
/home/frank/git/bash-completion/bash-completion/test/t/test_java.py:25: AssertionError
I think one good way would be to modify the tests affected like this so that they are run in the fixtures/java
dir instead of in fixtures
. The cwd
option to pytest.mark.complete
can be used to accomplish that, see git grep cwd= test/t
for examples. That would leave a lot fewer dirs to expect, but a/
would still be there to verify we get the dir in these completions.
Would be a good thing to also add a let's say JEP330.java
file (maybe with a link in its contents that points to the JEP) in fixtures/java
to make it explicit that we really do want *.java
in these completions, as it's probably not that well known feature to many.