Move the require './test.pl' to the end of t/comp/hints.t
[p5sagit/p5-mst-13.2.git] / t / op / readline.t
CommitLineData
79628082 1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
e4b7ebf3 9plan tests => 18;
79628082 10
11eval { for (\2) { $_ = <FH> } };
12like($@, 'Modification of a read-only value attempted', '[perl #19566]');
13
ba92458f 14{
1c25d394 15 my $file = tempfile();
16 open A,'+>',$file; $a = 3;
ba92458f 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');
ba92458f 20}
10bcdfd6 21
22# 82 is chosen to exceed the length for sv_grow in do_readline (80)
bfe0b846 23foreach my $k (1, 82) {
10bcdfd6 24 my $result
048e6480 25 = runperl (stdin => '', stderr => 1,
bfe0b846 26 prog => "\$x = q(k) x $k; \$a{\$x} = qw(v); \$_ = <> foreach keys %a; print qw(end)",
10bcdfd6 27 );
bfe0b846 28 $result =~ s/\n\z// if $^O eq 'VMS';
29 is ($result, "end", '[perl #21614] for length ' . length('k' x $k));
10bcdfd6 30}
bc44a8a2 31
32
bfe0b846 33foreach my $k (1, 21) {
bc44a8a2 34 my $result
048e6480 35 = runperl (stdin => ' rules', stderr => 1,
bfe0b846 36 prog => "\$x = q(perl) x $k; \$a{\$x} = q(v); foreach (keys %a) {\$_ .= <>; print}",
bc44a8a2 37 );
bfe0b846 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));
bc44a8a2 40}
41
42foreach 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
51foreach 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}
2d726892 58
59use strict;
60use File::Spec;
61
62open F, File::Spec->curdir and sysread F, $_, 1;
63my $err = $! + 0;
64close F;
65
66SKIP: {
389edf24 67 skip "you can read directories as plain files", 2 unless( $err );
2d726892 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
7b8203e3 82fresh_perl_is('BEGIN{<>}', '',
83 { switches => ['-w'], stdin => '', stderr => 1 },
84 'No ARGVOUT used only once warning');
85
e4b7ebf3 86fresh_perl_is('print readline', 'foo',
87 { switches => ['-w'], stdin => 'foo', stderr => 1 },
88 'readline() defaults to *ARGV');
89
48de12d9 90my $obj = bless [];
91$obj .= <DATA>;
92like($obj, qr/main=ARRAY.*world/, 'rcatline and refs');
93
0f722b55 94# bug #38631
95require Tie::Scalar;
96tie our $one, 'Tie::StdScalar', "A: ";
97tie our $two, 'Tie::StdScalar', "B: ";
98my $junk = $one;
99$one .= <DATA>;
100$two .= <DATA>;
101is( $one, "A: One\n", "rcatline works with tied scalars" );
102is( $two, "B: Two\n", "rcatline works with tied scalars" );
103
bc44a8a2 104__DATA__
105moo
106moo
107 rules
108 rules
48de12d9 109world
0f722b55 110One
111Two