Skip to content

Commit

Permalink
Hoist data into YAML file separate from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jan 20, 2025
1 parent 1b76d21 commit 73fd463
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 97 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
History file for ack 3. https://beyondgrep.com/

NEXT
========================================
ack now needs YAML::PP to run its tests.


v3.8.1 Tue Dec 31 21:22:59 CST 2024
========================================
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ t/ack-column.t
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
t/ack-group.t
Expand Down
3 changes: 3 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ my %parms = (
'version' => 0,
( $^O eq 'MSWin32' ? ('Win32::ShellQuote' => '0.002001') : () ),
},
TEST_REQUIRES => {
'YAML::PP' => 0,
},
MAN3PODS => {}, # no need for man pages for any of the .pm files
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'ack-3* nytprof* stderr.log stdout.log completion.*' },
Expand Down
24 changes: 24 additions & 0 deletions t/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use File::Temp ();
use Scalar::Util qw( tainted );
use Term::ANSIColor ();
use Test::More;
use YAML::PP;

our @EXPORT = qw(
prep_environment
Expand Down Expand Up @@ -77,6 +78,8 @@ our @EXPORT = qw(
subtest_name
permutate
read_tests
);

my $orig_wd;
Expand Down Expand Up @@ -1275,4 +1278,25 @@ sub list_with_x_first {
}


sub read_tests {
my $filename = shift;

my $ypp = YAML::PP->new;
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->{args} = [ split( / /, $test->{args} ) ];
}

return @tests;
}


1;
105 changes: 8 additions & 97 deletions t/ack-f.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,21 @@
use warnings;
use strict;

use Test::More tests => 6;
use Test::More tests => 3;

use lib 't';
use Util;

prep_environment();

DEFAULT_DIR_EXCLUSIONS: {
my @expected = ( qw(
t/swamp/0
t/swamp/c-header.h
t/swamp/c-source.c
t/swamp/constitution-100k.pl
t/swamp/crystallography-weenies.f
t/swamp/example.R
t/swamp/file.bar
t/swamp/file.foo
t/swamp/foo_test.py
t/swamp/fresh.css
t/swamp/groceries/another_subdir/fruit
t/swamp/groceries/another_subdir/junk
t/swamp/groceries/another_subdir/meat
t/swamp/groceries/dir.d/fruit
t/swamp/groceries/dir.d/junk
t/swamp/groceries/dir.d/meat
t/swamp/groceries/fruit
t/swamp/groceries/junk
t/swamp/groceries/meat
t/swamp/groceries/subdir/fruit
t/swamp/groceries/subdir/junk
t/swamp/groceries/subdir/meat
t/swamp/html.htm
t/swamp/html.html
t/swamp/incomplete-last-line.txt
t/swamp/javascript.js
t/swamp/lua-shebang-test
t/swamp/Makefile
t/swamp/Makefile.PL
t/swamp/MasterPage.master
t/swamp/notaMakefile
t/swamp/notaRakefile
t/swamp/notes.md
t/swamp/options-crlf.pl
t/swamp/options.pl
t/swamp/perl-test.t
t/swamp/perl-without-extension
t/swamp/perl.cgi
t/swamp/perl.handler.pod
t/swamp/perl.pl
t/swamp/perl.pm
t/swamp/perl.pod
t/swamp/pipe-stress-freaks.F
t/swamp/Rakefile
t/swamp/Sample.ascx
t/swamp/Sample.asmx
t/swamp/sample.asp
t/swamp/sample.aspx
t/swamp/sample.rake
t/swamp/service.svc
t/swamp/stuff.cmake
t/swamp/test_foo.py
t/swamp/test.py
t/swamp/CMakeLists.txt
t/swamp/swamp/ignoreme.txt
),
't/swamp/not-an-#emacs-workfile#',
);
my @tests = read_tests( 't/ack-f.yaml' );

my @args = qw( -f t/swamp );

ack_sets_match( [ @args ], \@expected, 'DEFAULT_DIR_EXCLUSIONS' );
is( get_rc(), 0, '-f with matches exits with 0' );
}

COMBINED_FILTERS: {
my @expected = qw(
t/swamp/0
t/swamp/constitution-100k.pl
t/swamp/perl.pm
t/swamp/Rakefile
t/swamp/options-crlf.pl
t/swamp/options.pl
t/swamp/perl-without-extension
t/swamp/perl.cgi
t/swamp/Makefile.PL
t/swamp/perl-test.t
t/swamp/perl.handler.pod
t/swamp/perl.pl
t/swamp/perl.pod
);

my @args = qw( -f t/swamp -t perl -t rake );

ack_sets_match( [ @args ], \@expected, 'COMBINED_FILTERS' );
is( get_rc(), 0, '-f with matches exits with 0' );
for my $test ( @tests ) {
subtest $test->{name} => sub () {
ack_sets_match( $test->{args}, $test->{output}, $test->{name} );
is( get_rc(), $test->{rc} );
};
}

EXIT_CODE: {
my @expected;

my @args = qw( -f t/swamp --type-add=baz:ext:baz -t baz );

ack_sets_match( \@args, \@expected, 'EXIT_CODE' );
is( get_rc(), 1, '-f with no matches exits with 1' );
}

done_testing();
exit 0;
86 changes: 86 additions & 0 deletions t/ack-f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
name: Default directory exclusions
args: -f t/swamp
rc: 0
output: |
t/swamp/0
t/swamp/c-header.h
t/swamp/c-source.c
t/swamp/constitution-100k.pl
t/swamp/crystallography-weenies.f
t/swamp/example.R
t/swamp/file.bar
t/swamp/file.foo
t/swamp/foo_test.py
t/swamp/fresh.css
t/swamp/groceries/another_subdir/fruit
t/swamp/groceries/another_subdir/junk
t/swamp/groceries/another_subdir/meat
t/swamp/groceries/dir.d/fruit
t/swamp/groceries/dir.d/junk
t/swamp/groceries/dir.d/meat
t/swamp/groceries/fruit
t/swamp/groceries/junk
t/swamp/groceries/meat
t/swamp/groceries/subdir/fruit
t/swamp/groceries/subdir/junk
t/swamp/groceries/subdir/meat
t/swamp/html.htm
t/swamp/html.html
t/swamp/incomplete-last-line.txt
t/swamp/javascript.js
t/swamp/lua-shebang-test
t/swamp/Makefile
t/swamp/Makefile.PL
t/swamp/MasterPage.master
t/swamp/notaMakefile
t/swamp/notaRakefile
t/swamp/notes.md
t/swamp/options-crlf.pl
t/swamp/options.pl
t/swamp/perl-test.t
t/swamp/perl-without-extension
t/swamp/perl.cgi
t/swamp/perl.handler.pod
t/swamp/perl.pl
t/swamp/perl.pm
t/swamp/perl.pod
t/swamp/pipe-stress-freaks.F
t/swamp/Rakefile
t/swamp/Sample.ascx
t/swamp/Sample.asmx
t/swamp/sample.asp
t/swamp/sample.aspx
t/swamp/sample.rake
t/swamp/service.svc
t/swamp/stuff.cmake
t/swamp/test_foo.py
t/swamp/test.py
t/swamp/CMakeLists.txt
t/swamp/swamp/ignoreme.txt
t/swamp/not-an-#emacs-workfile#
---
name: Combined filters
args: -f t/swamp -t perl -t rake
rc: 0
output: |
t/swamp/0
t/swamp/constitution-100k.pl
t/swamp/perl.pm
t/swamp/Rakefile
t/swamp/options-crlf.pl
t/swamp/options.pl
t/swamp/perl-without-extension
t/swamp/perl.cgi
t/swamp/Makefile.PL
t/swamp/perl-test.t
t/swamp/perl.handler.pod
t/swamp/perl.pl
t/swamp/perl.pod
---
name: Exit code with no matches
args: "-f t/swamp --type-add=baz:ext:baz -t baz"
rc: 1
output:

0 comments on commit 73fd463

Please sign in to comment.