File: dst.t

package info (click to toggle)
libparse-syslog-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 252 kB
  • sloc: perl: 333; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,539 bytes parent folder | download | duplicates (7)
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
use lib 'lib';
use Parse::Syslog;
use Test;
use POSIX;
use Time::Local;

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;
	};
	if($Time::Local::VERSION lt '1.07_94') {
		warn "Time::Local too old for DST-switch code to work (is: $Time::Local::VERSION, must be: 1.07_94)";
		plan test => 0;
		exit;
	}

	plan tests => 20
};

$ENV{TZ} = 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00';
POSIX::tzset();

my $data = <<END;
Oct 30 01:40:00 ivr3 bla: bla
Oct 30 02:00:00 ivr3 bla: bla
Oct 30 02:20:00 ivr3 bla: bla
Oct 30 02:40:00 ivr3 bla: bla
Oct 30 02:59:58 ivr3 bla: bla
Oct 30 02:00:00 ivr3 bla: bla
Oct 30 02:20:00 ivr3 bla: bla
Oct 30 02:40:00 ivr3 bla: bla
Oct 30 03:00:00 ivr3 bla: bla
Oct 30 03:20:00 ivr3 bla: bla
END

my $file = IO::Scalar->new(\$data);

my $parser = Parse::Syslog->new($file, year=>2005);

my $result = <<END;
Sun Oct 30 01:40:00 2005
Sun Oct 30 02:00:00 2005
Sun Oct 30 02:20:00 2005
Sun Oct 30 02:40:00 2005
Sun Oct 30 02:59:58 2005
Sun Oct 30 02:00:00 2005
Sun Oct 30 02:20:00 2005
Sun Oct 30 02:40:00 2005
Sun Oct 30 03:00:00 2005
Sun Oct 30 03:20:00 2005
END
my @result = split(/\n/, $result);

my $last_t=0;
while(my $sl = $parser->next) {
	# check that we get the correct localtime where a timewarp is noticeable
	# but always an increasing timestamp
	my $lt = localtime($sl->{timestamp});
	ok($lt, shift @result);
	ok($sl->{timestamp} > $last_t);
	$last_t = $sl->{timestamp};
}

# vim: ft=perl