perl 1.0 patch 1: Portability bugs and one possible SIGSEGV
[p5sagit/p5-mst-13.2.git] / t / cmd.while
CommitLineData
8d063cd8 1#!./perl
2
3# $Header: cmd.while,v 1.0 87/12/18 13:12:15 root Exp $
4
5print "1..10\n";
6
7open (tmp,'>Cmd.while.tmp') || die "Can't create Cmd.while.tmp.";
8print tmp "tvi925\n";
9print tmp "tvi920\n";
10print tmp "vt100\n";
11print tmp "Amiga\n";
12print tmp "paper\n";
13close tmp;
14
15# test "last" command
16
17open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
18while (<fh>) {
19 last if /vt100/;
20}
21if (!eof && /vt100/) {print "ok 1\n";} else {print "not ok 1\n";}
22
23# test "next" command
24
25$bad = '';
26open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
27while (<fh>) {
28 next if /vt100/;
29 $bad = 1 if /vt100/;
30}
31if (!eof || /vt100/ || $bad) {print "not ok 2\n";} else {print "ok 2\n";}
32
33# test "redo" command
34
35$bad = '';
36open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
37while (<fh>) {
38 if (s/vt100/VT100/g) {
39 s/VT100/Vt100/g;
40 redo;
41 }
42 $bad = 1 if /vt100/;
43 $bad = 1 if /VT100/;
44}
45if (!eof || $bad) {print "not ok 3\n";} else {print "ok 3\n";}
46
47# now do the same with a label and a continue block
48
49# test "last" command
50
51$badcont = '';
52open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
53line: while (<fh>) {
54 if (/vt100/) {last line;}
55} continue {
56 $badcont = 1 if /vt100/;
57}
58if (!eof && /vt100/) {print "ok 4\n";} else {print "not ok 4\n";}
59if (!$badcont) {print "ok 5\n";} else {print "not ok 5\n";}
60
61# test "next" command
62
63$bad = '';
64$badcont = 1;
65open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
66entry: while (<fh>) {
67 next entry if /vt100/;
68 $bad = 1 if /vt100/;
69} continue {
70 $badcont = '' if /vt100/;
71}
72if (!eof || /vt100/ || $bad) {print "not ok 6\n";} else {print "ok 6\n";}
73if (!$badcont) {print "ok 7\n";} else {print "not ok 7\n";}
74
75# test "redo" command
76
77$bad = '';
78$badcont = '';
79open(fh,'Cmd.while.tmp') || die "Can't open Cmd.while.tmp.";
80loop: while (<fh>) {
81 if (s/vt100/VT100/g) {
82 s/VT100/Vt100/g;
83 redo loop;
84 }
85 $bad = 1 if /vt100/;
86 $bad = 1 if /VT100/;
87} continue {
88 $badcont = 1 if /vt100/;
89}
90if (!eof || $bad) {print "not ok 8\n";} else {print "ok 8\n";}
91if (!$badcont) {print "ok 9\n";} else {print "not ok 9\n";}
92
93`/bin/rm -f Cmd.while.tmp`;
94
95#$x = 0;
96#while (1) {
97# if ($x > 1) {last;}
98# next;
99#} continue {
100# if ($x++ > 10) {last;}
101# next;
102#}
103#
104#if ($x < 10) {print "ok 10\n";} else {print "not ok 10\n";}
105
106$i = 9;
107{
108 $i++;
109}
110print "ok $i\n";