This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
heredoc.t: Suppress deprecation warnings
[perl5.git] / t / op / heredoc.t
CommitLineData
c8e9f72f 1# tests for heredocs besides what is tested in base/lex.t
c49688b0 2
c8e9f72f
DN
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
c49688b0
MS
9use strict;
10plan(tests => 6);
11
12
13# heredoc without newline (#65838)
14{
15 my $string = <<'HEREDOC';
c8e9f72f
DN
16testing for 65838
17HEREDOC
c8e9f72f 18
c49688b0
MS
19 my $code = "<<'HEREDOC';\n${string}HEREDOC"; # HD w/o newline, in eval-string
20 my $hd = eval $code or warn "$@ ---";
21 is($hd, $string, "no terminating newline in string-eval");
22}
23
24
25# here-doc edge cases
26{
27 my $string = "testing for 65838";
28
29 fresh_perl_is(
30 "print <<'HEREDOC';\n${string}\nHEREDOC",
31 $string,
32 {},
33 "heredoc at EOF without trailing newline"
34 );
35
36 fresh_perl_is(
37 "print <<;\n$string\n",
38 $string,
3f29db7f 39 { switches => ['-X'] },
c49688b0
MS
40 "blank-terminated heredoc at EOF"
41 );
c8e9f72f 42}
c8e9f72f 43
c49688b0
MS
44
45# here-doc parse failures
46{
47 fresh_perl_like(
48 "print <<HEREDOC;\nwibble\n HEREDOC",
49 qr/find string terminator/,
50 {},
51 "string terminator must start at newline"
52 );
53
54 fresh_perl_like(
55 "print <<;\nno more newlines",
56 qr/find string terminator/,
3f29db7f 57 { switches => ['-X'] },
c49688b0
MS
58 "empty string terminator still needs a newline"
59 );
60
61 fresh_perl_like(
62 "print <<ThisTerminatorIsLongerThanTheData;\nno more newlines",
63 qr/find string terminator/,
64 {},
65 "long terminator fails correctly"
66 );
67}