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
|
use Test;
use lib "lib";
BEGIN {
# only test if IO::Scalar is available
eval 'require IO::Scalar;' or do {
plan tests => 0;
warn "IO::Scalar not available: test skipped.\n";
exit;
};
plan tests => 2
};
use Parse::Syslog;
use IO::Scalar;
my $data = <<END;
Aug 12 06:55:06 hathi [LOG_NOTICE] sshd[1966]: error
END
my $file = IO::Scalar->new(\$data);
my $parser = Parse::Syslog->new($file, year=>2001);
ok(1);
$sl = $parser->next;
my $is = '';
$is .= "time : ".(localtime($sl->{timestamp}))."\n";
$is .= "host : $sl->{host}\n";
$is .= "program : $sl->{program}\n";
$is .= "pid : ".(defined $sl->{pid} ? $sl->{pid} : 'undef')."\n";
$is .= "text : $sl->{text}\n";
#print "$is";
my $shouldbe = <<END;
time : Sun Aug 12 06:55:06 2001
host : hathi
program : sshd
pid : 1966
text : error
END
ok($is, $shouldbe);
# vim: ft=perl
|