This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: updated patch on the sysread, syswrite for VMS
[perl5.git] / t / op / gv.t
1 #!./perl
2
3 #
4 # various typeglob tests
5 #
6
7 print "1..11\n";
8
9 # type coersion on assignment
10 $foo = 'foo';
11 $bar = *main::foo;
12 $bar = $foo;
13 print ref(\$bar) eq 'SCALAR' ? "ok 1\n" : "not ok 1\n";
14 $foo = *main::bar;
15
16 # type coersion (not) on misc ops
17
18 if ($foo) {
19   print ref(\$foo) eq 'GLOB' ? "ok 2\n" : "not ok 2\n";
20 }
21
22 unless ($foo =~ /abcd/) {
23   print ref(\$foo) eq 'GLOB' ? "ok 3\n" : "not ok 3\n";
24 }
25
26 if ($foo eq '*main::bar') {
27   print ref(\$foo) eq 'GLOB' ? "ok 4\n" : "not ok 4\n";
28 }
29
30 # type coersion on substitutions that match
31 $a = *main::foo;
32 $b = $a;
33 $a =~ s/^X//;
34 print ref(\$a) eq 'GLOB' ? "ok 5\n" : "not ok 5\n";
35 $a =~ s/^\*//;
36 print $a eq 'main::foo' ? "ok 6\n" : "not ok 6\n";
37 print ref(\$b) eq 'GLOB' ? "ok 7\n" : "not ok 7\n";
38
39 # typeglobs as lvalues
40 substr($foo, 0, 1) = "XXX";
41 print ref(\$foo) eq 'SCALAR' ? "ok 8\n" : "not ok 8\n";
42 print $foo eq 'XXXmain::bar' ? "ok 9\n" : "not ok 9\n";
43
44 # returning glob values
45 sub foo {
46   local($bar) = *main::foo;
47   $foo = *main::bar;
48   return ($foo, $bar);
49 }
50
51 ($fuu, $baa) = foo();
52 if (defined $fuu) {
53   print ref(\$fuu) eq 'GLOB' ? "ok 10\n" : "not ok 10\n";
54 }
55
56 if (defined $baa) {
57   print ref(\$baa) eq 'GLOB' ? "ok 11\n" : "not ok 11\n";
58 }
59