This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
applied patch, tweak for threads awareness
[perl5.git] / t / op / write.t
CommitLineData
a687059c
LW
1#!./perl
2
79072805 3# $RCSfile: write.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:38 $
a687059c 4
55497cff 5print "1..5\n";
a687059c 6
3fe9a6f1 7my $CAT = ($^O eq 'MSWin32') ? 'type' : 'cat';
8
a687059c
LW
9format OUT =
10the quick brown @<<
11$fox
12jumped
13@*
14$multiline
15^<<<<<<<<<
16$foo
17^<<<<<<<<<
18$foo
19^<<<<<<...
20$foo
21now @<<the@>>>> for all@|||||men to come @<<<<
a0d0e21e
LW
22{
23 'i' . 's', "time\n", $good, 'to'
24}
a687059c
LW
25.
26
a0d0e21e 27open(OUT, '>Op_write.tmp') || die "Can't create Op_write.tmp";
a687059c
LW
28
29$fox = 'foxiness';
30$good = 'good';
31$multiline = "forescore\nand\nseven years\n";
32$foo = 'when in the course of human events it becomes necessary';
33write(OUT);
34close OUT;
35
36$right =
37"the quick brown fox
38jumped
39forescore
40and
41seven years
42when in
43the course
44of huma...
45now is the time for all good men to come to\n";
46
3fe9a6f1 47if (`$CAT Op_write.tmp` eq $right)
a0d0e21e 48 { print "ok 1\n"; unlink 'Op_write.tmp'; }
a687059c
LW
49else
50 { print "not ok 1\n"; }
51
748a9306
LW
52$fox = 'wolfishness';
53my $fox = 'foxiness'; # Test a lexical variable.
54
a687059c
LW
55format OUT2 =
56the quick brown @<<
57$fox
58jumped
59@*
60$multiline
61^<<<<<<<<< ~~
62$foo
63now @<<the@>>>> for all@|||||men to come @<<<<
64'i' . 's', "time\n", $good, 'to'
65.
66
a0d0e21e 67open OUT2, '>Op_write.tmp' or die "Can't create Op_write.tmp";
a687059c 68
a687059c
LW
69$good = 'good';
70$multiline = "forescore\nand\nseven years\n";
71$foo = 'when in the course of human events it becomes necessary';
72write(OUT2);
73close OUT2;
74
75$right =
76"the quick brown fox
77jumped
78forescore
79and
80seven years
81when in
82the course
83of human
84events it
85becomes
86necessary
87now is the time for all good men to come to\n";
88
3fe9a6f1 89if (`$CAT Op_write.tmp` eq $right)
a0d0e21e 90 { print "ok 2\n"; unlink 'Op_write.tmp'; }
a687059c
LW
91else
92 { print "not ok 2\n"; }
93
0f85fab0
LW
94eval <<'EOFORMAT';
95format OUT2 =
96the brown quick @<<
97$fox
98jumped
99@*
100$multiline
a0d0e21e 101and
0f85fab0
LW
102^<<<<<<<<< ~~
103$foo
104now @<<the@>>>> for all@|||||men to come @<<<<
105'i' . 's', "time\n", $good, 'to'
106.
107EOFORMAT
108
a0d0e21e 109open(OUT2, '>Op_write.tmp') || die "Can't create Op_write.tmp";
0f85fab0
LW
110
111$fox = 'foxiness';
112$good = 'good';
113$multiline = "forescore\nand\nseven years\n";
114$foo = 'when in the course of human events it becomes necessary';
115write(OUT2);
116close OUT2;
117
118$right =
119"the brown quick fox
120jumped
121forescore
122and
123seven years
a0d0e21e 124and
0f85fab0
LW
125when in
126the course
127of human
128events it
129becomes
130necessary
131now is the time for all good men to come to\n";
132
3fe9a6f1 133if (`$CAT Op_write.tmp` eq $right)
a0d0e21e 134 { print "ok 3\n"; unlink 'Op_write.tmp'; }
0f85fab0
LW
135else
136 { print "not ok 3\n"; }
137
55497cff 138# formline tests
139
140$mustbe = <<EOT;
141@ a
142@> ab
143@>> abc
144@>>> abc
145@>>>> abc
146@>>>>> abc
147@>>>>>> abc
148@>>>>>>> abc
149@>>>>>>>> abc
150@>>>>>>>>> abc
151@>>>>>>>>>> abc
152EOT
153
154$was1 = $was2 = '';
155for (0..10) {
156 # lexical picture
157 $^A = '';
158 my $format1 = '@' . '>' x $_;
159 formline $format1, 'abc';
160 $was1 .= "$format1 $^A\n";
161 # global
162 $^A = '';
163 local $format2 = '@' . '>' x $_;
164 formline $format2, 'abc';
165 $was2 .= "$format2 $^A\n";
166}
167print $was1 eq $mustbe ? "ok 4\n" : "not ok 4\n";
168print $was2 eq $mustbe ? "ok 5\n" : "not ok 5\n";
169