This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove the port to MiNT. It's a dead platform that hasn't had any love since 5.005
[perl5.git] / t / op / readline.t
1 #!./perl
2
3 BEGIN {
4     chdir 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan tests => 18;
10
11 eval { for (\2) { $_ = <FH> } };
12 like($@, 'Modification of a read-only value attempted', '[perl #19566]');
13
14 {
15   my $file = tempfile();
16   open A,'+>',$file; $a = 3;
17   is($a .= <A>, 3, '#21628 - $a .= <A> , A eof');
18   close A; $a = 4;
19   is($a .= <A>, 4, '#21628 - $a .= <A> , A closed');
20 }
21
22 # 82 is chosen to exceed the length for sv_grow in do_readline (80)
23 foreach my $k (1, 82) {
24   my $result
25     = runperl (stdin => '', stderr => 1,
26               prog => "\$x = q(k) x $k; \$a{\$x} = qw(v); \$_ = <> foreach keys %a; print qw(end)",
27               );
28   $result =~ s/\n\z// if $^O eq 'VMS';
29   is ($result, "end", '[perl #21614] for length ' . length('k' x $k));
30 }
31
32
33 foreach my $k (1, 21) {
34   my $result
35     = runperl (stdin => ' rules', stderr => 1,
36               prog => "\$x = q(perl) x $k; \$a{\$x} = q(v); foreach (keys %a) {\$_ .= <>; print}",
37               );
38   $result =~ s/\n\z// if $^O eq 'VMS';
39   is ($result, ('perl' x $k) . " rules", 'rcatline to shared sv for length ' . length('perl' x $k));
40 }
41
42 foreach my $l (1, 82) {
43   my $k = $l;
44   $k = 'k' x $k;
45   my $copy = $k;
46   $k = <DATA>;
47   is ($k, "moo\n", 'catline to COW sv for length ' . length $copy);
48 }
49
50
51 foreach my $l (1, 21) {
52   my $k = $l;
53   $k = 'perl' x $k;
54   my $perl = $k;
55   $k .= <DATA>;
56   is ($k, "$perl rules\n", 'rcatline to COW sv for length ' . length $perl);
57 }
58
59 use strict;
60 use File::Spec;
61
62 open F, File::Spec->curdir and sysread F, $_, 1;
63 my $err = $! + 0;
64 close F;
65
66 SKIP: {
67   skip "you can read directories as plain files", 2 unless( $err );
68
69   $!=0;
70   open F, File::Spec->curdir and $_=<F>;
71   ok( $!==$err && !defined($_) => 'readline( DIRECTORY )' );
72   close F;
73
74   $!=0;
75   { local $/;
76     open F, File::Spec->curdir and $_=<F>;
77     ok( $!==$err && !defined($_) => 'readline( DIRECTORY ) slurp mode' );
78     close F;
79   }
80 }
81
82 fresh_perl_is('BEGIN{<>}', '',
83               { switches => ['-w'], stdin => '', stderr => 1 },
84               'No ARGVOUT used only once warning');
85
86 fresh_perl_is('print readline', 'foo',
87               { switches => ['-w'], stdin => 'foo', stderr => 1 },
88               'readline() defaults to *ARGV');
89
90 my $obj = bless [];
91 $obj .= <DATA>;
92 like($obj, qr/main=ARRAY.*world/, 'rcatline and refs');
93
94 # bug #38631
95 require Tie::Scalar;
96 tie our $one, 'Tie::StdScalar', "A: ";
97 tie our $two, 'Tie::StdScalar', "B: ";
98 my $junk = $one;
99 $one .= <DATA>;
100 $two .= <DATA>;
101 is( $one, "A: One\n", "rcatline works with tied scalars" );
102 is( $two, "B: Two\n", "rcatline works with tied scalars" );
103
104 __DATA__
105 moo
106 moo
107  rules
108  rules
109 world
110 One
111 Two