This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't use require in comp/our.t, as require isn't tested yet.
[perl5.git] / t / comp / opsubs.t
CommitLineData
f3ce0eb7 1#!./perl -Tw
02c3ec76 2
f3ce0eb7
NC
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;
520974d5 6
02c3ec76
AL
7$|++;
8
520974d5
JH
9require "./test.pl";
10
11plan(tests => 36);
12
02c3ec76
AL
13=pod
14
15Even if you have a C<sub q{}>, calling C<q()> will be parsed as the
16C<q()> operator. Calling C<&q()> or C<main::q()> gets you the function.
17This test verifies this behavior for nine different operators.
18
19=cut
20
02c3ec76
AL
21sub m { return "m-".shift }
22sub q { return "q-".shift }
23sub qq { return "qq-".shift }
24sub qr { return "qr-".shift }
25sub qw { return "qw-".shift }
26sub qx { return "qx-".shift }
27sub s { return "s-".shift }
28sub tr { return "tr-".shift }
29sub y { return "y-".shift }
30
31# m operator
32can_ok( 'main', "m" );
33SILENCE_WARNING: { # Complains because $_ is undef
f3ce0eb7 34 local $^W;
02c3ec76
AL
35 isnt( m('unqualified'), "m-unqualified", "m('unqualified') is oper" );
36}
37is( main::m('main'), "m-main", "main::m() is func" );
38is( &m('amper'), "m-amper", "&m() is func" );
39
40# q operator
41can_ok( 'main', "q" );
42isnt( q('unqualified'), "q-unqualified", "q('unqualified') is oper" );
43is( main::q('main'), "q-main", "main::q() is func" );
44is( &q('amper'), "q-amper", "&q() is func" );
45
46# qq operator
47can_ok( 'main', "qq" );
48isnt( qq('unqualified'), "qq-unqualified", "qq('unqualified') is oper" );
49is( main::qq('main'), "qq-main", "main::qq() is func" );
50is( &qq('amper'), "qq-amper", "&qq() is func" );
51
52# qr operator
53can_ok( 'main', "qr" );
54isnt( qr('unqualified'), "qr-unqualified", "qr('unqualified') is oper" );
55is( main::qr('main'), "qr-main", "main::qr() is func" );
56is( &qr('amper'), "qr-amper", "&qr() is func" );
57
58# qw operator
59can_ok( 'main', "qw" );
60isnt( qw('unqualified'), "qw-unqualified", "qw('unqualified') is oper" );
61is( main::qw('main'), "qw-main", "main::qw() is func" );
62is( &qw('amper'), "qw-amper", "&qw() is func" );
63
64# qx operator
65can_ok( 'main', "qx" );
b7c34493
YO
66eval "qx('unqualified'".
67 ($^O eq 'MSWin32' ? " 2>&1)" : ")");
9994ed7c
RGS
68SKIP: {
69 skip("external command not portable on VMS", 1) if $^O eq 'VMS';
70 TODO: {
f3ce0eb7 71 local $::TODO = $^O eq 'MSWin32' ? "Tainting of PATH not working of Windows" : $::TODO;
9994ed7c
RGS
72 like( $@, qr/^Insecure/, "qx('unqualified') doesn't work" );
73 }
83176b6e 74}
02c3ec76
AL
75is( main::qx('main'), "qx-main", "main::qx() is func" );
76is( &qx('amper'), "qx-amper", "&qx() is func" );
77
78# s operator
79can_ok( 'main', "s" );
80eval "s('unqualified')";
81like( $@, qr/^Substitution replacement not terminated/, "s('unqualified') doesn't work" );
82is( main::s('main'), "s-main", "main::s() is func" );
83is( &s('amper'), "s-amper", "&s() is func" );
84
85# tr operator
86can_ok( 'main', "tr" );
87eval "tr('unqualified')";
88like( $@, qr/^Transliteration replacement not terminated/, "tr('unqualified') doesn't work" );
89is( main::tr('main'), "tr-main", "main::tr() is func" );
90is( &tr('amper'), "tr-amper", "&tr() is func" );
91
92# y operator
93can_ok( 'main', "y" );
94eval "y('unqualified')";
95like( $@, qr/^Transliteration replacement not terminated/, "y('unqualified') doesn't work" );
96is( main::y('main'), "y-main", "main::y() is func" );
97is( &y('amper'), "y-amper", "&y() is func" );
98
99=pod
100
101from 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