Skip to content

Commit

Permalink
Hoist tests into YAML files
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jan 21, 2025
1 parent feaa4e5 commit 9484c28
Show file tree
Hide file tree
Showing 29 changed files with 628 additions and 877 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ nytprof.out
/_eumm/
ack-standalone
*~
__pycache__
17 changes: 7 additions & 10 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
74 changes: 62 additions & 12 deletions t/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
24 changes: 0 additions & 24 deletions t/ack-c.t

This file was deleted.

24 changes: 10 additions & 14 deletions t/ack-c.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
85 changes: 0 additions & 85 deletions t/ack-column.t

This file was deleted.

45 changes: 45 additions & 0 deletions t/ack-column.yaml
Original file line number Diff line number Diff line change
@@ -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!
Loading

0 comments on commit 9484c28

Please sign in to comment.