Skip to content

Commit

Permalink
Move -k to yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jan 20, 2025
1 parent 91e0d7e commit 5f05bf0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 112 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ t/ack-i.t
t/ack-ignore-dir.t
t/ack-ignore-file.t
t/ack-k.t
t/ack-k.yaml
t/ack-l.t
t/ack-m.t
t/ack-man.t
Expand All @@ -72,6 +73,7 @@ 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
Expand Down
122 changes: 10 additions & 112 deletions t/ack-k.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,124 +3,22 @@
use warnings;
use strict;

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

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 @tests = read_tests( 't/ack-k.yaml' );

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();
for my $test ( @tests ) {
subtest $test->{name} => sub () {
for my $args ( @{$test->{args}} ) {
ack_sets_match( $args, $test->{stdout}, $test->{name} );
is( get_rc(), $test->{exitcode} );
}
};
}

exit 0;
101 changes: 101 additions & 0 deletions t/ack-k.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5f05bf0

Please sign in to comment.