Two Cygwin patches from Gerrit.
[p5sagit/p5-mst-13.2.git] / t / comp / parser.t
CommitLineData
923be969 1#!./perl
2
3# Checks if the parser behaves correctly in edge cases
4# (including weird syntax errors)
5
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9}
10
f15b33d3 11require "./test.pl";
a40a317b 12plan( tests => 39 );
f15b33d3 13
14eval '%@x=0;';
15like( $@, qr/^Can't modify hash dereference in repeat \(x\)/, '%@x=0' );
16
17# Bug 20010422.005
18eval q{{s//${}/; //}};
19like( $@, qr/syntax error/, 'syntax error, used to dump core' );
20
21# Bug 20010528.007
22eval q/"\x{"/;
23like( $@, qr/^Missing right brace on \\x/,
24 'syntax error in string, used to dump core' );
25
26eval "a.b.c.d.e.f;sub";
27like( $@, qr/^Illegal declaration of anonymous subroutine/,
28 'found by Markov chain stress testing' );
29
30# Bug 20010831.001
31eval '($a, b) = (1, 2);';
32like( $@, qr/^Can't modify constant item in list assignment/,
33 'bareword in list assignment' );
34
35eval 'tie FOO, "Foo";';
36like( $@, qr/^Can't modify constant item in tie /,
37 'tying a bareword causes a segfault in 5.6.1' );
38
39eval 'undef foo';
40like( $@, qr/^Can't modify constant item in undef operator /,
41 'undefing constant causes a segfault in 5.6.1 [ID 20010906.019]' );
42
43eval 'read($bla, FILE, 1);';
44like( $@, qr/^Can't modify constant item in read /,
45 'read($var, FILE, 1) segfaults on 5.6.1 [ID 20011025.054]' );
923be969 46
47# This used to dump core (bug #17920)
48eval q{ sub { sub { f1(f2();); my($a,$b,$c) } } };
f15b33d3 49like( $@, qr/error/, 'lexical block discarded by yacc' );
961ce445 50
51# bug #18573, used to corrupt memory
52eval q{ "\c" };
53like( $@, qr/^Missing control char name in \\c/, q("\c" string) );
8edd5f42 54
a40a317b 55eval q{ qq(foo$) };
56like( $@, qr/Final \$ should be \\\$ or \$name/, q($ at end of "" string) );
57
8edd5f42 58# two tests for memory corruption problems in the said variables
59# (used to dump core or produce strange results)
60
61is( "\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q\Q\Qa", "a", "PL_lex_casestack" );
62
63eval {
64{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
65{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
66{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
67}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
68}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
69}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
70};
71is( $@, '', 'PL_lex_brackstack' );
437fd210 72
73{
7df0d042 74 # tests for bug #20716
75 undef $a;
76 undef @b;
77 my $a="A";
78 is("${a}{", "A{", "interpolation, qq//");
79 is("${a}[", "A[", "interpolation, qq//");
80 my @b=("B");
81 is("@{b}{", "B{", "interpolation, qq//");
82 is(qr/${a}{/, '(?-xism:A{)', "interpolation, qr//");
83 my $c = "A{";
84 $c =~ /${a}{/;
85 is($&, 'A{', "interpolation, m//");
86 $c =~ s/${a}{/foo/;
87 is($c, 'foo', "interpolation, s/...//");
88 $c =~ s/foo/${a}{/;
89 is($c, 'A{', "interpolation, s//.../");
90 is(<<"${a}{", "A{ A[ B{\n", "interpolation, here doc");
91${a}{ ${a}[ @{b}{
92${a}{
437fd210 93}
4a202259 94
0f5d0394 95eval q{ sub a(;; &) { } a { } };
96is($@, '', "';&' sub prototype confuses the lexer");
97
4a202259 98# Bug #21575
99# ensure that the second print statement works, by playing a bit
100# with the test output.
101my %data = ( foo => "\n" );
102print "#";
103print(
104$data{foo});
105pass();
abc667d1 106
107# Bug #21875
108# { q.* => ... } should be interpreted as hash, not block
109
110foreach my $line (split /\n/, <<'EOF')
1111 { foo => 'bar' }
1121 { qoo => 'bar' }
1131 { q => 'bar' }
1141 { qq => 'bar' }
1150 { q,'bar', }
1160 { q=bar= }
1170 { qq=bar= }
1181 { q=bar= => 'bar' }
119EOF
120{
121 my ($expect, $eval) = split / /, $line, 2;
122 my $result = eval $eval;
123 ok($@ eq '', "eval $eval");
124 is(ref $result, $expect ? 'HASH' : '', $eval);
125}