Avoid relying on prototypes working for tests to pass. They aren't tested yet.
[p5sagit/p5-mst-13.2.git] / t / comp / opsubs.t
1 #!./perl -Tw
2
3 # Uncomment this for testing, but don't leave it in for "production", as
4 # we've not yet verified that use works.
5 # use strict;
6
7 $|++;
8
9 require "./test.pl";
10
11 plan(tests => 36);
12
13 =pod
14
15 Even if you have a C<sub q{}>, calling C<q()> will be parsed as the
16 C<q()> operator.  Calling C<&q()> or C<main::q()> gets you the function.
17 This test verifies this behavior for nine different operators.
18
19 =cut
20
21 sub m  { return "m-".shift }
22 sub q  { return "q-".shift }
23 sub qq { return "qq-".shift }
24 sub qr { return "qr-".shift }
25 sub qw { return "qw-".shift }
26 sub qx { return "qx-".shift }
27 sub s  { return "s-".shift }
28 sub tr { return "tr-".shift }
29 sub y  { return "y-".shift }
30
31 # m operator
32 can_ok( 'main', "m" );
33 SILENCE_WARNING: { # Complains because $_ is undef
34     local $^W;                 
35     isnt( m('unqualified'), "m-unqualified", "m('unqualified') is oper" );
36 }
37 is( main::m('main'), "m-main", "main::m() is func" );
38 is( &m('amper'), "m-amper", "&m() is func" );
39
40 # q operator
41 can_ok( 'main', "q" );
42 isnt( q('unqualified'), "q-unqualified", "q('unqualified') is oper" );
43 is( main::q('main'), "q-main", "main::q() is func" );
44 is( &q('amper'), "q-amper", "&q() is func" );
45
46 # qq operator
47 can_ok( 'main', "qq" );
48 isnt( qq('unqualified'), "qq-unqualified", "qq('unqualified') is oper" );
49 is( main::qq('main'), "qq-main", "main::qq() is func" );
50 is( &qq('amper'), "qq-amper", "&qq() is func" );
51
52 # qr operator
53 can_ok( 'main', "qr" );
54 isnt( qr('unqualified'), "qr-unqualified", "qr('unqualified') is oper" );
55 is( main::qr('main'), "qr-main", "main::qr() is func" );
56 is( &qr('amper'), "qr-amper", "&qr() is func" );
57
58 # qw operator
59 can_ok( 'main', "qw" );
60 isnt( qw('unqualified'), "qw-unqualified", "qw('unqualified') is oper" );
61 is( main::qw('main'), "qw-main", "main::qw() is func" );
62 is( &qw('amper'), "qw-amper", "&qw() is func" );
63
64 # qx operator
65 can_ok( 'main', "qx" );
66 eval "qx('unqualified'".
67      ($^O eq 'MSWin32' ? " 2>&1)" : ")");
68 SKIP: {
69     skip("external command not portable on VMS", 1) if $^O eq 'VMS';
70     TODO: {
71         local $::TODO = $^O eq 'MSWin32' ? "Tainting of PATH not working of Windows" : $::TODO;
72         like( $@, qr/^Insecure/, "qx('unqualified') doesn't work" );
73     }
74 }
75 is( main::qx('main'), "qx-main", "main::qx() is func" );
76 is( &qx('amper'), "qx-amper", "&qx() is func" );
77
78 # s operator
79 can_ok( 'main', "s" );
80 eval "s('unqualified')";
81 like( $@, qr/^Substitution replacement not terminated/, "s('unqualified') doesn't work" );
82 is( main::s('main'), "s-main", "main::s() is func" );
83 is( &s('amper'), "s-amper", "&s() is func" );
84
85 # tr operator
86 can_ok( 'main', "tr" );
87 eval "tr('unqualified')";
88 like( $@, qr/^Transliteration replacement not terminated/, "tr('unqualified') doesn't work" );
89 is( main::tr('main'), "tr-main", "main::tr() is func" );
90 is( &tr('amper'), "tr-amper", "&tr() is func" );
91
92 # y operator
93 can_ok( 'main', "y" );
94 eval "y('unqualified')";
95 like( $@, qr/^Transliteration replacement not terminated/, "y('unqualified') doesn't work" );
96 is( main::y('main'), "y-main", "main::y() is func" );
97 is( &y('amper'), "y-amper", "&y() is func" );
98
99 =pod
100
101 from irc://irc.perl.org/p5p 2004/08/12
102
103  <kane-xs>  bug or feature?
104  <purl>     You decide!!!!
105  <kane-xs>  [kane@coke ~]$ perlc -le'sub y{1};y(1)'
106  <kane-xs>  Transliteration replacement not terminated at -e line 1.
107  <Nicholas> bug I think
108  <kane-xs>  i'll perlbug
109  <rgs>      feature
110  <kane-xs>  smiles at rgs
111  <kane-xs>  done
112  <rgs>      will be closed at not a bug,
113  <rgs>      like the previous reports of this one
114  <Nicholas> feature being first class and second class keywords?
115  <rgs>      you have similar ones with q, qq, qr, qx, tr, s and m
116  <rgs>      one could say 1st class keywords, yes
117  <rgs>      and I forgot qw
118  <kane-xs>  hmm silly...
119  <Nicholas> it's acutally operators, isn't it?
120  <Nicholas> as in you can't call a subroutine with the same name as an
121             operator unless you have the & ?
122  <kane-xs>  or fqpn (fully qualified package name)
123  <kane-xs>  main::y() works just fine
124  <kane-xs>  as does &y; but not y()
125  <Andy>     If that's a feature, then let's write a test that it continues
126             to work like that.
127
128 =cut