Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (56 sloc) 2.317 kb
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
1 use v6;
2 use Test;
8e9ba37 @TimToady return should not fallback to dynamic
TimToady authored
3 plan 18;
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
4
5 # Is there a better reference for the spec for how return return works?
6 # There is "return function" but that's a more advanced feature.
7 #L<S04/"Control Exceptions">
8
9 =begin pod
10
11 Basic tests for "return"
12
13 =end pod
14
15 sub bar { return }
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and…
pmichaud authored
16 is(bar(), Nil, '... bare return statement returned Nil');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
17
18 sub bar2 { return() }
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and…
pmichaud authored
19 is(bar2(), Nil, '... bare return statement w/ parens returned Nil');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
20
21 sub baz { return 10 if 1; }
8a5722b [t/spec] fixed return.t
moritz authored
22 is(baz(), 10, '... return worked with a statement modifier');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
23
24 sub foobar { return if 1; };
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and…
pmichaud authored
25 is(foobar(), Nil, '... bare return worked with a statement modifier');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
26
27 sub foobar2 { return() if 1; }
62e2e2f [t/spec]: Clean up (and unfudge) some tests involving Nil, sink, and…
pmichaud authored
28 is(foobar2(), Nil, '... bare return worked with a statement modifier');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
29
30 my $should_ret_empty_list1 = sub { return; 1 };
253374f More rakudo list-branch related updates.
pmichaud authored
31 is $should_ret_empty_list1().elems, 0, "our sub returned an empty list (1)";
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
32
33 sub return_1 { return 1; }
34 is(return_1(), 1, '... return_1() returned 1 correctly');
35
36 is( try { sub foo { my $x = 1; while $x-- { return 24; }; return 42; }; foo() }, 24, 'return in while');
37
38 # S04: "A return always exits from the lexically surrounding sub or method definition"
39 {
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
40 eval-dies-ok('return 1', 'bare return fails');
41 eval-dies-ok('for 1 {return 2}', 'cannot return out of a bare for block');
42 eval-dies-ok('my $i = 1; while $i-- {return 3}', 'cannot return out of a bare while');
43 eval-dies-ok('my $i = 0; until $i++ {return 4}', 'cannot return out of a bare until');
44 eval-dies-ok('loop (my $i = 0; $i < 1; $i++) {return 5}', 'cannot return out of a bare loop');
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
45 # XXX: Not 100% sure on this one
0cbc065 @lizmat s/eval_dies_ok/eval-dies-ok/g
lizmat authored
46 eval-dies-ok('do {return 5}', 'cannot return out of a do block');
8e9ba37 @TimToady return should not fallback to dynamic
TimToady authored
47
ba89213 @moritz fudge new test for rakudo
moritz authored
48 #?rakudo todo 'lexotic return'
8e9ba37 @TimToady return should not fallback to dynamic
TimToady authored
49 is (try EVAL 'my $double = -> $x { return 2 * $x }; sub foo($x) { $double($x) }; foo 42').defined, False, 'return is lexotic only; must not attempt dynamic return';
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
50 }
51
d72968b [t] moved tests around, merged single test into another file
moritz authored
52 {
53 sub list_return { return (42, 1) }
54 my $bar = ~list_return();
55 is($bar, '42 1', 'Should not return empty string');
56 }
57
dec32f3 @moritz RT #81962, re-binding my &return
moritz authored
58 # RT #81962
59 {
60 my $tracker = '';
61 my &r = &return;
62 sub f {
63 my &return := -> $v {
64 $tracker ~= 'LOL';
65 &r($v * 2);
66 };
67 return(21);
68 }
69 is f(), 42, 'proxied return produces the correct value';
70 is $tracker, 'LOL', 'proxied return produced the right side effect';
71 }
72
fa3a8b0 [gsoc_spectest] added tests to return.t and fudged for rakudo. (added…
Auzon authored
73 # vim: ft=perl6
Something went wrong with that request. Please try again.