aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libtests/qtest/arg_parser/completion_helpers.pm36
-rw-r--r--qpdf/qtest/qpdf.test40
2 files changed, 41 insertions, 35 deletions
diff --git a/libtests/qtest/arg_parser/completion_helpers.pm b/libtests/qtest/arg_parser/completion_helpers.pm
new file mode 100644
index 00000000..328673e5
--- /dev/null
+++ b/libtests/qtest/arg_parser/completion_helpers.pm
@@ -0,0 +1,36 @@
+# This is also used by qpdf.test.
+
+sub bash_completion
+{
+ my ($x, $line, $point) = @_;
+ if (! defined $point)
+ {
+ $point = length($line);
+ }
+ my $before_point = substr($line, 0, $point);
+ my $first = '';
+ my $sep = '';
+ my $cur = '';
+ if ($before_point =~ m/^(.*)([ =])([^= ]*)$/)
+ {
+ ($first, $sep, $cur) = ($1, $2, $3);
+ }
+ my $prev = ($sep eq '=' ? $sep : $first);
+ $prev =~ s/.* (\S+)$/$1/;
+ my $this = $first;
+ $this =~ s/(\S+)\s.*/$1/;
+ ['env', "COMP_LINE=$line", "COMP_POINT=$point",
+ $x, $this, $cur, $prev];
+}
+
+sub zsh_completion
+{
+ my ($x, $line, $point) = @_;
+ if (! defined $point)
+ {
+ $point = length($line);
+ }
+ ['env', "COMP_LINE=$line", "COMP_POINT=$point", $x];
+}
+
+1;
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index d12c9492..5f61388b 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -8,6 +8,9 @@ use File::Basename;
use File::Copy;
use File::Spec;
+unshift(@INC, '../../libtests/qtest/arg_parser');
+require completion_helpers;
+
chdir("qpdf") or die "chdir testdir failed: $!\n";
require TestDriver;
@@ -127,12 +130,12 @@ foreach my $c (@completion_tests)
$zout = $out;
}
$td->runtest("bash completion: $description",
- {$td->COMMAND => [@{bash_completion($cmd, $point)}],
+ {$td->COMMAND => [@{bash_completion("qpdf", $cmd, $point)}],
$td->FILTER => "$completion_filter $out"},
{$td->FILE => "$out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("zsh completion: $description",
- {$td->COMMAND => [@{zsh_completion($cmd, $point)}],
+ {$td->COMMAND => [@{zsh_completion("qpdf", $cmd, $point)}],
$td->FILTER => "$completion_filter $zout"},
{$td->FILE => "$zout", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
@@ -5427,39 +5430,6 @@ sub show_ntests
cleanup();
}
-sub bash_completion
-{
- my ($line, $point) = @_;
- if (! defined $point)
- {
- $point = length($line);
- }
- my $before_point = substr($line, 0, $point);
- my $first = '';
- my $sep = '';
- my $cur = '';
- if ($before_point =~ m/^(.*)([ =])([^= ]*)$/)
- {
- ($first, $sep, $cur) = ($1, $2, $3);
- }
- my $prev = ($sep eq '=' ? $sep : $first);
- $prev =~ s/.* (\S+)$/$1/;
- my $this = $first;
- $this =~ s/(\S+)\s.*/$1/;
- ['env', "COMP_LINE=$line", "COMP_POINT=$point",
- "qpdf", $this, $cur, $prev];
-}
-
-sub zsh_completion
-{
- my ($line, $point) = @_;
- if (! defined $point)
- {
- $point = length($line);
- }
- ['env', "COMP_LINE=$line", "COMP_POINT=$point", "qpdf"];
-}
-
sub check_pdf
{
my ($description, $command, $output, $status) = @_;