"Fossies" - the Fresh Open Source Software Archive

Member "Parse-Syslog-1.10/t/io-stringy.t" (30 Sep 2007, 867 Bytes) of package /linux/privat/old/Parse-Syslog-1.10.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use Test;
    2 use lib "lib";
    3 BEGIN {
    4 	# only test if IO::Scalar is available
    5 	eval 'require IO::Scalar;' or do {
    6 		plan tests => 0;
    7 		warn "IO::Scalar not available: test skipped.\n";
    8 		exit;
    9 	};
   10 	
   11 	plan tests => 2
   12 };
   13 
   14 use Parse::Syslog;
   15 use IO::Scalar;
   16 
   17 my $data = <<END;
   18 Aug 12 06:55:06 hathi [LOG_NOTICE] sshd[1966]: error
   19 END
   20 
   21 my $file = IO::Scalar->new(\$data);
   22 
   23 my $parser = Parse::Syslog->new($file, year=>2001);
   24 
   25 ok(1);
   26 
   27 $sl = $parser->next;
   28 
   29 my $is = '';
   30 $is .= "time    : ".(localtime($sl->{timestamp}))."\n";
   31 $is .= "host    : $sl->{host}\n";
   32 $is .= "program : $sl->{program}\n";
   33 $is .= "pid     : ".(defined $sl->{pid} ? $sl->{pid} : 'undef')."\n";
   34 $is .= "text    : $sl->{text}\n";
   35 #print "$is";
   36 
   37 my $shouldbe = <<END;
   38 time    : Sun Aug 12 06:55:06 2001
   39 host    : hathi
   40 program : sshd
   41 pid     : 1966
   42 text    : error
   43 END
   44 
   45 ok($is, $shouldbe);
   46 
   47 # vim: ft=perl
   48