File: 20debug.t

package info (click to toggle)
libregexp-log-perl 0.06-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 140 kB
  • sloc: perl: 144; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (4)
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
use Test::More tests => 8;
use t::Foo;
use re 'eval';

my $foo = Regexp::Log::Foo->new();

# test the accessor
ok( ! $foo->debug, "No debug by default" );
$foo->debug(1);
ok( $foo->debug == 1 , "Debug set" );

@ARGV = ('t/foo1.log');
$foo->format("%a %b %c %d");

my @fields = $foo->capture;
my $regexp = $foo->regexp;

# swap errputs
my $file = "t/.test.$$";
open OLDERR, ">&STDERR"
      or die "fatal: could not duplicate STDERR: $!";
close STDERR;
open STDERR, "> $file"
      or die "fatal: could not open temporary errput file $file: $!"; 

# debug data should go to the file
while(<>) {
    my %data;
    @data{@fields} = /$regexp/;
}

# put things back to normal
close STDERR;
open STDERR, ">&OLDERR"
  or die "fatal: could not duplicate STDERR: $!";
close(OLDERR);

@ARGV = ($file);
is( <>, "\n",               "First line is empty" );
is( <>, "a b cs cn c d \n", "Debug for a match" );
is( <>, "a b cs cn c d \n", "Debug for a match" );
is( <>, "a b cs cn c d \n", "Debug for a match" );

# Perl 5.6 and Perl 5.8 backtrack differently!
if ( $] >= 5.008 ) {
    is( <>, "a \n", "Debug for non-match" );
}
else {
    is( <>, "a a \n", "Debug for non-match" );
}

is( <>, "a b cs cn c d ", "Debug for a match" );
close ARGV;

# cleanup files
unlink $file or diag "Could not remove $file: $!";