Skip to content

Commit

Permalink
Merge pull request #587 from Varadinsky/test-output
Browse files Browse the repository at this point in the history
Added --output test script #532
  • Loading branch information
hoelzro committed Jan 1, 2016
2 parents 6922664 + 697174a commit efbf766
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions t/ack-output.t
@@ -0,0 +1,84 @@
#!perl -T

use warnings;
use strict;

use Test::More tests => 12;

use lib 't';
use Util;
use File::Next;

prep_environment();

ARG: {
my @expected = (
'Sink, swim, go down with the ship'
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( swim --output=$_ );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Matching line' );
}

MATCH: {
my @expected = (
'swim'
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( swim --output=$& );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Part of a line matching pattern' );
}

PREMATCH: {
my @expected = (
'Sink, '
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( swim --output=$` );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Part of a line preceding match' );
}

POSTMATCH: {
my @expected = (
', go down with the ship'
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( swim --output=$' );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Part of a line that follows match' );
}

SUBPATTERN_MATCH: {
my @expected = (
'Sink-swim-ship'
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( ^(Sink).+(swim).+(ship)$ --output=$1-$2-$3 );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Capturing parentheses match' );
}

INPUT_LINE_NUMBER: {
my @expected = (
'line:3'
);

my @files = qw( t/text/freedom-of-choice.txt );
my @args = qw( swim --output=line:$. );
my @results = run_ack( @args, @files );

lists_match( \@results, \@expected, 'Line number' );
}

0 comments on commit efbf766

Please sign in to comment.