xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Test/t/fail.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate# -*-perl-*-
2*0Sstevel@tonic-gateuse strict;
3*0Sstevel@tonic-gateuse vars qw($Expect);
4*0Sstevel@tonic-gateuse Test qw($TESTOUT $TESTERR $ntest ok skip plan);
5*0Sstevel@tonic-gateplan tests => 14;
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gateopen F, ">fails";
8*0Sstevel@tonic-gate$TESTOUT = *F{IO};
9*0Sstevel@tonic-gate$TESTERR = *F{IO};
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gatemy $r=0;
12*0Sstevel@tonic-gate{
13*0Sstevel@tonic-gate    # Shut up deprecated usage warning.
14*0Sstevel@tonic-gate    local $^W = 0;
15*0Sstevel@tonic-gate    $r |= skip(0,0);
16*0Sstevel@tonic-gate}
17*0Sstevel@tonic-gate$r |= ok(0);
18*0Sstevel@tonic-gate$r |= ok(0,1);
19*0Sstevel@tonic-gate$r |= ok(sub { 1+1 }, 3);
20*0Sstevel@tonic-gate$r |= ok(sub { 1+1 }, sub { 2 * 0});
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gatemy @list = (0,0);
23*0Sstevel@tonic-gate$r |= ok @list, 1, "\@list=".join(',',@list);
24*0Sstevel@tonic-gate$r |= ok @list, 1, sub { "\@list=".join ',',@list };
25*0Sstevel@tonic-gate$r |= ok 'segmentation fault', '/bongo/';
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gatefor (1..2) { $r |= ok(0); }
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate$r |= ok(1, undef);
30*0Sstevel@tonic-gate$r |= ok(undef, 1);
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateok($r); # (failure==success :-)
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gateclose F;
35*0Sstevel@tonic-gate$TESTOUT = *STDOUT{IO};
36*0Sstevel@tonic-gate$TESTERR = *STDERR{IO};
37*0Sstevel@tonic-gate$ntest = 1;
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gateopen F, "fails";
40*0Sstevel@tonic-gatemy $O;
41*0Sstevel@tonic-gatewhile (<F>) { $O .= $_; }
42*0Sstevel@tonic-gateclose F;
43*0Sstevel@tonic-gateunlink "fails";
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gateok join(' ', map { m/(\d+)/; $1 } grep /^not ok/, split /\n+/, $O),
46*0Sstevel@tonic-gate    join(' ', 1..13);
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gatemy @got = split /not ok \d+\n/, $O;
49*0Sstevel@tonic-gateshift @got;
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate$Expect =~ s/\n+$//;
52*0Sstevel@tonic-gatemy @expect = split /\n\n/, $Expect;
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gatesub commentless {
56*0Sstevel@tonic-gate  my $in = $_[0];
57*0Sstevel@tonic-gate  $in =~ s/^#[^\n]*\n//mg;
58*0Sstevel@tonic-gate  $in =~ s/\n#[^\n]*$//mg;
59*0Sstevel@tonic-gate  return $in;
60*0Sstevel@tonic-gate}
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gatefor (my $x=0; $x < @got; $x++) {
64*0Sstevel@tonic-gate    ok commentless($got[$x]), commentless($expect[$x]."\n");
65*0Sstevel@tonic-gate}
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gateBEGIN {
69*0Sstevel@tonic-gate    $Expect = <<"EXPECT";
70*0Sstevel@tonic-gate# Failed test 1 in $0 at line 15
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate# Failed test 2 in $0 at line 17
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate# Test 3 got: '0' ($0 at line 18)
75*0Sstevel@tonic-gate#   Expected: '1'
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate# Test 4 got: '2' ($0 at line 19)
78*0Sstevel@tonic-gate#   Expected: '3'
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate# Test 5 got: '2' ($0 at line 20)
81*0Sstevel@tonic-gate#   Expected: '0'
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate# Test 6 got: '2' ($0 at line 23)
84*0Sstevel@tonic-gate#   Expected: '1' (\@list=0,0)
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate# Test 7 got: '2' ($0 at line 24)
87*0Sstevel@tonic-gate#   Expected: '1' (\@list=0,0)
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate# Test 8 got: 'segmentation fault' ($0 at line 25)
90*0Sstevel@tonic-gate#   Expected: qr{bongo}
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate# Failed test 9 in $0 at line 27
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate# Failed test 10 in $0 at line 27 fail #2
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate# Failed test 11 in $0 at line 29
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate# Test 12 got: <UNDEF> ($0 at line 30)
99*0Sstevel@tonic-gate#    Expected: '1'
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate# Failed test 13 in $0 at line 32
102*0Sstevel@tonic-gateEXPECT
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate}
105