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