This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #65838] Tests for here-docs without final newlines
[perl5.git] / t / op / heredoc.t
CommitLineData
c8e9f72f
DN
1
2# heredoc.t
3# tests for heredocs besides what is tested in base/lex.t
4BEGIN {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 require './test.pl';
8}
9
10plan (tests => 6);
11#heredoc without newline (#65838)
12$string = <<'HEREDOC';
13testing for 65838
14HEREDOC
15$code = "<<'HEREDOC';\n${string}HEREDOC"; # HD w/o newline, in eval-string
16$hd = eval $code or warn "$@ ---";
17ok($hd eq $string, "no terminating newline in string-eval");
18
19$redirect = <<\REDIR;
20BEGIN {
21 open STDERR, ">&STDOUT" or die "PROBLEM DUPING STDOUT: $!"
22}
23REDIR
24
25chomp (my $chomped_string = $string);
26fresh_perl_is(
27 "print $code",
28 $chomped_string,{},
29 "heredoc at EOF without trailing newline"
30);
31
32# like test 18 from t/base/lex.t but at EOF
33fresh_perl_is(
34 "print <<;\n$string",
35 $chomped_string,{},
36 "blank-terminated heredoc at EOF"
37);
38
39
40# the next three are supposed to fail parsing
41fresh_perl_like(
42 "$redirect print <<HEREDOC;\n$string HEREDOC",
43 qr/find string terminator/, {},
44 "string terminator must start at newline"
45);
46
47fresh_perl_like(
48 "$redirect print <<;\nno more newlines",
49 qr/find string terminator/, {},
50 "empty string terminator still needs a newline"
51);
52
53fresh_perl_like(
54 "$redirect print <<ThisTerminatorIsLongerThanTheData;\nno more newlines",
55 qr/find string terminator/, {},
56 "long terminator fails correctly"
57);
58