File: after.t

package info (click to toggle)
perl-tk 1%3A804.036%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,284 kB
  • sloc: ansic: 349,560; perl: 52,292; sh: 12,678; makefile: 5,700; asm: 3,565; ada: 1,681; pascal: 1,082; cpp: 1,006; yacc: 883; cs: 879
file content (44 lines) | stat: -rwxr-xr-x 1,324 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
my $divisor;
use Test::More (tests => 6);
use Tk;
use strict;
BEGIN {
    eval 'use Time::HiRes qw(time)';
    $divisor = $@ ? 1 : 10;
}
my $mw = MainWindow->new;
$mw->withdraw;
my $start = time;

local $TODO;
if ($^O =~ m{^(MSWin32|cygwin)$}) {
    $TODO = "May fail on Windows-like systems, see https://rt.cpan.org/Ticket/Display.html?id=57009";
}

$mw->after(1000/$divisor,sub { my $t = time;
			       isnt($t,$start);
			       my $expected_min = $start+1/$divisor;
			       my $expected_max = $start+3/$divisor;
			       cmp_ok($t, ">=", $expected_min, "short after: $t >= $expected_min");
			       if ($t <= $expected_max) {
				   pass("$t <= $expected_max");
			       } else {
				   local $TODO = "Probably loaded machine";
				   fail("$t is not <= $expected_max");
			       }
			   });
$mw->after(2000/$divisor,sub { my $t = time;
			       my $expected_min = $start+2/$divisor;
			       my $expected_max = $start+4/$divisor;
			       cmp_ok($t, ">=", $expected_min, "longer after: $t >= $expected_min");
			       if ($t <= $expected_max) {
				   pass("$t <= $expected_max");
			       } else {
				   local $TODO = "Probably loaded machine";
				   fail("$t is not <= $expected_max");
			       }
			   });
$mw->after(3000/$divisor,[destroy => $mw ]);
MainLoop;
cmp_ok(time, ">=", $start+3/$divisor);