From 9484c284c808a90d44c9cb67aad478d3436a8aad Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Mon, 20 Jan 2025 20:12:08 -0600 Subject: [PATCH] Hoist tests into YAML files --- .gitignore | 1 + MANIFEST | 17 ++-- cpanfile | 1 + t/Util.pm | 74 +++++++++++--- t/ack-c.t | 24 ----- t/ack-c.yaml | 24 ++--- t/ack-column.t | 85 ---------------- t/ack-column.yaml | 45 +++++++++ t/ack-f.t | 25 ----- t/ack-f.yaml | 10 +- t/ack-k.t | 126 ----------------------- t/ack-k.yaml | 101 +++++++++++++++++++ t/ack-l.t | 110 -------------------- t/ack-l.yaml | 40 ++++++++ t/ack-o.t | 51 ---------- t/ack-o.yaml | 25 +++++ t/ack-proximate.t | 232 ------------------------------------------- t/ack-proximate.yaml | 158 +++++++++++++++++++++++++++++ t/ack-v.t | 69 ------------- t/ack-v.yaml | 38 +++++++ t/basic.t | 25 ----- t/basic.yaml | 15 +-- t/run_test.py | 51 ++++++++++ t/swamp/foo_test.py | 9 +- t/swamp/test_foo.py | 9 +- t/yaml.t | 38 +++++++ t/zero.t | 56 ----------- t/zero.yaml | 16 +++ tags | 30 +++--- 29 files changed, 628 insertions(+), 877 deletions(-) delete mode 100644 t/ack-c.t delete mode 100644 t/ack-column.t create mode 100644 t/ack-column.yaml delete mode 100644 t/ack-f.t delete mode 100644 t/ack-k.t create mode 100644 t/ack-k.yaml delete mode 100644 t/ack-l.t create mode 100644 t/ack-l.yaml delete mode 100644 t/ack-o.t create mode 100644 t/ack-o.yaml delete mode 100644 t/ack-proximate.t create mode 100644 t/ack-proximate.yaml delete mode 100644 t/ack-v.t create mode 100644 t/ack-v.yaml delete mode 100644 t/basic.t create mode 100644 t/run_test.py create mode 100644 t/yaml.t delete mode 100644 t/zero.t create mode 100644 t/zero.yaml diff --git a/.gitignore b/.gitignore index 51238fc8..0e16751d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ nytprof.out /_eumm/ ack-standalone *~ +__pycache__ diff --git a/MANIFEST b/MANIFEST index 9cca8da8..08d28afe 100644 --- a/MANIFEST +++ b/MANIFEST @@ -35,13 +35,11 @@ t/00-load.t t/FilterTest.pm t/ack-1.t t/ack-Q.t -t/ack-c.t t/ack-c.yaml t/ack-color.t -t/ack-column.t +t/ack-column.yaml t/ack-create-ackrc.t t/ack-dump.t -t/ack-f.t t/ack-f.yaml t/ack-files-from.t t/ack-g.t @@ -53,32 +51,31 @@ t/ack-i.barfly t/ack-i.t t/ack-ignore-dir.t t/ack-ignore-file.t -t/ack-k.t -t/ack-l.t +t/ack-k.yaml +t/ack-l.yaml t/ack-m.t t/ack-man.t t/ack-match.t t/ack-n.t -t/ack-o.t +t/ack-o.yaml t/ack-output.t t/ack-pager.t t/ack-passthru.t t/ack-print0.t -t/ack-proximate.t +t/ack-proximate.yaml t/ack-s.t t/ack-show-types.t t/ack-type-del.t t/ack-type.t t/ack-underline.barfly t/ack-underline.t -t/ack-v.t +t/ack-v.yaml t/ack-version.t t/ack-w.barfly t/ack-w.t t/ack-x.t t/anchored.t t/bad-ackrc-opt.t -t/basic.t t/basic.yaml t/boolean.t t/build_regex.t @@ -123,7 +120,7 @@ t/prescan-line-boundaries.t t/process-substitution.t t/runtests.pl t/trailing-whitespace.t -t/zero.t +t/zero.yaml t/etc/buttonhook.xml.xxx t/etc/shebang.empty.xxx diff --git a/cpanfile b/cpanfile index 05cd4c73..30a568ca 100644 --- a/cpanfile +++ b/cpanfile @@ -26,6 +26,7 @@ on 'test' => sub { requires 'Scalar::Util' => 0; requires 'Test::Harness' => '2.50'; # Something reasonably newish requires 'Test::More' => '0.98'; # For subtest() + requires 'YAML::PP' => 0; if ( $^O ne 'MSWin32' ) { requires 'IO::Pty' => 0; diff --git a/t/Util.pm b/t/Util.pm index 0352ee1a..30517d98 100644 --- a/t/Util.pm +++ b/t/Util.pm @@ -12,6 +12,7 @@ use Cwd (); use File::Next (); use File::Spec (); use File::Temp (); +use List::Util qw( any ); use Scalar::Util qw( tainted ); use Term::ANSIColor (); use Test::More; @@ -1285,23 +1286,72 @@ sub read_tests { my @tests = $ypp->load_file( $filename ); for my $test ( @tests ) { - my @lines; - if ( $test->{output} ) { - @lines = split( /\n/, $test->{output} ); - chomp $lines[-1] if @lines; - } - $test->{output} = \@lines; + $test->{stdout} = _lineify( $test->{stdout} ); - my $args = $test->{args}; - $args = [ $args ] unless ref($args); - for ( @$args ) { - $_ = [ split / / ]; - } - $test->{args} = $args; + $test->{args} = _split_args( $test->{args} ); + + # Assume successful run. + $test->{exitcode} //= 0; + + # Assume order doesn't matter. + $test->{ordered} //= 0; + + _validate_test( $test ); } return @tests; } +sub _split_args { + my $args = shift; + + $args = [ $args ] unless ref($args); + for ( @{$args} ) { + $_ = [ split / / ]; + } + return $args; +} + + +sub _lineify { + my $block = shift; + + my @lines; + if ( $block ) { + @lines = split( /\n/, $block ); + chomp $lines[-1] if @lines; + } + + return \@lines; +} + + +sub _validate_test { + my $test = shift; + + my @valid_keys = qw( + args + exitcode + name + ordered + stderr + stdout + ); + for my $key ( keys %{$test} ) { + die "Invalid key $key" unless _in( $key, \@valid_keys ); + } + + return; +} + + +sub _in { + my $needle = shift; + my $haystack = shift; + + return any { $_ eq $needle } @{$haystack}; +} + + 1; diff --git a/t/ack-c.t b/t/ack-c.t deleted file mode 100644 index 5158124d..00000000 --- a/t/ack-c.t +++ /dev/null @@ -1,24 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 7; - -use lib 't'; -use Util; - -prep_environment(); - -my @tests = read_tests( 't/ack-c.yaml' ); - -for my $test ( @tests ) { - subtest $test->{name} => sub () { - for my $args ( @{$test->{args}} ) { - ack_sets_match( $args, $test->{output}, $test->{name} ); - is( get_rc(), $test->{rc} ); - } - }; -} - -exit 0; diff --git a/t/ack-c.yaml b/t/ack-c.yaml index 1d54406e..4fef32ee 100644 --- a/t/ack-c.yaml +++ b/t/ack-c.yaml @@ -1,8 +1,8 @@ --- name: -c args: God -c --sort-files t/text -rc: 0 -output: | +ordered: true +stdout: | t/text/amontillado.txt:2 t/text/bill-of-rights.txt:0 t/text/constitution.txt:0 @@ -16,15 +16,14 @@ output: | --- name: -c and --no-filename args: God -c --no-filename t/text -rc: 0 -output: | +stdout: | 5 --- name: -c and -v args: the -i -w -v -c --sort-files t/text -rc: 0 -output: | +ordered: true +stdout: | t/text/amontillado.txt:206 t/text/bill-of-rights.txt:45 t/text/constitution.txt:259 @@ -38,28 +37,25 @@ output: | --- name: -c and -l args: congress -i -l -c --sort-files t/text -rc: 0 -output: | +ordered: true +stdout: | t/text/bill-of-rights.txt:1 t/text/constitution.txt:29 --- name: -c and -h args: Montresor -c -h t/text -rc: 0 -output: | +stdout: | 3 --- name: Normal count args: Montresor -c -h t/text/amontillado.txt -rc: 0 -output: | +stdout: | 3 --- name: Count with --not args: Montresor -c -h --not God t/text/amontillado.txt -rc: 0 -output: | +stdout: | 2 diff --git a/t/ack-column.t b/t/ack-column.t deleted file mode 100644 index bd5842e1..00000000 --- a/t/ack-column.t +++ /dev/null @@ -1,85 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 6; - - -use lib 't'; -use Util; - -prep_environment(); - -my $raven = reslash( 't/text/raven.txt' ); -my @base_args = qw( nevermore -w -i --with-filename --noenv ); - -WITH_COLUMNS: { - my @expected = line_split( <<'HERE' ); -55:23: Quoth the Raven, "Nevermore." -62:24: With such name as "Nevermore." -69:26: Then the bird said, "Nevermore." -76:18: Of 'Never -- nevermore.' -83:24: Meant in croaking "Nevermore." -90:26: She shall press, ah, nevermore! -97:23: Quoth the Raven, "Nevermore." -104:23: Quoth the Raven, "Nevermore." -111:23: Quoth the Raven, "Nevermore." -118:23: Quoth the Raven, "Nevermore." -125:22: Shall be lifted--nevermore! -HERE - @expected = map { "${raven}:$_" } @expected; - - my @files = ( $raven ); - my @args = ( @base_args, '--column' ); - my @results = run_ack( @args, @files ); - - lists_match( \@results, \@expected, 'Checking column numbers' ); -} - - -WITH_COLUMNS_AND_NOT: { - # Verify that the --not does not mess up the column number. - my @expected = line_split( <<'HERE' ); -62:24: With such name as "Nevermore." -69:26: Then the bird said, "Nevermore." -76:18: Of 'Never -- nevermore.' -83:24: Meant in croaking "Nevermore." -90:26: She shall press, ah, nevermore! -125:22: Shall be lifted--nevermore! -HERE - @expected = map { "${raven}:$_" } @expected; - - my @files = ( $raven ); - my @args = ( @base_args, '--column', '--not', 'Quoth' ); - my @results = run_ack( @args, @files ); - - lists_match( \@results, \@expected, 'Checking column numbers' ); -} - - -WITHOUT_COLUMNS: { - my @expected = line_split( <<'HERE' ); -55: Quoth the Raven, "Nevermore." -62: With such name as "Nevermore." -69: Then the bird said, "Nevermore." -76: Of 'Never -- nevermore.' -83: Meant in croaking "Nevermore." -90: She shall press, ah, nevermore! -97: Quoth the Raven, "Nevermore." -104: Quoth the Raven, "Nevermore." -111: Quoth the Raven, "Nevermore." -118: Quoth the Raven, "Nevermore." -125: Shall be lifted--nevermore! -HERE - @expected = map { "${raven}:$_" } @expected; - - my @files = ( $raven ); - my @args = ( @base_args, '--no-column' ); - my @results = run_ack( @args, @files ); - - lists_match( \@results, \@expected, 'Checking without column numbers' ); -} - -done_testing(); -exit 0; diff --git a/t/ack-column.yaml b/t/ack-column.yaml new file mode 100644 index 00000000..1cfe8dba --- /dev/null +++ b/t/ack-column.yaml @@ -0,0 +1,45 @@ +--- +name: With --columns +args: nevermore --column -w -i --with-filename --noenv t/text/raven.txt +ordered: true +stdout: | + t/text/raven.txt:55:23: Quoth the Raven, "Nevermore." + t/text/raven.txt:62:24: With such name as "Nevermore." + t/text/raven.txt:69:26: Then the bird said, "Nevermore." + t/text/raven.txt:76:18: Of 'Never -- nevermore.' + t/text/raven.txt:83:24: Meant in croaking "Nevermore." + t/text/raven.txt:90:26: She shall press, ah, nevermore! + t/text/raven.txt:97:23: Quoth the Raven, "Nevermore." + t/text/raven.txt:104:23: Quoth the Raven, "Nevermore." + t/text/raven.txt:111:23: Quoth the Raven, "Nevermore." + t/text/raven.txt:118:23: Quoth the Raven, "Nevermore." + t/text/raven.txt:125:22: Shall be lifted--nevermore! + +--- +name: With --column and --not +args: nevermore --not Quoth -w -i --with-filename --noenv --column t/text/raven.txt +ordered: true +stdout: | + t/text/raven.txt:62:24: With such name as "Nevermore." + t/text/raven.txt:69:26: Then the bird said, "Nevermore." + t/text/raven.txt:76:18: Of 'Never -- nevermore.' + t/text/raven.txt:83:24: Meant in croaking "Nevermore." + t/text/raven.txt:90:26: She shall press, ah, nevermore! + t/text/raven.txt:125:22: Shall be lifted--nevermore! + +--- +name: Without columns +args: nevermore -w -i --with-filename --noenv --no-column t/text/raven.txt +ordered: true +stdout: | + t/text/raven.txt:55: Quoth the Raven, "Nevermore." + t/text/raven.txt:62: With such name as "Nevermore." + t/text/raven.txt:69: Then the bird said, "Nevermore." + t/text/raven.txt:76: Of 'Never -- nevermore.' + t/text/raven.txt:83: Meant in croaking "Nevermore." + t/text/raven.txt:90: She shall press, ah, nevermore! + t/text/raven.txt:97: Quoth the Raven, "Nevermore." + t/text/raven.txt:104: Quoth the Raven, "Nevermore." + t/text/raven.txt:111: Quoth the Raven, "Nevermore." + t/text/raven.txt:118: Quoth the Raven, "Nevermore." + t/text/raven.txt:125: Shall be lifted--nevermore! diff --git a/t/ack-f.t b/t/ack-f.t deleted file mode 100644 index 04624edd..00000000 --- a/t/ack-f.t +++ /dev/null @@ -1,25 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 3; - -use lib 't'; -use Util; - -prep_environment(); - -my @tests = read_tests( 't/ack-f.yaml' ); - -for my $test ( @tests ) { - subtest $test->{name} => sub () { - for my $args ( @{$test->{args}} ) { - ack_sets_match( $args, $test->{output}, $test->{name} ); - is( get_rc(), $test->{rc} ); - } - }; -} - - -exit 0; diff --git a/t/ack-f.yaml b/t/ack-f.yaml index db13cbd0..612f4b32 100644 --- a/t/ack-f.yaml +++ b/t/ack-f.yaml @@ -1,8 +1,7 @@ --- name: Default directory exclusions args: -f t/swamp -rc: 0 -output: | +stdout: | t/swamp/0 t/swamp/c-header.h t/swamp/c-source.c @@ -63,8 +62,7 @@ output: | --- name: Combined filters args: -f t/swamp -t perl -t rake -rc: 0 -output: | +stdout: | t/swamp/0 t/swamp/constitution-100k.pl t/swamp/perl.pm @@ -82,5 +80,5 @@ output: | --- name: Exit code with no matches args: "-f t/swamp --type-add=baz:ext:baz -t baz" -rc: 1 -output: +exitcode: 1 +stdout: diff --git a/t/ack-k.t b/t/ack-k.t deleted file mode 100644 index 89dbfe5d..00000000 --- a/t/ack-k.t +++ /dev/null @@ -1,126 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 3; - -use lib 't'; -use Util; - -prep_environment(); - -subtest 'No restrictions on type' => sub { - my $expected = <<'HERE'; -t/etc/buttonhook.xml.xxx => xml -t/etc/shebang.empty.xxx => -t/etc/shebang.foobar.xxx => -t/etc/shebang.php.xxx => php -t/etc/shebang.pl.xxx => perl -t/etc/shebang.py.xxx => python -t/etc/shebang.rb.xxx => ruby -t/etc/shebang.sh.xxx => shell -HERE - my @expected = reslash_all( line_split( $expected ) ); - - my @args = qw( -f --show-types t/etc ); - ack_sets_match( [ @args ], \@expected, 'No restrictions on type' ); -}; - -subtest 'Only known types' => sub { - my $expected = <<'HERE'; -t/etc/buttonhook.xml.xxx => xml -t/etc/shebang.php.xxx => php -t/etc/shebang.pl.xxx => perl -t/etc/shebang.py.xxx => python -t/etc/shebang.rb.xxx => ruby -t/etc/shebang.sh.xxx => shell -HERE - my @expected = reslash_all( line_split( $expected ) ); - - my @args = qw( -f -k --show-types t/etc ); - ack_sets_match( [ @args ], \@expected, 'Only known types' ); -}; - - -subtest 'More testing' => sub { - plan tests => 4; - - my @files = qw( - t/swamp/0 - t/swamp/constitution-100k.pl - t/swamp/Rakefile - t/swamp/options-crlf.pl - t/swamp/options.pl - t/swamp/javascript.js - t/swamp/html.html - t/swamp/perl-without-extension - t/swamp/sample.rake - t/swamp/perl.cgi - t/swamp/Makefile - t/swamp/pipe-stress-freaks.F - t/swamp/perl.pod - t/swamp/html.htm - t/swamp/perl-test.t - t/swamp/perl.handler.pod - t/swamp/perl.pl - t/swamp/Makefile.PL - t/swamp/MasterPage.master - t/swamp/c-source.c - t/swamp/perl.pm - t/swamp/c-header.h - t/swamp/crystallography-weenies.f - t/swamp/CMakeLists.txt - t/swamp/Sample.ascx - t/swamp/Sample.asmx - t/swamp/sample.asp - t/swamp/sample.aspx - t/swamp/service.svc - t/swamp/stuff.cmake - t/swamp/example.R - t/swamp/fresh.css - t/swamp/lua-shebang-test - t/swamp/notes.md - t/swamp/test.py - t/swamp/test_foo.py - t/swamp/foo_test.py - ); - - my @files_no_perl = qw( - t/swamp/Rakefile - t/swamp/javascript.js - t/swamp/html.html - t/swamp/sample.rake - t/swamp/Makefile - t/swamp/MasterPage.master - t/swamp/pipe-stress-freaks.F - t/swamp/html.htm - t/swamp/c-source.c - t/swamp/c-header.h - t/swamp/crystallography-weenies.f - t/swamp/CMakeLists.txt - t/swamp/Sample.ascx - t/swamp/Sample.asmx - t/swamp/sample.asp - t/swamp/sample.aspx - t/swamp/service.svc - t/swamp/stuff.cmake - t/swamp/example.R - t/swamp/fresh.css - t/swamp/lua-shebang-test - t/swamp/notes.md - t/swamp/test.py - t/swamp/test_foo.py - t/swamp/foo_test.py - ); - - - for my $k_arg ( '-k', '--known-types' ) { - ack_sets_match( [ $k_arg, '-f', 't/swamp' ], \@files, "$k_arg test #1" ); - ack_sets_match( [ $k_arg, '-T', 'perl', '-f', 't/swamp' ], \@files_no_perl, "$k_arg test #2" ); - } -}; - -done_testing(); - -exit 0; diff --git a/t/ack-k.yaml b/t/ack-k.yaml new file mode 100644 index 00000000..367fa59b --- /dev/null +++ b/t/ack-k.yaml @@ -0,0 +1,101 @@ +--- +name: No restrictions on type +args: -f --show-types t/etc +stdout: | + t/etc/buttonhook.xml.xxx => xml + t/etc/shebang.empty.xxx => + t/etc/shebang.foobar.xxx => + t/etc/shebang.php.xxx => php + t/etc/shebang.pl.xxx => perl + t/etc/shebang.py.xxx => python + t/etc/shebang.rb.xxx => ruby + t/etc/shebang.sh.xxx => shell + +--- +name: Only known types +args: -f -k --show-types t/etc +stdout: | + t/etc/buttonhook.xml.xxx => xml + t/etc/shebang.php.xxx => php + t/etc/shebang.pl.xxx => perl + t/etc/shebang.py.xxx => python + t/etc/shebang.rb.xxx => ruby + t/etc/shebang.sh.xxx => shell + +--- +name: -k and -f +args: + - t/swamp -f -k + - t/swamp -f --known-types +stdout: | + t/swamp/0 + t/swamp/constitution-100k.pl + t/swamp/Rakefile + t/swamp/options-crlf.pl + t/swamp/options.pl + t/swamp/javascript.js + t/swamp/html.html + t/swamp/perl-without-extension + t/swamp/sample.rake + t/swamp/perl.cgi + t/swamp/Makefile + t/swamp/pipe-stress-freaks.F + t/swamp/perl.pod + t/swamp/html.htm + t/swamp/perl-test.t + t/swamp/perl.handler.pod + t/swamp/perl.pl + t/swamp/Makefile.PL + t/swamp/MasterPage.master + t/swamp/c-source.c + t/swamp/perl.pm + t/swamp/c-header.h + t/swamp/crystallography-weenies.f + t/swamp/CMakeLists.txt + t/swamp/Sample.ascx + t/swamp/Sample.asmx + t/swamp/sample.asp + t/swamp/sample.aspx + t/swamp/service.svc + t/swamp/stuff.cmake + t/swamp/example.R + t/swamp/fresh.css + t/swamp/lua-shebang-test + t/swamp/notes.md + t/swamp/test.py + t/swamp/test_foo.py + t/swamp/foo_test.py + +--- +name: -k and negated --type specifiers +args: + - -f -T perl t/swamp -k + - -f -T perl t/swamp --known-types + - -f --noperl t/swamp -k + - -f --noperl t/swamp --known-types +stdout: | + t/swamp/Rakefile + t/swamp/javascript.js + t/swamp/html.html + t/swamp/sample.rake + t/swamp/Makefile + t/swamp/MasterPage.master + t/swamp/pipe-stress-freaks.F + t/swamp/html.htm + t/swamp/c-source.c + t/swamp/c-header.h + t/swamp/crystallography-weenies.f + t/swamp/CMakeLists.txt + t/swamp/Sample.ascx + t/swamp/Sample.asmx + t/swamp/sample.asp + t/swamp/sample.aspx + t/swamp/service.svc + t/swamp/stuff.cmake + t/swamp/example.R + t/swamp/fresh.css + t/swamp/lua-shebang-test + t/swamp/notes.md + t/swamp/test.py + t/swamp/test_foo.py + t/swamp/foo_test.py diff --git a/t/ack-l.t b/t/ack-l.t deleted file mode 100644 index 85ade5c9..00000000 --- a/t/ack-l.t +++ /dev/null @@ -1,110 +0,0 @@ -#!perl - -use strict; -use warnings; - -use Test::More; - -plan tests => 11; - -use lib 't'; -use Util; - -prep_environment(); - - -my @matching = qw( - t/text/bill-of-rights.txt - t/text/constitution.txt -); - -my @nonmatching = qw( - t/text/amontillado.txt - t/text/gettysburg.txt - t/text/movies.txt - t/text/number.txt - t/text/numbered-text.txt - t/text/ozymandias.txt - t/text/raven.txt -); - -for my $arg ( qw( -l --files-with-matches ) ) { - subtest "Files with matches: $arg" => sub { - my @results = run_ack( $arg, 'strict', 't/text' ); - sets_match( \@results, \@matching, 'File list match' ); - } -} - - -for my $arg ( qw( -L --files-without-matches ) ) { - subtest "Files without matches: $arg" => sub { - my @results = run_ack( $arg, 'strict', 't/text' ); - sets_match( \@results, \@nonmatching, 'File list match' ); - } -} - -DASH_L: { - my @expected = qw( - t/text/amontillado.txt - t/text/gettysburg.txt - t/text/raven.txt - ); - - my @args = qw( God -i -l --sort-files ); - my @files = qw( t/text ); - - ack_sets_match( [ @args, @files ], \@expected, 'Looking for God with -l' ); -} - -DASH_CAPITAL_L: { - my @expected = qw( - t/text/bill-of-rights.txt - t/text/constitution.txt - t/text/movies.txt - t/text/number.txt - t/text/numbered-text.txt - t/text/ozymandias.txt - ); - - my @switches = ( - ['-L'], - ['--files-without-matches'], - ); - - for my $switches ( @switches ) { - my @files = qw( t/text ); - my @args = ( 'God', @{$switches}, '--sort-files' ); - - ack_sets_match( [ @args, @files ], \@expected, "Looking for God with @{$switches}" ); - } -} - -DASH_LV: { - my @expected = qw( - t/text/amontillado.txt - t/text/bill-of-rights.txt - t/text/constitution.txt - t/text/gettysburg.txt - t/text/movies.txt - t/text/number.txt - t/text/numbered-text.txt - t/text/ozymandias.txt - t/text/raven.txt - ); - my @switches = ( - ['-l','-v'], - ['-l','--invert-match'], - ['--files-with-matches','-v'], - ['--files-with-matches','--invert-match'], - ); - - for my $switches ( @switches ) { - my @files = qw( t/text ); - my @args = ( 'religion', @{$switches}, '--sort-files' ); - - ack_sets_match( [ @args, @files ], \@expected, '-l -v will match all input files because "religion" will not be on every line' ); - } -} - - -exit 0; diff --git a/t/ack-l.yaml b/t/ack-l.yaml new file mode 100644 index 00000000..530c7247 --- /dev/null +++ b/t/ack-l.yaml @@ -0,0 +1,40 @@ +--- +name: Simple -l +args: + - strict t/text -l + - strict t/text --files-with-matches +stdout: | + t/text/bill-of-rights.txt + t/text/constitution.txt + +--- +name: Simple -L +args: + - strict t/text -L + - strict t/text --files-without-matches +stdout: | + t/text/amontillado.txt + t/text/gettysburg.txt + t/text/movies.txt + t/text/number.txt + t/text/numbered-text.txt + t/text/ozymandias.txt + t/text/raven.txt + +--- +name: -l with inverted match +args: + - religion t/text -l -v + - religion t/text -l --invert-match + - religion t/text --files-with-matches -v + - religion t/text --files-with-matches --invert-match +stdout: | + t/text/amontillado.txt + t/text/bill-of-rights.txt + t/text/constitution.txt + t/text/gettysburg.txt + t/text/movies.txt + t/text/number.txt + t/text/numbered-text.txt + t/text/ozymandias.txt + t/text/raven.txt diff --git a/t/ack-o.t b/t/ack-o.t deleted file mode 100644 index 0d1adf34..00000000 --- a/t/ack-o.t +++ /dev/null @@ -1,51 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 2; - -use lib 't'; -use Util; - -prep_environment(); - -NO_O: { - my @files = qw( t/text/gettysburg.txt ); - my @args = qw( the\\s+\\S+ ); - my @expected = line_split( <<'HERE' ); - but it can never forget what they did here. It is for us the living, - rather, to be dedicated here to the unfinished work which they who - here dedicated to the great task remaining before us -- that from these - the last full measure of devotion -- that we here highly resolve that - shall have a new birth of freedom -- and that government of the people, - by the people, for the people, shall not perish from the earth. -HERE - s/^\s+// for @expected; - - ack_lists_match( [ @args, @files ], \@expected, 'Find all the things without -o' ); -} - - -WITH_O: { - my @files = qw( t/text/gettysburg.txt ); - my @args = qw( the\\s+\\S+ -o ); - my @expected = line_split( <<'HERE' ); - the living, - the unfinished - the great - the last - the people, - the people, - the people, - the earth. -HERE - s/^\s+// for @expected; - - ack_lists_match( [ @args, @files ], \@expected, 'Find all the things with -o' ); -} - - -done_testing(); - -exit 0; diff --git a/t/ack-o.yaml b/t/ack-o.yaml new file mode 100644 index 00000000..f26b56a9 --- /dev/null +++ b/t/ack-o.yaml @@ -0,0 +1,25 @@ +--- +name: No -o +args: 'the\s+\S+ t/text/gettysburg.txt' +ordered: true +stdout: | + but it can never forget what they did here. It is for us the living, + rather, to be dedicated here to the unfinished work which they who + here dedicated to the great task remaining before us -- that from these + the last full measure of devotion -- that we here highly resolve that + shall have a new birth of freedom -- and that government of the people, + by the people, for the people, shall not perish from the earth. + +--- +name: With -o +args: 'the\s+\S+ t/text/gettysburg.txt -o' +ordered: true +stdout: | + the living, + the unfinished + the great + the last + the people, + the people, + the people, + the earth. diff --git a/t/ack-proximate.t b/t/ack-proximate.t deleted file mode 100644 index c32966aa..00000000 --- a/t/ack-proximate.t +++ /dev/null @@ -1,232 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 7; - -use lib 't'; -use Util; - -prep_environment(); - -my $const = reslash( 't/text/constitution.txt' ); -my $bill = reslash( 't/text/bill-of-rights.txt' ); - -subtest 'Grouped proximate' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill -53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const -199:To constitute Tribunals inferior to the supreme Court; - -372:Judges of the supreme Court, and all other Officers of the United States, - -376:in the Courts of Law, or in the Heads of Departments. - -404:Court, and in such inferior Courts as the Congress may from time to - -406:Courts, shall hold their Offices during good Behaviour, and shall, at - -425:and those in which a State shall be Party, the supreme Court shall - -427:the supreme Court shall have appellate Jurisdiction, both as to Law and - -441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( -p -i --group --sort court ); - - for my $arg ( qw( --proximate -p ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Grouped proximate' ); - } -}; - - -subtest 'Ungrouped proximate' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill:53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const:199:To constitute Tribunals inferior to the supreme Court; - -$const:372:Judges of the supreme Court, and all other Officers of the United States, - -$const:376:in the Courts of Law, or in the Heads of Departments. - -$const:404:Court, and in such inferior Courts as the Congress may from time to - -$const:406:Courts, shall hold their Offices during good Behaviour, and shall, at - -$const:425:and those in which a State shall be Party, the supreme Court shall - -$const:427:the supreme Court shall have appellate Jurisdiction, both as to Law and - -$const:441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate -i --nogroup --sort court ); - - for my $arg ( qw( --proximate -p ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Ungrouped proximate' ); - } -}; - - -subtest 'Grouped proximate=2' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill -53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const -199:To constitute Tribunals inferior to the supreme Court; - -372:Judges of the supreme Court, and all other Officers of the United States, - -376:in the Courts of Law, or in the Heads of Departments. - -404:Court, and in such inferior Courts as the Congress may from time to -406:Courts, shall hold their Offices during good Behaviour, and shall, at - -425:and those in which a State shall be Party, the supreme Court shall -427:the supreme Court shall have appellate Jurisdiction, both as to Law and - -441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate=2 --group -i --sort court ); - - for my $arg ( qw( --proximate=2 -p2 ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Grouped proximate=2' ); - } -}; - - -subtest 'Grouped proximate=2 with --not' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill -53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const -199:To constitute Tribunals inferior to the supreme Court; - -372:Judges of the supreme Court, and all other Officers of the United States, - -404:Court, and in such inferior Courts as the Congress may from time to -406:Courts, shall hold their Offices during good Behaviour, and shall, at - -425:and those in which a State shall be Party, the supreme Court shall - -441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate=2 --group -i --sort court --not law ); - - for my $arg ( qw( --proximate=2 -p2 ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Grouped proximate=2' ); - } -}; - - - - -subtest 'Ungrouped proximate=2' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill:53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const:199:To constitute Tribunals inferior to the supreme Court; - -$const:372:Judges of the supreme Court, and all other Officers of the United States, - -$const:376:in the Courts of Law, or in the Heads of Departments. - -$const:404:Court, and in such inferior Courts as the Congress may from time to -$const:406:Courts, shall hold their Offices during good Behaviour, and shall, at - -$const:425:and those in which a State shall be Party, the supreme Court shall -$const:427:the supreme Court shall have appellate Jurisdiction, both as to Law and - -$const:441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate=2 --nogroup -i --sort court ); - - for my $arg ( qw( --proximate=2 -p2 ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Ungrouped proximate=2' ); - } -}; - - - -subtest 'Ungrouped proximate=20' => sub { - plan tests => 2; - - my @expected = line_split( <<"HERE" ); -$bill:53:fact tried by a jury, shall be otherwise re-examined in any Court of - -$const:199:To constitute Tribunals inferior to the supreme Court; - -$const:372:Judges of the supreme Court, and all other Officers of the United States, -$const:376:in the Courts of Law, or in the Heads of Departments. - -$const:404:Court, and in such inferior Courts as the Congress may from time to -$const:406:Courts, shall hold their Offices during good Behaviour, and shall, at -$const:425:and those in which a State shall be Party, the supreme Court shall -$const:427:the supreme Court shall have appellate Jurisdiction, both as to Law and -$const:441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate=20 --nogroup -i --sort court ); - - for my $arg ( qw( --proximate=20 -p20 ) ) { - $args[0] = $arg; - ack_lists_match( [ @args, @files ], \@expected, 'Ungrouped proximate=20' ); - } -}; - - -subtest '-P overrides --prox' => sub { - plan tests => 1; - - my @expected = line_split( <<"HERE" ); -$bill:53:fact tried by a jury, shall be otherwise re-examined in any Court of -$const:199:To constitute Tribunals inferior to the supreme Court; -$const:372:Judges of the supreme Court, and all other Officers of the United States, -$const:376:in the Courts of Law, or in the Heads of Departments. -$const:404:Court, and in such inferior Courts as the Congress may from time to -$const:406:Courts, shall hold their Offices during good Behaviour, and shall, at -$const:425:and those in which a State shall be Party, the supreme Court shall -$const:427:the supreme Court shall have appellate Jurisdiction, both as to Law and -$const:441:of two Witnesses to the same overt Act, or on Confession in open Court. -HERE - - my @files = qw( t/text ); - my @args = qw( --proximate=20 --nogroup -i --sort -P court ); - - ack_lists_match( [ @args, @files ], \@expected, '-P overrides --prox' ); -}; - -done_testing(); - -exit 0; diff --git a/t/ack-proximate.yaml b/t/ack-proximate.yaml new file mode 100644 index 00000000..62eb67fd --- /dev/null +++ b/t/ack-proximate.yaml @@ -0,0 +1,158 @@ +--- +name: Basic --proximate +args: + - court t/text -i --group --sort -p + - court t/text -i --group --sort --proximate +ordered: true +stdout: | + t/text/bill-of-rights.txt + 53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt + 199:To constitute Tribunals inferior to the supreme Court; + + 372:Judges of the supreme Court, and all other Officers of the United States, + + 376:in the Courts of Law, or in the Heads of Departments. + + 404:Court, and in such inferior Courts as the Congress may from time to + + 406:Courts, shall hold their Offices during good Behaviour, and shall, at + + 425:and those in which a State shall be Party, the supreme Court shall + + 427:the supreme Court shall have appellate Jurisdiction, both as to Law and + + 441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: Ungrouped --proximate +args: + - court t/text -i --nogroup --sort -p + - court t/text -i --nogroup --sort --proximate +ordered: true +stdout: | + t/text/bill-of-rights.txt:53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt:199:To constitute Tribunals inferior to the supreme Court; + + t/text/constitution.txt:372:Judges of the supreme Court, and all other Officers of the United States, + + t/text/constitution.txt:376:in the Courts of Law, or in the Heads of Departments. + + t/text/constitution.txt:404:Court, and in such inferior Courts as the Congress may from time to + + t/text/constitution.txt:406:Courts, shall hold their Offices during good Behaviour, and shall, at + + t/text/constitution.txt:425:and those in which a State shall be Party, the supreme Court shall + + t/text/constitution.txt:427:the supreme Court shall have appellate Jurisdiction, both as to Law and + + t/text/constitution.txt:441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: --proximate with a number +args: + - court t/text -i --sort --group -p2 + - court t/text -i --sort --group --proximate=2 +ordered: true +stdout: | + t/text/bill-of-rights.txt + 53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt + 199:To constitute Tribunals inferior to the supreme Court; + + 372:Judges of the supreme Court, and all other Officers of the United States, + + 376:in the Courts of Law, or in the Heads of Departments. + + 404:Court, and in such inferior Courts as the Congress may from time to + 406:Courts, shall hold their Offices during good Behaviour, and shall, at + + 425:and those in which a State shall be Party, the supreme Court shall + 427:the supreme Court shall have appellate Jurisdiction, both as to Law and + + 441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: Ungrouped --proximate with a number +args: + - court t/text -i --sort --nogroup -p2 + - court t/text -i --sort --nogroup --proximate=2 +ordered: true +stdout: | + t/text/bill-of-rights.txt:53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt:199:To constitute Tribunals inferior to the supreme Court; + + t/text/constitution.txt:372:Judges of the supreme Court, and all other Officers of the United States, + + t/text/constitution.txt:376:in the Courts of Law, or in the Heads of Departments. + + t/text/constitution.txt:404:Court, and in such inferior Courts as the Congress may from time to + t/text/constitution.txt:406:Courts, shall hold their Offices during good Behaviour, and shall, at + + t/text/constitution.txt:425:and those in which a State shall be Party, the supreme Court shall + t/text/constitution.txt:427:the supreme Court shall have appellate Jurisdiction, both as to Law and + + t/text/constitution.txt:441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: Ungrouped --proximate=20 +args: + - court t/text -i --sort --nogroup -p20 + - court t/text -i --sort --nogroup --proximate=20 +ordered: true +stdout: | + t/text/bill-of-rights.txt:53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt:199:To constitute Tribunals inferior to the supreme Court; + + t/text/constitution.txt:372:Judges of the supreme Court, and all other Officers of the United States, + t/text/constitution.txt:376:in the Courts of Law, or in the Heads of Departments. + + t/text/constitution.txt:404:Court, and in such inferior Courts as the Congress may from time to + t/text/constitution.txt:406:Courts, shall hold their Offices during good Behaviour, and shall, at + t/text/constitution.txt:425:and those in which a State shall be Party, the supreme Court shall + t/text/constitution.txt:427:the supreme Court shall have appellate Jurisdiction, both as to Law and + t/text/constitution.txt:441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: --proximate with a number and --not +args: + - court --not law t/text -i --sort --group -p2 + - court --not law t/text -i --sort --group --proximate=2 +ordered: true +stdout: | + t/text/bill-of-rights.txt + 53:fact tried by a jury, shall be otherwise re-examined in any Court of + + t/text/constitution.txt + 199:To constitute Tribunals inferior to the supreme Court; + + 372:Judges of the supreme Court, and all other Officers of the United States, + + 404:Court, and in such inferior Courts as the Congress may from time to + 406:Courts, shall hold their Offices during good Behaviour, and shall, at + + 425:and those in which a State shall be Party, the supreme Court shall + + 441:of two Witnesses to the same overt Act, or on Confession in open Court. + +--- +name: -P overrides -p and --proximate +args: + - court t/text -i --sort --nogroup -p20 -P + - court t/text -i --sort --nogroup --proximate=20 -P +ordered: true +stdout: | + t/text/bill-of-rights.txt:53:fact tried by a jury, shall be otherwise re-examined in any Court of + t/text/constitution.txt:199:To constitute Tribunals inferior to the supreme Court; + t/text/constitution.txt:372:Judges of the supreme Court, and all other Officers of the United States, + t/text/constitution.txt:376:in the Courts of Law, or in the Heads of Departments. + t/text/constitution.txt:404:Court, and in such inferior Courts as the Congress may from time to + t/text/constitution.txt:406:Courts, shall hold their Offices during good Behaviour, and shall, at + t/text/constitution.txt:425:and those in which a State shall be Party, the supreme Court shall + t/text/constitution.txt:427:the supreme Court shall have appellate Jurisdiction, both as to Law and + t/text/constitution.txt:441:of two Witnesses to the same overt Act, or on Confession in open Court. diff --git a/t/ack-v.t b/t/ack-v.t deleted file mode 100644 index b39ed10d..00000000 --- a/t/ack-v.t +++ /dev/null @@ -1,69 +0,0 @@ -#!perl - -use warnings; -use strict; - -use Test::More tests => 3; - -use lib 't'; -use Util; - -prep_environment(); - -NORMAL_CASE: { - my @expected = line_split( <<'END' ); -I met a traveller from an antique land -Stand in the desert... Near them, on the sand, -Which yet survive, stamped on these lifeless things, -The hand that mocked them, and the heart that fed: -'My name is Ozymandias, king of kings: -Nothing beside remains. Round the decay -END - - my @args = qw( -v w ); - my @files = qw( t/text/ozymandias.txt ); - - ack_lists_match( [ @args, @files ], \@expected, 'Find the lines that do not contain a "w"' ); -} - -IGNORE_CASE: { - my @expected = line_split( <<'END' ); -I met a traveller from an antique land -Stand in the desert... Near them, on the sand, -The hand that mocked them, and the heart that fed: -'My name is Ozymandias, king of kings: -Nothing beside remains. Round the decay -END - - my @args = qw( -i -v w ); - my @files = qw( t/text/ozymandias.txt ); - - ack_lists_match( [ @args, @files ], \@expected, 'Find the lines that do not contain a "w", ignoring case' ); -} - - -# -v and --not means double negation. -WITH_NOT: { - my @expected = line_split( <<'END' ); -I met a traveller from an antique land -Who said: Two vast and trunkless legs of stone -Stand in the desert... Near them, on the sand, -Half sunk, a shattered visage lies, whose frown, -And wrinkled lip, and sneer of cold command, -Tell that its sculptor well those passions read -The hand that mocked them, and the heart that fed: -'My name is Ozymandias, king of kings: -Look on my works, ye Mighty, and despair!' -Of that colossal wreck, boundless and bare -END - - my @args = qw( -i -v the --not them ); - my @files = qw( t/text/ozymandias.txt ); - - ack_lists_match( [ @args, @files ], \@expected, 'Find "the" --not "them"' ); -} - - -done_testing(); - -exit 0; diff --git a/t/ack-v.yaml b/t/ack-v.yaml new file mode 100644 index 00000000..761fa841 --- /dev/null +++ b/t/ack-v.yaml @@ -0,0 +1,38 @@ +--- +name: Normal case +args: -v w t/text/ozymandias.txt +ordered: true +stdout: | + I met a traveller from an antique land + Stand in the desert... Near them, on the sand, + Which yet survive, stamped on these lifeless things, + The hand that mocked them, and the heart that fed: + 'My name is Ozymandias, king of kings: + Nothing beside remains. Round the decay + +--- +name: Ignore case +args: -i -v w t/text/ozymandias.txt +ordered: true +stdout: | + I met a traveller from an antique land + Stand in the desert... Near them, on the sand, + The hand that mocked them, and the heart that fed: + 'My name is Ozymandias, king of kings: + Nothing beside remains. Round the decay + +--- +name: With not +args: -i -v the --not them t/text/ozymandias.txt +ordered: true +stdout: | + I met a traveller from an antique land + Who said: Two vast and trunkless legs of stone + Stand in the desert... Near them, on the sand, + Half sunk, a shattered visage lies, whose frown, + And wrinkled lip, and sneer of cold command, + Tell that its sculptor well those passions read + The hand that mocked them, and the heart that fed: + 'My name is Ozymandias, king of kings: + Look on my works, ye Mighty, and despair!' + Of that colossal wreck, boundless and bare diff --git a/t/basic.t b/t/basic.t deleted file mode 100644 index c34ca6e3..00000000 --- a/t/basic.t +++ /dev/null @@ -1,25 +0,0 @@ -#!perl - -use strict; -use warnings; -use lib 't'; - -use Util; -use Test::More tests => 5; - -prep_environment(); - - -my @tests = read_tests( 't/basic.yaml' ); - -for my $test ( @tests ) { - subtest $test->{name} => sub () { - for my $args ( @{$test->{args}} ) { - my @results = run_ack( @{$args} ); - lists_match( \@results, $test->{output}, $test->{name} ); - } - }; -} - - -exit 0; diff --git a/t/basic.yaml b/t/basic.yaml index d14280c7..18001e46 100644 --- a/t/basic.yaml +++ b/t/basic.yaml @@ -1,22 +1,19 @@ --- name: No switches, one directory args: consecrated t/text -rc: 0 -output: | +stdout: | t/text/gettysburg.txt:14:struggled here, have consecrated it, far above our poor power to add or --- name: No switches, one file args: strict t/swamp/options.pl -rc: 0 -output: | +stdout: | use strict; --- name: No switches, multiple files args: strict t/text/constitution.txt t/swamp/pipe-stress-freaks.F t/swamp/options.pl -rc: 0 -output: | +stdout: | t/text/constitution.txt:225:such District (not exceeding ten Miles square) as may, by Cession of t/swamp/options.pl:2:use strict; @@ -25,8 +22,7 @@ name: With inclusion switch args: - strict -H t/swamp/options.pl - strict --with-filename t/swamp/options.pl -rc: 0 -output: | +stdout: | t/swamp/options.pl:2:use strict; --- @@ -34,6 +30,5 @@ name: With exclusion switch, multiple files args: - strict -h t/swamp/options.pl t/swamp/crystallography-weenies.f - strict --no-filename t/swamp/options.pl t/swamp/crystallography-weenies.f -rc: 0 -output: | +stdout: | use strict; diff --git a/t/run_test.py b/t/run_test.py new file mode 100644 index 00000000..776d594f --- /dev/null +++ b/t/run_test.py @@ -0,0 +1,51 @@ +import glob +import yaml +import subprocess + + +def test_via_yaml_data(): + filenames = glob.glob("t/*.yaml") + for filename in filenames: + with open(filename, "r") as f: + tests = yaml.load_all(f, yaml.FullLoader) + for test in tests: + test = massage_test(test) + run_test(test) + + +def massage_test(test: dict): + if "exitcode" not in test: + test["exitcode"] = 0 + + # Make an array of args arrays out of it if it"s not already. + if not isinstance(test["args"], list): + test["args"] = [test["args"]] + + return test + + +def sorted_output(block: str): + if block: + return sorted([x.rstrip() for x in block.split("\n")]) + + return None + + +def run_test(test): + for args in test["args"]: + args = args.split() + command = ["perl", "-Mblib", "ack", "--noenv"] + args + result = subprocess.run( + command, capture_output=True, text=True, check=(not test["exitcode"]) + ) + + if test["exitcode"]: + assert result.returncode == test["exitcode"] + + if "ordered" in test and test["ordered"]: + assert result.stdout == test["stdout"] + else: + assert sorted_output(result.stdout) == sorted_output(test["stdout"]) + + +test_via_yaml_data() diff --git a/t/swamp/foo_test.py b/t/swamp/foo_test.py index 919cb190..6a7bb477 100644 --- a/t/swamp/foo_test.py +++ b/t/swamp/foo_test.py @@ -1,6 +1,7 @@ # foo_test.py IS a pytest test, as well as Python. +# This test doesn't test anything meaningful. It's just here for filetype tests. +# But it should pass. -code = 0 - -# This should fail -assert code == 1 +def test_reality(): + code = 1 + assert code == 1 diff --git a/t/swamp/test_foo.py b/t/swamp/test_foo.py index ab599bad..aa6f6f92 100644 --- a/t/swamp/test_foo.py +++ b/t/swamp/test_foo.py @@ -1,6 +1,7 @@ # test_foo.py IS a pytest test, as well as Python. +# This test doesn't test anything meaningful. It's just here for filetype tests. +# But it should pass. -code = 0 - -# This should fail -assert code == 1 +def test_reality(): + code = 1 + assert code == 1 diff --git a/t/yaml.t b/t/yaml.t new file mode 100644 index 00000000..9cc397df --- /dev/null +++ b/t/yaml.t @@ -0,0 +1,38 @@ +#!perl + +use warnings; +use strict; + +use Test::More tests => 10; + +use lib 't'; +use Util; + +prep_environment(); + +MAIN: { + my @yamlfiles = glob( 't/*.yaml' ); + + for my $file ( @yamlfiles ) { + subtest $file => sub () { + my @tests = read_tests( $file ); + + for my $test ( @tests ) { + for my $args ( @{$test->{args}} ) { + subtest $file . ' ' . join( ', ', @{$args} ) => sub { + if ( $test->{ordered} ) { + ack_lists_match( $args, $test->{stdout}, $test->{name} ); + } + else { + ack_sets_match( $args, $test->{stdout}, $test->{name} ); + } + is( get_rc(), $test->{exitcode} ); + } + } + } + }; + } +} + + +exit 0; diff --git a/t/zero.t b/t/zero.t deleted file mode 100644 index 9c5afc8b..00000000 --- a/t/zero.t +++ /dev/null @@ -1,56 +0,0 @@ -#!perl - -=pod - -Long ago there was a problem where ack would ignore a file named -"0" because 0 is a false value in Perl. Here we check to make sure -we don't fall prey to that again. - -=cut - -use warnings; -use strict; - -use Test::More tests => 2; - -use lib 't'; -use Util; - -prep_environment(); - -my $swamp = 't/swamp'; - -my @actual_swamp_perl = map { "$swamp/$_" } qw( - 0 - constitution-100k.pl - Makefile.PL - options.pl - options-crlf.pl - perl.cgi - perl.handler.pod - perl.pl - perl.pm - perl.pod - perl-test.t - perl-without-extension -); - -DASH_F: { - my @args = qw( -f -t perl ); - - ack_sets_match( [ @args, $swamp ], \@actual_swamp_perl, 'DASH_F' ); -} - -DASH_F_CWD: { - my @args = qw( -f -t perl --sort-files ); - - my @swamp_basenames = @actual_swamp_perl; - s{^$swamp/}{} for @swamp_basenames; - - my $wd = getcwd_clean(); - safe_chdir('t/swamp'); - ack_sets_match( [ @args, '.' ], \@swamp_basenames, 'DASH_F_CWD:' ); - safe_chdir($wd); -} - -exit 0; diff --git a/t/zero.yaml b/t/zero.yaml new file mode 100644 index 00000000..d8715cb9 --- /dev/null +++ b/t/zero.yaml @@ -0,0 +1,16 @@ +--- +name: Handle a filename of a literal "0" +args: -f --perl t/swamp +stdout: | + t/swamp/0 + t/swamp/constitution-100k.pl + t/swamp/Makefile.PL + t/swamp/options.pl + t/swamp/options-crlf.pl + t/swamp/perl.cgi + t/swamp/perl.handler.pod + t/swamp/perl.pl + t/swamp/perl.pm + t/swamp/perl.pod + t/swamp/perl-test.t + t/swamp/perl-without-extension diff --git a/tags b/tags index 7c226ce5..dde6d16b 100644 --- a/tags +++ b/tags @@ -29,6 +29,9 @@ ADJACENT_CAPTURE_COLORING t/ack-color.t /^ADJACENT_CAPTURE_COLORING: {$/;" l AFTER t/context.t /^AFTER: {$/;" l AND t/boolean.t /^AND: {$/;" l +AND t/highlighting.t /^ AND: {$/;" l +AND t/highlighting.t /^AND: {$/;" l +AND_AND t/highlighting.t /^ AND_AND: {$/;" l ARG_MULTIPLE_FILES t/ack-output.t /^ARG_MULTIPLE_FILES: {$/;" l App::Ack lib/App/Ack.pm /^package App::Ack;$/;" p App::Ack::ConfigDefault lib/App/Ack/ConfigDefault.pm /^package App::Ack::ConfigDefault;$/;" p @@ -60,7 +63,6 @@ Barfly::Block t/Barfly.pm /^package Barfly::Block;$/;" p CAPTURE_PARSED lib/App/Ack/ConfigLoader.pm /^ CAPTURE_PARSED: {$/;" l CAPTURE_RAW lib/App/Ack/ConfigLoader.pm /^ CAPTURE_RAW: {$/;" l CHARACTER_SUBSTITUTIONS t/ack-output.t /^CHARACTER_SUBSTITUTIONS: {$/;" l -COMBINED_FILTERS t/ack-f.t /^COMBINED_FILTERS: {$/;" l COMBOS_1 t/ack-output.t /^COMBOS_1: {$/;" l COMBOS_2 t/ack-output.t /^COMBOS_2: {$/;" l COMBOS_3 t/ack-output.t /^COMBOS_3: {$/;" l @@ -75,13 +77,11 @@ CONTEXT_OVERLAPPING_COLOR t/context.t /^CONTEXT_OVERLAPPING_COLOR: {$/;" l CONTEXT_OVERLAPPING_COLOR_AFTER t/context.t /^CONTEXT_OVERLAPPING_COLOR_AFTER: {$/;" l CONTEXT_OVERLAPPING_COLOR_BEFORE t/context.t /^CONTEXT_OVERLAPPING_COLOR_BEFORE: {$/;" l COUNT_PRINT0 t/ack-print0.t /^COUNT_PRINT0: {$/;" l -DASH_C t/ack-c.t /^DASH_C: {$/;" l DASH_CAPITAL_L t/ack-l.t /^DASH_CAPITAL_L: {$/;" l DASH_F t/ack-1.t /^DASH_F: {$/;" l DASH_F t/zero.t /^DASH_F: {$/;" l DASH_F_CWD t/zero.t /^DASH_F_CWD: {$/;" l DASH_G t/ack-1.t /^DASH_G: {$/;" l -DASH_HC t/ack-c.t /^DASH_HC: {$/;" l DASH_IGNORE_DIR t/ack-ignore-dir.t /^DASH_IGNORE_DIR: {$/;" l DASH_IGNORE_DIR_IGNORES_RELATIVE_PATHS t/ack-ignore-dir.t /^DASH_IGNORE_DIR_IGNORES_RELATIVE_PATHS: {$/;" l DASH_IGNORE_DIR_MULTIPLE_TIMES t/ack-ignore-dir.t /^DASH_IGNORE_DIR_MULTIPLE_TIMES: {$/;" l @@ -89,7 +89,6 @@ DASH_IGNORE_DIR_WITH_DASH_NOIGNORE_DIR t/ack-ignore-dir.t /^DASH_IGNORE_DIR_WITH DASH_IGNORE_DIR_WITH_SLASH t/ack-ignore-dir.t /^DASH_IGNORE_DIR_WITH_SLASH: {$/;" l DASH_L t/ack-1.t /^DASH_L: {$/;" l DASH_L t/ack-l.t /^DASH_L: {$/;" l -DASH_LC t/ack-c.t /^DASH_LC: {$/;" l DASH_LV t/ack-l.t /^DASH_LV: {$/;" l DASH_NOIGNORE_DIR t/ack-ignore-dir.t /^DASH_NOIGNORE_DIR: {$/;" l DASH_NOIGNORE_DIR_MULTIPLE_TIMES t/ack-ignore-dir.t /^DASH_NOIGNORE_DIR_MULTIPLE_TIMES: {$/;" l @@ -97,14 +96,12 @@ DASH_Q t/build_regex.t /^DASH_Q: {$/;" l DASH_V t/ack-1.t /^DASH_V: {$/;" l DASH_i t/build_regex.t /^DASH_i: {$/;" l DASH_w t/build_regex.t /^DASH_w: {$/;" l -DEFAULT_DIR_EXCLUSIONS t/ack-f.t /^DEFAULT_DIR_EXCLUSIONS: {$/;" l DOLLAR_1 t/ack-output.t /^DOLLAR_1: {$/;" l DOLLAR_UNDERSCORE t/ack-output.t /^DOLLAR_UNDERSCORE: {$/;" l DOUBLE_QUOTES t/ack-output.t /^DOUBLE_QUOTES: {$/;" l DUMP t/ack-dump.t /^DUMP: {$/;" l DUMP t/ack-type-del.t /^DUMP: {$/;" l EXCLUDE_ONLY t/inverted-file-filter.t /^EXCLUDE_ONLY: {$/;" l -EXIT_CODE t/ack-f.t /^EXIT_CODE: {$/;" l FILENAME_SUBSTITUTION_1 t/ack-output.t /^FILENAME_SUBSTITUTION_1 : {$/;" l FILENAME_SUBSTITUTION_2 t/ack-output.t /^FILENAME_SUBSTITUTION_2 : {$/;" l FILENAME_SUBSTITUTION_3 t/ack-output.t /^FILENAME_SUBSTITUTION_3 : {$/;" l @@ -160,21 +157,24 @@ NOIGNORE_DIR_RELATIVE_PATHS t/ack-ignore-dir.t /^NOIGNORE_DIR_RELATIVE_PATHS: {$ NOIGNORE_SUBDIR_WINS t/ack-ignore-dir.t /^NOIGNORE_SUBDIR_WINS: {$/;" l NORMAL_CASE t/ack-v.t /^NORMAL_CASE: {$/;" l NORMAL_COLOR t/ack-color.t /^NORMAL_COLOR: {$/;" l -NOT t/ack-c.t /^NOT: {$/;" l NOT t/boolean.t /^NOT: {$/;" l +NOT t/highlighting.t /^ NOT: {$/;" l +NOT t/highlighting.t /^NOT: {$/;" l +NOT_AGAIN t/highlighting.t /^ NOT_AGAIN: {$/;" l NO_BOOLEANS t/boolean.t /^NO_BOOLEANS: {$/;" l NO_GROUPING t/ack-group.t /^NO_GROUPING: {$/;" l NO_O t/ack-o.t /^NO_O: {$/;" l NO_PAGER t/ack-pager.t /^NO_PAGER: {$/;" l NO_SPECIALS_IN_OUTPUT_EXPRESSION t/ack-output.t /^NO_SPECIALS_IN_OUTPUT_EXPRESSION : {$/;" l NO_SWITCHES_MULTIPLE_FILES t/ack-h.t /^NO_SWITCHES_MULTIPLE_FILES: {$/;" l -NO_SWITCHES_MULTIPLE_FILES t/basic.t /^NO_SWITCHES_MULTIPLE_FILES: {$/;" l -NO_SWITCHES_ONE_DIRECTORY t/basic.t /^NO_SWITCHES_ONE_DIRECTORY: {$/;" l NO_SWITCHES_ONE_FILE t/ack-h.t /^NO_SWITCHES_ONE_FILE: {$/;" l -NO_SWITCHES_ONE_FILE t/basic.t /^NO_SWITCHES_ONE_FILE: {$/;" l NTESTS t/file-permission.t /^use constant NTESTS => 5;$/;" c NUMERIC_SUBSTITUTIONS t/ack-output.t /^NUMERIC_SUBSTITUTIONS: {$/;" l OR t/boolean.t /^OR: {$/;" l +OR t/highlighting.t /^ OR: {$/;" l +OR t/highlighting.t /^OR: {$/;" l +ORIGINAL t/highlighting.t /^ ORIGINAL: {$/;" l +OR_OR t/highlighting.t /^ OR_OR: {$/;" l PAGER t/ack-pager.t /^PAGER: {$/;" l PAGER_ACKRC t/ack-pager.t /^PAGER_ACKRC: {$/;" l PAGER_ACKRC_OVERRIDE t/ack-pager.t /^PAGER_ACKRC_OVERRIDE: {$/;" l @@ -195,7 +195,6 @@ REQUIRE_F_OR_G t/ack-show-types.t /^REQUIRE_F_OR_G: {$/;" l RESTRICTED_DIRECTORIES t/ack-s.t /^RESTRICTED_DIRECTORIES: {$/;" l RUBY_AND_RAKE t/ack-show-types.t /^RUBY_AND_RAKE: {$/;" l RangeFile t/range/rangefile.pm /^package RangeFile;$/;" p -SINGLE_FILE_COUNT t/ack-c.t /^SINGLE_FILE_COUNT: {$/;" l SINGLE_TEXT_MATCH t/ack-1.t /^SINGLE_TEXT_MATCH: {$/;" l SKIP t/ack-passthru.t /^SKIP: {$/;" l SKIP t/file-permission.t /^SKIP: {$/;" l @@ -223,20 +222,18 @@ WITHOUT_S t/ack-s.t /^WITHOUT_S: {$/;" l WITH_COLUMNS t/ack-column.t /^WITH_COLUMNS: {$/;" l WITH_COLUMNS_AND_CONTEXT t/context.t /^WITH_COLUMNS_AND_CONTEXT: {$/;" l WITH_COLUMNS_AND_NOT t/ack-column.t /^WITH_COLUMNS_AND_NOT: {$/;" l -WITH_DASH_V t/ack-c.t /^WITH_DASH_V: {$/;" l WITH_NOT t/ack-v.t /^WITH_NOT: {$/;" l WITH_O t/ack-o.t /^WITH_O: {$/;" l WITH_S t/ack-s.t /^WITH_S: {$/;" l WITH_SWITCHES_MULTIPLE_FILES t/ack-h.t /^WITH_SWITCHES_MULTIPLE_FILES: {$/;" l -WITH_SWITCHES_MULTIPLE_FILES t/basic.t /^WITH_SWITCHES_MULTIPLE_FILES: {$/;" l WITH_SWITCHES_ONE_FILE t/ack-h.t /^WITH_SWITCHES_ONE_FILE: {$/;" l -WITH_SWITCHES_ONE_FILE t/basic.t /^WITH_SWITCHES_ONE_FILE: {$/;" l _argjoin t/boolean.t /^sub _argjoin {$/;" s _big_split t/lowercase.t /^sub _big_split {$/;" s _check t/build_regex.t /^sub _check {$/;" s _check_command_for_taintedness t/Util.pm /^sub _check_command_for_taintedness {$/;" s _check_for_ackrc lib/App/Ack/ConfigFinder.pm /^sub _check_for_ackrc {$/;" s _check_for_mutex_options lib/App/Ack/ConfigLoader.pm /^sub _check_for_mutex_options {$/;" s +_check_it t/highlighting.t /^sub _check_it {$/;" s _check_message t/Util.pm /^sub _check_message {$/;" s _color_cell lib/App/Ack.pm /^sub _color_cell {$/;" s _compare_opts lib/App/Ack/ConfigLoader.pm /^sub _compare_opts {$/;" s @@ -252,6 +249,8 @@ _generate_error_handler lib/App/Ack/Files.pm /^sub _generate_error_handler {$/;" _generate_ignore_dir lib/App/Ack/ConfigLoader.pm /^sub _generate_ignore_dir {$/;" s _get_code_from_file squash /^sub _get_code_from_file {$/;" s _get_good_and_bad t/ack-w.t /^sub _get_good_and_bad {$/;" s +_in t/Util.pm /^sub _in {$/;" s +_lineify t/Util.pm /^sub _lineify {$/;" s _movies_are t/boolean.t /^sub _movies_are {$/;" s _my_program lib/App/Ack.pm /^sub _my_program {$/;" s _options_block lib/App/Ack/ConfigDefault.pm /^sub _options_block {$/;" s @@ -270,11 +269,13 @@ _save_rgb_grid dev/generate-rgb-codes.pl /^sub _save_rgb_grid {$/;" s _show_color_grid lib/App/Ack.pm /^sub _show_color_grid {$/;" s _show_hue_sat_grid dev/generate-rgb-codes.pl /^sub _show_hue_sat_grid {$/;" s _show_rgb_grid lib/App/Ack.pm /^sub _show_rgb_grid {$/;" s +_split_args t/Util.pm /^sub _split_args {$/;" s _test_home_ackrc t/forbidden-options.t /^sub _test_home_ackrc {$/;" s _test_project_ackrc t/forbidden-options.t /^sub _test_project_ackrc {$/;" s _type_handler lib/App/Ack/ConfigLoader.pm /^ sub _type_handler {$/;" s _uninvert_filter lib/App/Ack/ConfigLoader.pm /^sub _uninvert_filter {$/;" s _untaint t/Barfly.pm /^sub _untaint {$/;" s +_validate_test t/Util.pm /^sub _validate_test {$/;" s _where dev/generate-rgb-codes.pl /^sub _where {$/;" s _write_file t/Util.pm /^sub _write_file {$/;" s ack_error_matches t/Util.pm /^sub ack_error_matches {$/;" s @@ -437,6 +438,7 @@ process_args lib/App/Ack/ConfigLoader.pm /^sub process_args {$/;" s range_setup ack /^sub range_setup {$/;" s read_file t/Util.pm /^sub read_file {$/;" s read_rcfile lib/App/Ack/ConfigLoader.pm /^sub read_rcfile {$/;" s +read_tests t/Util.pm /^sub read_tests {$/;" s regex_eq t/Util.pm /^sub regex_eq {$/;" s register_filter lib/App/Ack/Filter.pm /^sub register_filter {$/;" s remove_defaults_and_globals t/noenv.t /^sub remove_defaults_and_globals {$/;" s