Commit 0f1ffa1215ae2ca28e9ff9726313853cba021737
1 parent
4782b590
Move bash/zsh completion helpers to libtests/arg_parser
Showing
2 changed files
with
41 additions
and
35 deletions
libtests/qtest/arg_parser/completion_helpers.pm
0 → 100644
| 1 | +# This is also used by qpdf.test. | |
| 2 | + | |
| 3 | +sub bash_completion | |
| 4 | +{ | |
| 5 | + my ($x, $line, $point) = @_; | |
| 6 | + if (! defined $point) | |
| 7 | + { | |
| 8 | + $point = length($line); | |
| 9 | + } | |
| 10 | + my $before_point = substr($line, 0, $point); | |
| 11 | + my $first = ''; | |
| 12 | + my $sep = ''; | |
| 13 | + my $cur = ''; | |
| 14 | + if ($before_point =~ m/^(.*)([ =])([^= ]*)$/) | |
| 15 | + { | |
| 16 | + ($first, $sep, $cur) = ($1, $2, $3); | |
| 17 | + } | |
| 18 | + my $prev = ($sep eq '=' ? $sep : $first); | |
| 19 | + $prev =~ s/.* (\S+)$/$1/; | |
| 20 | + my $this = $first; | |
| 21 | + $this =~ s/(\S+)\s.*/$1/; | |
| 22 | + ['env', "COMP_LINE=$line", "COMP_POINT=$point", | |
| 23 | + $x, $this, $cur, $prev]; | |
| 24 | +} | |
| 25 | + | |
| 26 | +sub zsh_completion | |
| 27 | +{ | |
| 28 | + my ($x, $line, $point) = @_; | |
| 29 | + if (! defined $point) | |
| 30 | + { | |
| 31 | + $point = length($line); | |
| 32 | + } | |
| 33 | + ['env', "COMP_LINE=$line", "COMP_POINT=$point", $x]; | |
| 34 | +} | |
| 35 | + | |
| 36 | +1; | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -8,6 +8,9 @@ use File::Basename; |
| 8 | 8 | use File::Copy; |
| 9 | 9 | use File::Spec; |
| 10 | 10 | |
| 11 | +unshift(@INC, '../../libtests/qtest/arg_parser'); | |
| 12 | +require completion_helpers; | |
| 13 | + | |
| 11 | 14 | chdir("qpdf") or die "chdir testdir failed: $!\n"; |
| 12 | 15 | |
| 13 | 16 | require TestDriver; |
| ... | ... | @@ -127,12 +130,12 @@ foreach my $c (@completion_tests) |
| 127 | 130 | $zout = $out; |
| 128 | 131 | } |
| 129 | 132 | $td->runtest("bash completion: $description", |
| 130 | - {$td->COMMAND => [@{bash_completion($cmd, $point)}], | |
| 133 | + {$td->COMMAND => [@{bash_completion("qpdf", $cmd, $point)}], | |
| 131 | 134 | $td->FILTER => "$completion_filter $out"}, |
| 132 | 135 | {$td->FILE => "$out", $td->EXIT_STATUS => 0}, |
| 133 | 136 | $td->NORMALIZE_NEWLINES); |
| 134 | 137 | $td->runtest("zsh completion: $description", |
| 135 | - {$td->COMMAND => [@{zsh_completion($cmd, $point)}], | |
| 138 | + {$td->COMMAND => [@{zsh_completion("qpdf", $cmd, $point)}], | |
| 136 | 139 | $td->FILTER => "$completion_filter $zout"}, |
| 137 | 140 | {$td->FILE => "$zout", $td->EXIT_STATUS => 0}, |
| 138 | 141 | $td->NORMALIZE_NEWLINES); |
| ... | ... | @@ -5427,39 +5430,6 @@ sub show_ntests |
| 5427 | 5430 | cleanup(); |
| 5428 | 5431 | } |
| 5429 | 5432 | |
| 5430 | -sub bash_completion | |
| 5431 | -{ | |
| 5432 | - my ($line, $point) = @_; | |
| 5433 | - if (! defined $point) | |
| 5434 | - { | |
| 5435 | - $point = length($line); | |
| 5436 | - } | |
| 5437 | - my $before_point = substr($line, 0, $point); | |
| 5438 | - my $first = ''; | |
| 5439 | - my $sep = ''; | |
| 5440 | - my $cur = ''; | |
| 5441 | - if ($before_point =~ m/^(.*)([ =])([^= ]*)$/) | |
| 5442 | - { | |
| 5443 | - ($first, $sep, $cur) = ($1, $2, $3); | |
| 5444 | - } | |
| 5445 | - my $prev = ($sep eq '=' ? $sep : $first); | |
| 5446 | - $prev =~ s/.* (\S+)$/$1/; | |
| 5447 | - my $this = $first; | |
| 5448 | - $this =~ s/(\S+)\s.*/$1/; | |
| 5449 | - ['env', "COMP_LINE=$line", "COMP_POINT=$point", | |
| 5450 | - "qpdf", $this, $cur, $prev]; | |
| 5451 | -} | |
| 5452 | - | |
| 5453 | -sub zsh_completion | |
| 5454 | -{ | |
| 5455 | - my ($line, $point) = @_; | |
| 5456 | - if (! defined $point) | |
| 5457 | - { | |
| 5458 | - $point = length($line); | |
| 5459 | - } | |
| 5460 | - ['env', "COMP_LINE=$line", "COMP_POINT=$point", "qpdf"]; | |
| 5461 | -} | |
| 5462 | - | |
| 5463 | 5433 | sub check_pdf |
| 5464 | 5434 | { |
| 5465 | 5435 | my ($description, $command, $output, $status) = @_; | ... | ... |