File: test.t

package info (click to toggle)
libtest-mocktime-perl 0.09-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 68 kB
  • ctags: 9
  • sloc: perl: 212; makefile: 15
file content (58 lines) | stat: -rwxr-xr-x 2,098 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/perl 

use Test::MockTime();
use Test::More(tests => 11);
use Time::Local();
use strict;
use warnings;

my ($mock, $real);
$mock = time;
$real = CORE::time;
ok(($mock == $real) || (($mock + 1) == $real) || (($mock - 1) == $real), "Starting time " . localtime($mock)); # previous two statements might go over a second boundary
Test::MockTime::set_relative_time(-600);
$mock = time;
$real = CORE::time;
sleep 2;
$mock = time;
$mock += 600;
$real = CORE::time;
ok(($mock == $real) || (($mock + 1) == $real) || (($mock - 1) == $real), "Set time to be 10 minutes ago, slept for two seconds, time was still in sync");
$mock = Time::Local::timelocal(localtime);
$real = Time::Local::timelocal(CORE::localtime);
$mock = $mock + 600;
ok(($mock == $real) || (($mock + 1) == $real) || (($mock - 1) == $real), "localtime was also still in sync");
Test::MockTime::set_relative_time(+2);
$mock = time;
$real = CORE::time;
sleep 2;
$mock = time;
$real = CORE::time;
ok($mock >= ($real + 1), "Set time to be 2 seconds in the future, slept for three seconds, time was still in front");
$mock = Time::Local::timelocal(localtime);
$real = Time::Local::timelocal(CORE::localtime);
ok($mock >= ($real + 1), "localtime was also still in front");
Test::MockTime::set_absolute_time(100);
$mock = time;
ok(($mock >= 100) && ($mock <= 101), "Absolute time works");
sleep 2;
$mock = time;
ok(($mock >= 102) && ($mock <= 103), "Absolute time is still in sync after two seconds sleep:$mock");
$mock = Time::Local::timelocal(localtime);
$real = Time::Local::timelocal(CORE::localtime);
ok($mock <= $real, "localtime seems ok");
Test::MockTime::set_fixed_time(CORE::time);
$real = time;
sleep 2;
$mock = time;
ok($mock == $real, "fixed time correctly");
Test::MockTime::set_fixed_time(CORE::time);
$mock = Time::Local::timelocal(localtime());
sleep 2;
$real = Time::Local::timelocal(localtime);
ok($mock eq $real, "fixed localtime correctly");
Test::MockTime::set_fixed_time(CORE::time);
$mock = Time::Local::timegm(gmtime);
sleep 2;
$real = Time::Local::timegm(gmtime);
ok($mock eq $real, "fixed gmtime correctly");