Skip to content

Commit 693cdad

Browse files
committed
Adjusted sleep() related test to new spec implementation
1 parent 4ae1f4c commit 693cdad

File tree

1 file changed

+65
-26
lines changed

1 file changed

+65
-26
lines changed

S29-context/sleep.t

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,77 @@ use Test;
33

44
# L<S29/Context/"=item sleep">
55

6-
plan 12;
6+
plan 21;
7+
8+
my $seconds = 3;
9+
my $nil is default(Nil);
10+
my $b;
711

812
{
9-
diag "Sleeping for 3s";
10-
my $start = time;
11-
my $sleep_says = sleep 3;
12-
my $diff = time - $start;
13+
diag "sleep() for $seconds seconds";
14+
my $start = now;
15+
$nil = sleep $seconds;
16+
my $diff = now - $start;
1317

14-
#?pugs todo
15-
ok( $sleep_says >= 2 , 'Sleep says it slept at least 2 seconds');
16-
ok( $sleep_says <= 10 , '... and no more than 10');
18+
#?pugs todo "NYI"
19+
#?niecza todo "NYI"
20+
ok $nil === Nil , 'sleep() always returns Nil';
1721

18-
ok( $diff >= 2 , 'We actually slept at least 2 seconds');
19-
ok( $diff <= 10 , '... and no more than 10');
20-
} #4
22+
ok $diff >= $seconds - 1 , 'we actually slept at some seconds';
23+
ok $diff <= $seconds + 5 , '... but not too long';
24+
25+
#?pugs 2 skip "NYI"
26+
#?niecza 2 skip "NYI"
27+
$nil = 1;
28+
lives_ok { $nil = sleep(-1) }, "silently ignores negative times";
29+
ok $nil === Nil , 'sleep() always returns Nil';
30+
} #5
31+
32+
#?pugs skip "NYI"
33+
#?niecza skip "NYI"
34+
{
35+
diag "sleep-timer() for $seconds seconds";
36+
my $then = now;
37+
my $left = sleep-timer $seconds;
38+
my $now = now;
39+
40+
isa_ok $left, Duration, 'did we get a Duration back (1)';
41+
ok $now - $then + $seconds >= $left, 'does Duration returned make sense';
2142

22-
#?pugs skip "not yet implemented"
23-
#?niecza todo "not yet implemented"
43+
$left = sleep-timer -1;
44+
isa_ok $left, Duration, 'did we get a Duration back (2)';
45+
is $left, 0, 'no time left to wait';
46+
47+
$left = sleep-timer 0;
48+
isa_ok $left, Duration, 'did we get a Duration back (3)';
49+
is $left, 0, 'no time left to wait either';
50+
} #6
51+
52+
#?pugs skip "NYI"
53+
#?niecza skip "NYI"
2454
{
25-
is interval( 1.5 ), 0, "first call doesn't wait";
26-
my $start = time.Num;
27-
ok 0 <= interval(2.5) < 1.5, "first sleep";
28-
ok 0 <= interval(5 ) < 2.5, "second sleep";
29-
ok 0 <= interval(0 ) < 5 , "third sleep";
30-
is interval(3), 0, "fourth sleep";
31-
ok 0 <= interval(0 ) < 3 , "fifth sleep";
32-
ok 12 <= time.Num - $start <= 15, "some overall time";
33-
} #7
34-
35-
#?pugs todo "not yet implemented"
55+
diag "sleep-till() for $seconds seconds";
56+
my $then = now;
57+
my $slept = sleep-till $then + $seconds;
58+
my $now = now;
59+
60+
isa_ok $slept, Bool, 'did we get a Bool back';
61+
ok $slept, 'did we actually wait';
62+
ok $now - $then + $seconds >= 0, 'does elapsed time make sense';
63+
64+
nok sleep-till($then + $seconds), 'should not actually sleep again';
65+
} #4
66+
67+
#?pugs todo "NYI"
68+
#?niecza todo "NYI"
3669
{
37-
dies_ok( { sleep(-1) }, "cannot go back in time" );
38-
} #1
70+
diag "checking infinite waiting times";
71+
isa_ok eval('$b={sleep(Inf)}'), Block, 'sleep(Inf) compiles';
72+
isa_ok eval('$b={sleep(*)}'), Block, 'sleep(*) compiles';
73+
isa_ok eval('$b={sleep-timer(Inf)}'), Block, 'sleep-timer(Inf) compiles';
74+
isa_ok eval('$b={sleep-timer(*)}'), Block, 'sleep-timer(*) compiles';
75+
isa_ok eval('$b={sleep-till(Inf)}'), Block, 'sleep-till(Inf) compiles';
76+
isa_ok eval('$b={sleep-till(*)}'), Block, 'sleep-till(*) compiles';
77+
} #6
3978

4079
# vim: ft=perl6

0 commit comments

Comments
 (0)