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