xref: /trunk/main/solenv/bin/exectest.pl (revision 7e90fac2)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24$#ARGV >= 1
25    or die "Usage: $0 <input file>|-SUCCESS|-FAILURE <command> <arguments...>";
26if ($ARGV[0] eq "-SUCCESS")
27{
28    $expect = "SUCCESS";
29    $input = 0;
30}
31elsif ($ARGV[0] eq "-FAILURE")
32{
33    $expect = "FAILURE";
34    $input = 0;
35}
36else
37{
38    open INPUT, $ARGV[0] or die "cannot open $ARGV[0]: $!";
39    $input = 1;
40}
41shift @ARGV;
42$failed = 0;
43$open = 0;
44while (1) {
45    $eof = $input ? eof INPUT : $open;
46    $in = <INPUT> if $input && !$eof;
47    if (!$input || $eof
48		|| $in =~ /^EXPECT (SUCCESS|FAILURE|\d+)( "([^"]*)")?:\n$/)
49    {
50        if ($open)
51        {
52            close PIPE;
53            if ($? % 256 == 0)
54            {
55                $exit = $? / 256;
56                $ok = $expect eq "SUCCESS" ? $exit == 0
57                    : $expect eq "FAILURE" ? $exit != 0 : $exit == $expect;
58            }
59            else
60            {
61                $exit = "signal";
62                $ok = 0;
63            }
64            print "\"$title\", " if defined $title;
65            print "expected $expect, got $exit ($?): ";
66            if ($ok)
67            {
68                print "ok\n";
69            }
70            else
71            {
72                print "FAILED!\n";
73                $failed = 1;
74            }
75        }
76        last if $eof;
77        $expect = $1 if $input;
78        if (defined $3)
79        {
80            $title = $3;
81        }
82        else
83        {
84            undef $title;
85        }
86        open PIPE, "| @ARGV" or die "cannot start process: $!";
87        $open = 1;
88    }
89    elsif ($open && $input)
90    {
91        print PIPE $in or die "cannot write to pipe: $!";
92    }
93}
94exit $failed;
95