"Fossies" - the Fresh Open Source Software Archive 
Member "Tk-804.036/t/after.t" (15 Nov 2013, 1324 Bytes) of package /linux/misc/Tk-804.036.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 my $divisor;
2 use Test::More (tests => 6);
3 use Tk;
4 use strict;
5 BEGIN {
6 eval 'use Time::HiRes qw(time)';
7 $divisor = $@ ? 1 : 10;
8 }
9 my $mw = MainWindow->new;
10 $mw->withdraw;
11 my $start = time;
12
13 local $TODO;
14 if ($^O =~ m{^(MSWin32|cygwin)$}) {
15 $TODO = "May fail on Windows-like systems, see https://rt.cpan.org/Ticket/Display.html?id=57009";
16 }
17
18 $mw->after(1000/$divisor,sub { my $t = time;
19 isnt($t,$start);
20 my $expected_min = $start+1/$divisor;
21 my $expected_max = $start+3/$divisor;
22 cmp_ok($t, ">=", $expected_min, "short after: $t >= $expected_min");
23 if ($t <= $expected_max) {
24 pass("$t <= $expected_max");
25 } else {
26 local $TODO = "Probably loaded machine";
27 fail("$t is not <= $expected_max");
28 }
29 });
30 $mw->after(2000/$divisor,sub { my $t = time;
31 my $expected_min = $start+2/$divisor;
32 my $expected_max = $start+4/$divisor;
33 cmp_ok($t, ">=", $expected_min, "longer after: $t >= $expected_min");
34 if ($t <= $expected_max) {
35 pass("$t <= $expected_max");
36 } else {
37 local $TODO = "Probably loaded machine";
38 fail("$t is not <= $expected_max");
39 }
40 });
41 $mw->after(3000/$divisor,[destroy => $mw ]);
42 MainLoop;
43 cmp_ok(time, ">=", $start+3/$divisor);
44