This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
157ac249aab65de7173c366a17b97e29af42d976
[perl5.git] / t / op / lex.t
1 #!perl
2 use strict;
3 use warnings;
4
5 require './test.pl';
6
7 plan(tests => 7);
8
9 {
10     no warnings 'deprecated';
11     print <<;   # Yow!
12 ok 1
13
14     # previous line intentionally left blank.
15
16     my $yow = "ok 2";
17     print <<;   # Yow!
18 $yow
19
20     # previous line intentionally left blank.
21 }
22
23 curr_test(3);
24
25
26 {
27     my %foo = (aap => "monkey");
28     my $foo = '';
29     is("@{[$foo{'aap'}]}", 'monkey', 'interpolation of hash lookup with space between lexical variable and subscript');
30     is("@{[$foo {'aap'}]}", 'monkey', 'interpolation of hash lookup with space between lexical variable and subscript - test for [perl #70091]');
31
32 # Original bug report [perl #70091]
33 #  #!perl
34 #  use warnings;
35 #  my %foo;
36 #  my $foo = '';
37 #  (my $tmp = $foo) =~ s/^/$foo {$0}/e;
38 #  __END__
39 #
40 #  This program causes a segfault with 5.10.0 and 5.10.1.
41 #
42 #  The space between '$foo' and '{' is essential, which is why piping
43 #  it through perl -MO=Deparse "fixes" it.
44 #
45
46 }
47
48 fresh_perl_is(
49   'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"} } "\N{a}"',
50   'Constant(\N{a}) unknown at - line 1, within string' . "\n"
51  ."Execution of - aborted due to compilation errors.\n",
52    { stderr => 1 },
53   'correct output (and no crash) when charnames cannot load for \N{...}'
54 );
55 fresh_perl_is(
56   'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"};
57           $^H{charnames} = "foo" } "\N{a}"',
58   "Undefined subroutine &main::foo called at - line 2.\n"
59  ."Propagated at - line 2, within string\n"
60  ."Execution of - aborted due to compilation errors.\n",
61    { stderr => 1 },
62   'no crash when charnames cannot load and %^H holds string'
63 );
64 fresh_perl_is(
65   'BEGIN{ ++$_ for @INC{"charnames.pm","_charnames.pm"};
66           $^H{charnames} = \"foo" } "\N{a}"',
67   "Not a CODE reference at - line 2.\n"
68  ."Propagated at - line 2, within string\n"
69  ."Execution of - aborted due to compilation errors.\n",
70    { stderr => 1 },
71   'no crash when charnames cannot load and %^H holds string reference'
72 );