App-dategrep

 view release on metacpan or  search on metacpan

t/01basic.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;
use Test::Output;
use Test::More;
use FindBin qw($Bin);
use lib "$Bin/lib";
use Test::Dategrep;
use POSIX qw(setlocale LC_ALL);

setlocale( LC_ALL, 'C' );

delete $ENV{DATEGREP_DEFAULT_FORMAT};

test_dategrep( ["$Bin/files/empty"], <<'EOF', "Empty files" );
EOF

test_dategrep( [ '--unknown=%Y', "$Bin/files/empty" ],
    <<'EOF', "Unknown parameter" );
Unknown option: unknown
EOF

test_dategrep(
    [
        '--start=32.13.2013',      '--end=01.04.2014',
        '--format=%Y-%m-%d %H:%M', "$Bin/files/empty"
    ],
    <<'EOF', 'unparsable date for --start' );
dategrep: Illegal start time.
EOF

test_dategrep(
    [
        '--end=32.13.2013',        '--start=01.04.2014',
        '--format=%Y-%m-%d %H:%M', "$Bin/files/empty"
    ],
    <<'EOF', 'unparsable date for --end' );
dategrep: Illegal end time.
EOF

test_dategrep(
    [
        '--start=2014-03-23 14:15',
        '--end=2014-03-23 14:17',
        "$Bin/files/does_note_exists.log"
    ],
    <<"EOF", 'access missing file' );
dategrep: Can't open $Bin/files/does_note_exists.log: No such file or directory
EOF

test_dategrep(
    [
        '--start=2014-03-23 14:15',
        '--end=2014-03-23 14:17',
        "$Bin/files/test03.log"
    ],
    <<"EOF", 'Missing date on first line' );
dategrep: No date found in line lalalalalalalalalalala
EOF

# files with line before and after date range
test_dategrep(
    [
        '--format=%Y-%m-%d %H:%M',
        '--start=2014-03-23 14:15',
        '--end=2014-03-23 14:17',
        "$Bin/files/test01.log"
    ],
    <<'EOF', 'files with line before and after date range' );
2014-03-23 14:15 line 1
2014-03-23 14:16 line 1



( run in 0.715 second using v1.01-cache-2.11-cpan-ceb78f64989 )