File: command-line-files.t

package info (click to toggle)
ack 2.24-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,704 kB
  • sloc: perl: 8,590; ansic: 21; fortran: 11; makefile: 5; sh: 5
file content (76 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!perl -T

# This file validates behaviors of specifying files on the command line.

use warnings;
use strict;

use Test::More tests => 4;

use lib 't';
use Util;

prep_environment();

my @source_files = map { reslash($_) } qw(
    t/swamp/options-crlf.pl
    t/swamp/options.pl
    t/swamp/options.pl.bak
);

JUST_THE_DIR: {
    my @expected = line_split( <<"HERE" );
$source_files[0]:19:notawordhere
$source_files[1]:19:notawordhere
HERE

    my @files = qw( t/swamp );
    my @args = qw( notaword );

    ack_sets_match( [ @args, @files ], \@expected, q{One hit for specifying a dir} );
}

# Even a .bak file gets searched if you specify it on the command line.
SPECIFYING_A_BAK_FILE: {
    my @expected = line_split( <<"HERE" );
$source_files[1]:19:notawordhere
$source_files[2]:19:notawordhere
HERE

    my @files = qw(
        t/swamp/options.pl
        t/swamp/options.pl.bak
    );
    my @args = qw( notaword );

    ack_sets_match( [ @args, @files ], \@expected, q{Two hits for specifying the file} );
}

FILE_NOT_THERE: {
    my $file = reslash( 't/swamp/perl.pod' );

    my @expected_stderr;

    # I don't care for this, but it's the least of the evils I could think of
    if ( $ENV{'ACK_TEST_STANDALONE'} ) {
        @expected_stderr = line_split( <<'HERE' );
ack: non-existent-file.txt: No such file or directory
HERE
    }
    else {
        @expected_stderr = line_split( <<'HERE' );
ack: non-existent-file.txt: No such file or directory
HERE
    }

    my @expected_stdout = line_split( <<"HERE" );
${file}:3:=head2 There's important stuff in here!
HERE

    my @files = ( 'non-existent-file.txt', $file );
    my @args = qw( head2 );
    my ($stdout, $stderr) = run_ack_with_stderr( @args, @files );

    lists_match( $stderr, \@expected_stderr, q{Error if there's no file} );
    lists_match( $stdout, \@expected_stdout, 'Find the one file that has a hit' );
}