From 4782b5904f2cddc7ecda86abc0590a2ff8715b33 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 30 Dec 2021 12:56:27 -0500 Subject: [PATCH] Move filter-completion.pl to libtests/arg_parser --- libtests/qtest/arg_parser/filter-completion.pl | 41 +++++++++++++++++++++++++++++++++++++++++ qpdf/qtest/qpdf.test | 6 ++++-- qpdf/qtest/qpdf/filter-completion.pl | 39 --------------------------------------- 3 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 libtests/qtest/arg_parser/filter-completion.pl delete mode 100644 qpdf/qtest/qpdf/filter-completion.pl diff --git a/libtests/qtest/arg_parser/filter-completion.pl b/libtests/qtest/arg_parser/filter-completion.pl new file mode 100644 index 0000000..2d17630 --- /dev/null +++ b/libtests/qtest/arg_parser/filter-completion.pl @@ -0,0 +1,41 @@ +use warnings; +use strict; + +# THIS SCRIPT IS ALSO USED IN qpdf.test + +# Output every line from STDIN that appears in the file. +my %wanted = (); +my %notwanted = (); +my $f = $ARGV[0]; +if (open(F, "<$f")) +{ + while () + { + chomp; + if (s/^!//) + { + $notwanted{$_} = 1; + } + else + { + $wanted{$_} = 1; + } + } + close(F); +} +while () +{ + chomp; + if (exists $wanted{$_}) + { + print $_, "\n"; + } + elsif (exists $notwanted{$_}) + { + delete $notwanted{$_}; + } +} +foreach my $k (sort keys %notwanted) +{ + print "!$k\n"; +} diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index cd40121..d12c949 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -115,6 +115,8 @@ my @completion_tests = ( ['qpdf --encrypt user\ password ', undef, 'quoting'], ); $n_tests += 2 * scalar(@completion_tests); +my $completion_filter = + "perl ../../../libtests/qtest/arg_parser/filter-completion.pl"; foreach my $c (@completion_tests) { my ($cmd, $point, $description) = @$c; @@ -126,12 +128,12 @@ foreach my $c (@completion_tests) } $td->runtest("bash completion: $description", {$td->COMMAND => [@{bash_completion($cmd, $point)}], - $td->FILTER => "perl filter-completion.pl $out"}, + $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->FILTER => "perl filter-completion.pl $zout"}, + $td->FILTER => "$completion_filter $zout"}, {$td->FILE => "$zout", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); } diff --git a/qpdf/qtest/qpdf/filter-completion.pl b/qpdf/qtest/qpdf/filter-completion.pl deleted file mode 100644 index a81178e..0000000 --- a/qpdf/qtest/qpdf/filter-completion.pl +++ /dev/null @@ -1,39 +0,0 @@ -use warnings; -use strict; - -# Output every line from STDIN that appears in the file. -my %wanted = (); -my %notwanted = (); -my $f = $ARGV[0]; -if (open(F, "<$f")) -{ - while () - { - chomp; - if (s/^!//) - { - $notwanted{$_} = 1; - } - else - { - $wanted{$_} = 1; - } - } - close(F); -} -while () -{ - chomp; - if (exists $wanted{$_}) - { - print $_, "\n"; - } - elsif (exists $notwanted{$_}) - { - delete $notwanted{$_}; - } -} -foreach my $k (sort keys %notwanted) -{ - print "!$k\n"; -} -- libgit2 0.21.4