Skip to content
Newer
Older
100644 98 lines (74 sloc) 2.51 KB
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
1 use v6;
2
3 use Test;
4
1867d4a @moritz update trait tests to current spec, unfudge
moritz authored Dec 14, 2011
5 plan 19;
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
6
7 =begin description
8
9 Testing parameter traits for subroutines
10
11 =end description
12
eda6db1 [t/spec] move smartlinks from POD to ordinary comments
moritz authored Aug 2, 2009
13 # L<S06/"Parameter traits">
14
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
15 my $foo=1;
16
17 # note: many of these errors can be detected at compile time, so need
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
18 # eval_dies_ok instead of dies_ok
d4308c8 [t/spec] another test for ro-ness of arguments.
moritz authored Nov 6, 2008
19 #
20 # test twice, once with assignment and once with increment, rakudo
21 # used to catch the first but not the latter.
22 #
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
23 eval_dies_ok '
97fdbb2 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
moritz authored Nov 6, 2008
24 my $tmp = 1;
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
25 sub mods_param ($x) { $x++; }
97fdbb2 [t/spec] don't rely on a lexicals working in eval() when testing ro-n…
moritz authored Nov 6, 2008
26 mods_param($tmp)
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
27 ',
28 'can\'t modify parameter, constant by default';
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
29
d4308c8 [t/spec] another test for ro-ness of arguments.
moritz authored Nov 6, 2008
30 eval_dies_ok '
31 my $tmp = 1;
32 sub mods_param ($x) { $x = 1; }
33 mods_param($tmp)
34 ',
35 'can\'t modify parameter, constant by default';
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
36
37 # is readonly
db93e89 [t/spec] unmark some passing rakudo tests due to container/value refa…
particle authored Nov 8, 2008
38 eval_dies_ok 'sub mods_param_constant ($x is readonly) { $x++; };
39 mods_param_constant($foo);' ,
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
40 'can\'t modify constant parameter, constant by default';
41
42 sub mods_param_rw ($x is rw) { $x++; }
43 dies_ok { mods_param_rw(1) }, 'can\'t modify constant even if we claim it\'s rw';
44 sub mods_param_rw_does_nothing ($x is rw) { $x; }
45 lives_ok { mods_param_rw_does_nothing(1) }, 'is rw with non-lvalue should autovivify';
46
47 lives_ok { mods_param_rw($foo) }, 'pass by "is rw" doesn\'t die';
48 is($foo, 2, 'pass by reference works');
49
50 #icopy
51 $foo=1;
52 sub mods_param_copy ($x is copy) {$x++;}
53 lives_ok { mods_param_copy($foo) }, 'is copy';
54 is($foo, 1, 'pass by value works');
55
26e3caa [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
moritz authored Sep 29, 2008
56 # same test with default value
57 sub boom ($arg is copy = 0) { $arg++ }
58
59 lives_ok { boom(42) }, "can modify a copy";
60
61
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
62 # is ref
1b911a1 [t/spec] fudged S06-traits/misc.t for rakudo
moritz authored Sep 3, 2008
63 #?rakudo skip 'is ref'
64 {
65 $foo=1;
66 sub mods_param_ref ($x is ref) { $x++; }
67 dies_ok { mods_param_ref(1); }, 'is ref with non-lvalue';
1c0341c [t/spec] Change more Pugs todo flags to fudge commands
kyle authored Jun 19, 2009
68 #?pugs todo
69 lives_ok { mods_param_ref($foo); }, 'is ref with non-lvalue';
70 #?pugs todo
71 is($foo, 2, 'is ref works');
1b911a1 [t/spec] fudged S06-traits/misc.t for rakudo
moritz authored Sep 3, 2008
72 }
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
73
3b8f4d2 [t/spec] Some more tests to exercise <->.
jnthn authored Feb 11, 2009
74
75 # with <-> we should still obey readonly traits
76 {
77 my $anon1 = <-> $a is readonly, $b { $b++ };
78 my $anon2 = <-> $a is readonly, $b { $a++ };
79 my $x = 1;
80 $anon1($x, $x);
81 is($x, 2, '<-> does not override explicit traints (sanity)');
26d9454 @jnthn Unfudging/refudging for <-> fix.
jnthn authored Oct 17, 2012
82 #?rakudo 2 todo 'is readonly does not override'
3b8f4d2 [t/spec] Some more tests to exercise <->.
jnthn authored Feb 11, 2009
83 dies_ok({ $anon2($x, $x) }, '<-> does not override explicit traints');
84 is($x, 2, '<-> does not override explicit traints (sanity)');
85 }
86
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
87
5547d3f [t/spec] Test for RT #60966
kyle authored Jul 9, 2009
88 {
1867d4a @moritz update trait tests to current spec, unfudge
moritz authored Dec 14, 2011
89 try { eval 'my $gack; sub oh_noes( $gack is nonesuch ) { }' };
5547d3f [t/spec] Test for RT #60966
kyle authored Jul 9, 2009
90
91 ok $! ~~ Exception, "Can't use an unknown trait";
92 ok "$!" ~~ /trait/, 'error message mentions trait';
1867d4a @moritz update trait tests to current spec, unfudge
moritz authored Dec 14, 2011
93 #?rakudo todo 'RT 60966'
5547d3f [t/spec] Test for RT #60966
kyle authored Jul 9, 2009
94 ok "$!" ~~ /nonesuch/, 'error message mentions the name of the trait';
95 }
26e3caa [t] merge xx-uncategorized/optional_copy.t into S06-traits/misc.t, an…
moritz authored Sep 29, 2008
96
4ae127a [t] moved sub_parameter_traits to spec/
moritz authored Sep 3, 2008
97 # vim: ft=perl6
Something went wrong with that request. Please try again.