git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@915991 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -32,26 +32,6 @@ | |||
| <isset property="sh.exe.executable"/> | |||
| </or> | |||
| </condition> | |||
| <!-- UNIX --> | |||
| <available file="wc" filepath="${env.PATH}" property="wc.executable"/> | |||
| <!-- CYGWIN --> | |||
| <available file="wc.exe" filepath="${env.PATH}" property="wc.exe.executable"/> | |||
| <condition property="wc.can.run"> | |||
| <or> | |||
| <isset property="wc.executable"/> | |||
| <isset property="wc.exe.executable"/> | |||
| </or> | |||
| </condition> | |||
| <!-- UNIX --> | |||
| <available file="cat" filepath="${env.PATH}" property="cat.executable"/> | |||
| <!-- CYGWIN --> | |||
| <available file="cat.exe" filepath="${env.PATH}" property="cat.exe.executable"/> | |||
| <condition property="cat.can.run"> | |||
| <or> | |||
| <isset property="cat.executable"/> | |||
| <isset property="cat.exe.executable"/> | |||
| </or> | |||
| </condition> | |||
| </target> | |||
| <target name="spawn" depends="init" if="test.can.run"> | |||
| @@ -62,324 +42,7 @@ | |||
| </exec> | |||
| </target> | |||
| <target name="no-redirect" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect1" depends="init" if="test.can.run"> | |||
| <exec executable="sh" output="redirect.out"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect2" depends="init" if="test.can.run"> | |||
| <exec executable="sh" output="redirect.out" error="redirect.err"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect3" depends="init" if="test.can.run"> | |||
| <exec executable="sh" logerror="true" | |||
| output="redirect.out" outputproperty="redirect.out"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect4" depends="init" if="test.can.run"> | |||
| <exec executable="sh" | |||
| error="redirect.err" errorproperty="redirect.err" | |||
| output="redirect.out" outputproperty="redirect.out"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect5" depends="init" if="wc.can.run"> | |||
| <exec executable="wc" inputstring="x y z" | |||
| error="redirect.err" errorproperty="redirect.err" | |||
| output="redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect6" depends="init" if="wc.can.run"> | |||
| <echo file="redirect.in">x y z</echo> | |||
| <exec executable="wc" input="redirect.in" | |||
| error="redirect.err" errorproperty="redirect.err" | |||
| output="redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirect7" depends="init" if="wc.can.run"> | |||
| <exec executable="wc" inputstring="x y z" | |||
| error="redirect.err" | |||
| output="redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector1" description="fail" | |||
| depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="redirector.out" /> | |||
| <redirector output="whocares" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector2" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="redirector.out" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector3" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="redirector.out" error="redirector.err" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector4" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="redirector.out" logerror="true" | |||
| outputproperty="redirector.out" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector5" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector error="redirector.err" errorproperty="redirector.err" | |||
| output="redirector.out" outputproperty="redirector.out" /> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector6" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector7" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| <errorfilterchain> | |||
| <replacestring from="err" to="ERROR!!!" /> | |||
| </errorfilterchain> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector8" depends="init" if="wc.can.run"> | |||
| <echo file="redirector.in">x y z</echo> | |||
| <exec executable="wc"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <inputmapper type="merge" to="redirector.in" /> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| </redirector> | |||
| <arg value="-w"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector9" depends="init" if="cat.can.run"> | |||
| <echo file="redirector.in">blah before blah</echo> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <inputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </inputfilterchain> | |||
| <inputmapper type="merge" to="redirector.in" /> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| </redirector> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector10" depends="init" if="cat.can.run"> | |||
| <echo file="redirector.in">blah before blah</echo> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| </redirector> | |||
| <arg value="redirector.in"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector11" depends="init" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err" | |||
| inputstring="blah before blah"> | |||
| <inputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </inputfilterchain> | |||
| <outputmapper type="merge" to="redirector.out" /> | |||
| <errormapper type="merge" to="redirector.err" /> | |||
| </redirector> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector12" depends="init" if="cat.can.run"> | |||
| <echo file="redirector.in">blah before blah</echo> | |||
| <exec executable="cat" output="redirector.out" error="redirector.err"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="glob" from="nomatch" to="nomatchout" /> | |||
| <errormapper type="glob" from="nomatch" to="nomatcherr" /> | |||
| </redirector> | |||
| <arg value="redirector.in"/> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector13" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector> | |||
| <outputfilterchain> | |||
| <replacestring from="out" to="OUTPUT???" /> | |||
| </outputfilterchain> | |||
| <errorfilterchain> | |||
| <replacestring from="err" to="ERROR!!!" /> | |||
| </errorfilterchain> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector14" depends="init" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector inputstring="blah before blah"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="glob" from="nomatch" to="nomatchout" /> | |||
| <errormapper type="glob" from="nomatch" to="nomatcherr" /> | |||
| </redirector> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector15" depends="init" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector input="input/iso8859-1" output="redirector.out" | |||
| inputencoding="ISO8859_1" outputencoding="UTF8" /> | |||
| </exec> | |||
| </target> | |||
| <target name="redirector16" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector inputstring="exit" | |||
| output="redirector16.out" error="redirector16.err" /> | |||
| </exec> | |||
| <condition property="16pass"> | |||
| <and> | |||
| <available file="redirector16.out" type="file" /> | |||
| <available file="redirector16.err" type="file" /> | |||
| </and> | |||
| </condition> | |||
| <fail unless="16pass">Files were not created.</fail> | |||
| </target> | |||
| <target name="redirector17" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector inputstring="exit" createemptyfiles="false" | |||
| output="redirector17.out" error="redirector17.err" /> | |||
| </exec> | |||
| <condition property="17fail"> | |||
| <or> | |||
| <available file="redirector17.out" type="file" /> | |||
| <available file="redirector17.err" type="file" /> | |||
| </or> | |||
| </condition> | |||
| <fail if="17fail">Files were created.</fail> | |||
| </target> | |||
| <target name="redirector18" depends="init" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh"/> | |||
| <arg value="${ant.file}" /> | |||
| <redirector alwayslog="true" logerror="true" | |||
| outputproperty="redirector.out" /> | |||
| </exec> | |||
| <fail message="property redirector.out has unexpected content"> | |||
| <condition> | |||
| <not> | |||
| <equals arg1="${ant.file} out" arg2="${redirector.out}" /> | |||
| </not> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <!-- test will succeed as the OS wont match--> | |||
| <target name="testExecUnknownOS"> | |||
| <exec executable="nonexistent-program-we-expect" | |||
| failonerror="true" | |||
| os="ZX81"> | |||
| </exec> | |||
| </target> | |||
| <target name="testExecOSFamily"> | |||
| <exec executable="uptime" | |||
| failonerror="true" | |||
| osFamily="unix"> | |||
| </exec> | |||
| <exec executable="cmd.exe" | |||
| failonerror="true" | |||
| osFamily="winnt"> | |||
| <arg value="/c" /> | |||
| <arg value="time /t" /> | |||
| </exec> | |||
| </target> | |||
| <target name="testExecInconsistentSettings"> | |||
| <exec executable="nonexistent-program-we-expect" | |||
| failonerror="true" | |||
| osFamily="WIN9X" | |||
| os="linux unix"> | |||
| </exec> | |||
| </target> | |||
| <target name="cleanup"> | |||
| <delete> | |||
| <fileset file="${logFile}" /> | |||
| <fileset dir="${basedir}" includes="redirect*" /> | |||
| <fileset dir="${basedir}" includes="redirector*" /> | |||
| </delete> | |||
| <delete file="${logFile}" /> | |||
| </target> | |||
| </project> | |||
| @@ -0,0 +1,639 @@ | |||
| <?xml version="1.0"?> | |||
| <!-- | |||
| Licensed to the Apache Software Foundation (ASF) under one or more | |||
| contributor license agreements. See the NOTICE file distributed with | |||
| this work for additional information regarding copyright ownership. | |||
| The ASF licenses this file to You under the Apache License, Version 2.0 | |||
| (the "License"); you may not use this file except in compliance with | |||
| the License. You may obtain a copy of the License at | |||
| http://www.apache.org/licenses/LICENSE-2.0 | |||
| Unless required by applicable law or agreed to in writing, software | |||
| distributed under the License is distributed on an "AS IS" BASIS, | |||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| See the License for the specific language governing permissions and | |||
| limitations under the License. | |||
| --> | |||
| <project name="exec-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> | |||
| <import file="../../antunit-base.xml" /> | |||
| <target name="antunit"> | |||
| <mkdir dir="${java.io.tmpdir}/antunit-exec" /> | |||
| <antunit xmlns="antlib:org.apache.ant.antunit"> | |||
| <plainlistener sendLogTo="both" toDir="${java.io.tmpdir}/antunit-exec" logLevel="debug" /> | |||
| <file file="${ant.file}" xmlns="antlib:org.apache.tools.ant" /> | |||
| </antunit> | |||
| </target> | |||
| <macrodef name="assert-trimmed-resource-content"> | |||
| <attribute name="content" /> | |||
| <attribute name="astext" default="true" /> | |||
| <element name="resource" implicit="true" /> | |||
| <sequential> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="@{astext}"> | |||
| <string value="@{content}" /> | |||
| <concat> | |||
| <resource /> | |||
| <filterchain> | |||
| <trim /> | |||
| </filterchain> | |||
| </concat> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </sequential> | |||
| </macrodef> | |||
| <target name="setUp"> | |||
| <mkdir dir="${input}" /> | |||
| <mkdir dir="${output}" /> | |||
| <property environment="env" /> | |||
| <!-- UNIX --> | |||
| <available file="sh" filepath="${env.PATH}" property="sh.executable" /> | |||
| <!-- CYGWIN --> | |||
| <available file="sh.exe" filepath="${env.PATH}" property="sh.exe.executable" /> | |||
| <condition property="test.can.run"> | |||
| <or> | |||
| <isset property="sh.executable" /> | |||
| <isset property="sh.exe.executable" /> | |||
| </or> | |||
| </condition> | |||
| <!-- UNIX --> | |||
| <available file="wc" filepath="${env.PATH}" property="wc.executable" /> | |||
| <!-- CYGWIN --> | |||
| <available file="wc.exe" filepath="${env.PATH}" property="wc.exe.executable" /> | |||
| <condition property="wc.can.run"> | |||
| <or> | |||
| <isset property="wc.executable" /> | |||
| <isset property="wc.exe.executable" /> | |||
| </or> | |||
| </condition> | |||
| <!-- UNIX --> | |||
| <available file="cat" filepath="${env.PATH}" property="cat.executable" /> | |||
| <!-- CYGWIN --> | |||
| <available file="cat.exe" filepath="${env.PATH}" property="cat.exe.executable" /> | |||
| <condition property="cat.can.run"> | |||
| <or> | |||
| <isset property="cat.executable" /> | |||
| <isset property="cat.exe.executable" /> | |||
| </or> | |||
| </condition> | |||
| </target> | |||
| <target name="test-no-redirect" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertLogContains text="${ant.file} out" /> | |||
| <au:assertLogContains text="${ant.file} err" /> | |||
| </target> | |||
| <target name="test-redirect-output" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh" output="${output}/redirect.out"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out${line.separator}${ant.file} err</string> | |||
| <file file="${output}/redirect.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirect-output-error" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh" output="${output}/redirect.out" error="${output}/redirect.err"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirect.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} err</string> | |||
| <file file="${output}/redirect.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirect-output-outputproperty-logerror" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh" logerror="true" | |||
| output="${output}/redirect.out" outputproperty="redirect.out"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirect.out" /> | |||
| <propertyresource name="redirect.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertLogContains text="${ant.file} err" /> | |||
| </target> | |||
| <target name="test-redirect-output-outputproperty-error-errorproperty" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh" | |||
| error="${output}/redirect.err" errorproperty="redirect.err" | |||
| output="${output}/redirect.out" outputproperty="redirect.out"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirect.out" /> | |||
| <propertyresource name="redirect.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} err</string> | |||
| <file file="${output}/redirect.err" /> | |||
| <propertyresource name="redirect.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirect-inputstring-output-outputproperty-error-errorproperty" | |||
| depends="setUp" if="wc.can.run"> | |||
| <exec executable="wc" inputstring="x y z" | |||
| error="${output}/redirect.err" errorproperty="redirect.err" | |||
| output="${output}/redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirect.err" /> | |||
| <propertyresource name="redirect.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <file file="${output}/redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <propertyresource name="redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| </target> | |||
| <target name="test-redirect-input-output-outputproperty-error-errorproperty" | |||
| depends="setUp" if="wc.can.run"> | |||
| <echo file="${input}/redirect.in">x y z</echo> | |||
| <exec executable="wc" input="${input}/redirect.in" | |||
| error="${output}/redirect.err" errorproperty="redirect.err" | |||
| output="${output}/redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirect.err" /> | |||
| <propertyresource name="redirect.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <file file="${output}/redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <propertyresource name="redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| </target> | |||
| <target name="test-redirect-input-output-outputproperty-error" | |||
| depends="setUp" if="wc.can.run"> | |||
| <exec executable="wc" inputstring="x y z" | |||
| error="${output}/redirect.err" | |||
| output="${output}/redirect.out" outputproperty="redirect.out"> | |||
| <arg value="-w" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirect.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| <concat> | |||
| <file file="${output}/redirect.out" /> | |||
| <propertyresource name="redirect.out" /> | |||
| </concat> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <file file="${output}/redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <propertyresource name="redirect.out" /> | |||
| </assert-trimmed-resource-content> | |||
| </target> | |||
| <target name="test-multiple-redirectors" description="fail" | |||
| depends="setUp" if="test.can.run"> | |||
| <au:expectfailure> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="${output}/redirector.out" /> | |||
| <redirector output="whocares" /> | |||
| </exec> | |||
| </au:expectfailure> | |||
| </target> | |||
| <target name="test-redirector-output" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="${output}/redirector.out" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out${line.separator}${ant.file} err</string> | |||
| <file file="${output}/redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-output-error" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="${output}/redirector.out" error="${output}/redirector.err" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} err</string> | |||
| <file file="${output}/redirector.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-output-outputproperty-logerror" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| <redirector output="${output}/redirector.out" logerror="true" | |||
| outputproperty="redirector.out" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertLogContains text="${ant.file} err" /> | |||
| </target> | |||
| <target name="test-redirector-output-outputproperty-error-errorproperty" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector error="${output}/redirector.err" errorproperty="redirector.err" | |||
| output="${output}/redirector.out" outputproperty="redirector.out" /> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} err</string> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-outputmapper-errormapper" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} err</string> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-outputmapper-errormapper-errorfilterchain" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| <errorfilterchain> | |||
| <replacestring from="err" to="ERROR!!!" /> | |||
| </errorfilterchain> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} out</string> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string>${ant.file} ERROR!!!</string> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-inputmapper-outputmapper-errormapper" | |||
| depends="setUp" if="wc.can.run"> | |||
| <echo file="${input}/redirector.in">x y z</echo> | |||
| <exec executable="wc"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <inputmapper type="merge" to="${input}/redirector.in" /> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| </redirector> | |||
| <arg value="-w" /> | |||
| </exec> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <file file="${output}/redirector.out" /> | |||
| </assert-trimmed-resource-content> | |||
| <assert-trimmed-resource-content content="3"> | |||
| <propertyresource name="redirector.out" /> | |||
| </assert-trimmed-resource-content> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-inputfilterchain-inputmapper-outputmapper-errormapper" | |||
| depends="setUp" if="cat.can.run"> | |||
| <echo file="${input}/redirector.in">blah before blah</echo> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <inputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </inputfilterchain> | |||
| <inputmapper type="merge" to="${input}/redirector.in" /> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| </redirector> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string value="blah after blah" /> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-outputfilterchain-outputmapper-errormapper" | |||
| depends="setUp" if="cat.can.run"> | |||
| <echo file="${input}/redirector.in">blah before blah</echo> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| </redirector> | |||
| <arg value="${input}/redirector.in" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string value="blah after blah" /> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputproperty-errorproperty-inputstring-inputfilterchain-outputmapper-errormapper" | |||
| depends="setUp" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err" | |||
| inputstring="blah before blah"> | |||
| <inputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </inputfilterchain> | |||
| <outputmapper type="merge" to="${output}/redirector.out" /> | |||
| <errormapper type="merge" to="${output}/redirector.err" /> | |||
| </redirector> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string value="blah after blah" /> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirect-output-error-redirector-outputproperty-errorproperty-outputfilterchain-invalid-outputmapper-invalid-errormapper" | |||
| depends="setUp" if="cat.can.run"> | |||
| <echo file="${input}/redirector.in">blah before blah</echo> | |||
| <exec executable="cat" output="${output}/redirector.out" error="${output}/redirector.err"> | |||
| <redirector outputproperty="redirector.out" | |||
| errorproperty="redirector.err"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="glob" from="nomatch" to="${output}/nomatchout" /> | |||
| <errormapper type="glob" from="nomatch" to="${output}/nomatcherr" /> | |||
| </redirector> | |||
| <arg value="${input}/redirector.in" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <string value="blah after blah" /> | |||
| <file file="${output}/redirector.out" /> | |||
| <propertyresource name="redirector.out" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <length length="0"> | |||
| <file file="${output}/redirector.err" /> | |||
| <propertyresource name="redirector.err" /> | |||
| </length> | |||
| </au:assertTrue> | |||
| <au:assertTrue> | |||
| <resourcecount count="0"> | |||
| <fileset dir="${output}" includes="nomatch???" /> | |||
| </resourcecount> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-outputfilterchain-errorfilterchain" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector> | |||
| <outputfilterchain> | |||
| <replacestring from="out" to="OUTPUT???" /> | |||
| </outputfilterchain> | |||
| <errorfilterchain> | |||
| <replacestring from="err" to="ERROR!!!" /> | |||
| </errorfilterchain> | |||
| </redirector> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| </exec> | |||
| <au:assertLogContains text="${ant.file} OUTPUT???" /> | |||
| <au:assertLogContains text="${ant.file} ERROR!!!" /> | |||
| </target> | |||
| <target name="test-redirector-inputstring-outputfilterchain-outputmapper-errormapper" | |||
| depends="setUp" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector inputstring="blah before blah"> | |||
| <outputfilterchain> | |||
| <replacestring from="before" to="after" /> | |||
| </outputfilterchain> | |||
| <outputmapper type="glob" from="nomatch" to="nomatchout" /> | |||
| <errormapper type="glob" from="nomatch" to="nomatcherr" /> | |||
| </redirector> | |||
| </exec> | |||
| <au:assertLogContains text="blah after blah" /> | |||
| </target> | |||
| <target name="test-redirector-input-output-inputencoding-outputencoding" | |||
| depends="setUp" if="cat.can.run"> | |||
| <exec executable="cat"> | |||
| <redirector input="input/iso8859-1" output="${output}/redirector.out" | |||
| inputencoding="ISO8859_1" outputencoding="UTF8" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <resourcesmatch astext="true"> | |||
| <file file="${output}/redirector.out" /> | |||
| <file file="expected/utf-8" /> | |||
| </resourcesmatch> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-inputstring-output-error" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector inputstring="exit" | |||
| output="${output}/redirector.out" error="${output}/redirector.err" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <and> | |||
| <available file="${output}/redirector.out" type="file" /> | |||
| <available file="${output}/redirector.err" type="file" /> | |||
| </and> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-inputstring-nocreateempty-output-error" | |||
| depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <redirector inputstring="exit" createemptyfiles="false" | |||
| output="${output}/redirector.out" error="${output}/redirector.err" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <not> | |||
| <or> | |||
| <available file="${output}/redirector.out" type="file" /> | |||
| <available file="${output}/redirector.err" type="file" /> | |||
| </or> | |||
| </not> | |||
| </au:assertTrue> | |||
| </target> | |||
| <target name="test-redirector-alwayslog-outputproperty" depends="setUp" if="test.can.run"> | |||
| <exec executable="sh"> | |||
| <arg value="parrot.sh" /> | |||
| <arg value="${ant.file}" /> | |||
| <redirector alwayslog="true" logerror="true" | |||
| outputproperty="redirector.out" /> | |||
| </exec> | |||
| <au:assertTrue> | |||
| <equals arg1="${ant.file} out" arg2="${redirector.out}" /> | |||
| </au:assertTrue> | |||
| <au:assertLogContains text="${ant.file} out" /> | |||
| </target> | |||
| <!-- test will succeed as the OS wont match--> | |||
| <target name="testExecUnknownOS"> | |||
| <exec executable="nonexistent-program-we-expect" | |||
| failonerror="true" | |||
| os="ZX81"> | |||
| </exec> | |||
| </target> | |||
| <target name="testExecOSFamily"> | |||
| <exec executable="uptime" | |||
| failonerror="true" | |||
| osFamily="unix"> | |||
| </exec> | |||
| <exec executable="cmd.exe" | |||
| failonerror="true" | |||
| osFamily="winnt"> | |||
| <arg value="/c" /> | |||
| <arg value="time /t" /> | |||
| </exec> | |||
| </target> | |||
| <target name="testExecInconsistentSettings"> | |||
| <exec executable="nonexistent-program-we-expect" | |||
| failonerror="true" | |||
| osFamily="WIN9X" | |||
| os="linux unix"> | |||
| </exec> | |||
| </target> | |||
| </project> | |||
| @@ -22,12 +22,8 @@ import org.apache.tools.ant.*; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import java.io.File; | |||
| import java.io.FileReader; | |||
| import java.io.IOException; | |||
| import java.util.GregorianCalendar; | |||
| import junit.framework.ComparisonFailure; | |||
| /** | |||
| * Unit test for the <exec> task. | |||
| */ | |||
| @@ -38,7 +34,8 @@ public class ExecTaskTest extends BuildFileTest { | |||
| /** maximum time allowed for the build in milliseconds */ | |||
| private static final int MAX_BUILD_TIME = 4000; | |||
| private static final int SECURITY_MARGIN = 2000; // wait 2 second extras | |||
| // the test failed with 100 ms of margin on cvs.apache.org on August 1st, 2003 | |||
| // the test failed with 100 ms of margin on cvs.apache.org on August 1st, | |||
| // 2003 | |||
| /** Utilities used for file operations */ | |||
| private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
| @@ -46,6 +43,7 @@ public class ExecTaskTest extends BuildFileTest { | |||
| private File logFile; | |||
| private MonitoredBuild myBuild = null; | |||
| volatile private boolean buildFinished = false; | |||
| public ExecTaskTest(String name) { | |||
| super(name); | |||
| } | |||
| @@ -61,293 +59,13 @@ public class ExecTaskTest extends BuildFileTest { | |||
| executeTarget("cleanup"); | |||
| } | |||
| public void testNoRedirect() { | |||
| executeTarget("no-redirect"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected log content", | |||
| getProject().getProperty("ant.file") + " out" | |||
| + getProject().getProperty("ant.file") + " err", getLog()); | |||
| } | |||
| public void testRedirect1() throws IOException { | |||
| executeTarget("redirect1"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n" | |||
| + getProject().getProperty("ant.file") + " err\n"; | |||
| assertEquals("unexpected output", | |||
| expectedOut, getFileString("redirect.out")); | |||
| } | |||
| public void testRedirect2() throws IOException { | |||
| executeTarget("redirect2"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", | |||
| getProject().getProperty("ant.file") + " out\n", | |||
| getFileString("redirect.out")); | |||
| assertEquals("unexpected error output", | |||
| getProject().getProperty("ant.file") + " err\n", | |||
| getFileString("redirect.err")); | |||
| } | |||
| public void testRedirect3() throws IOException { | |||
| executeTarget("redirect3"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected log content", | |||
| getProject().getProperty("ant.file") + " err", getLog()); | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n"; | |||
| assertEquals("unexpected output", | |||
| expectedOut, getFileString("redirect.out")); | |||
| assertPropertyEquals("redirect.out", expectedOut.trim()); | |||
| } | |||
| public void testRedirect4() throws IOException { | |||
| executeTarget("redirect4"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n"; | |||
| String expectedErr = getProject().getProperty("ant.file") + " err\n"; | |||
| assertEquals("unexpected output", | |||
| expectedOut, getFileString("redirect.out")); | |||
| assertPropertyEquals("redirect.out", expectedOut.trim()); | |||
| assertEquals("unexpected error output", | |||
| expectedErr, getFileString("redirect.err")); | |||
| assertPropertyEquals("redirect.err", expectedErr.trim()); | |||
| } | |||
| public void testRedirect5() throws IOException { | |||
| testRedirect5or6("redirect5"); | |||
| } | |||
| public void testRedirect6() throws IOException { | |||
| testRedirect5or6("redirect6"); | |||
| } | |||
| public void testRedirect5or6(String target) throws IOException { | |||
| executeTarget(target); | |||
| if (getProject().getProperty("wc.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", "3", getFileString("redirect.out").trim()); | |||
| assertEquals("property redirect.out", "3", | |||
| getProject().getProperty("redirect.out").trim()); | |||
| assertNull("unexpected error output", getFileString("redirect.err")); | |||
| assertPropertyEquals("redirect.err", ""); | |||
| } | |||
| public void testRedirect7() throws IOException { | |||
| executeTarget("redirect7"); | |||
| if (getProject().getProperty("wc.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", "3", getFileString("redirect.out").trim()); | |||
| assertEquals("property redirect.out", "3", | |||
| getProject().getProperty("redirect.out").trim()); | |||
| assertNull("unexpected error output", getFileString("redirect.err")); | |||
| } | |||
| public void testRedirector1() { | |||
| executeTarget("init"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| expectBuildException("redirector1", "cannot have > 1 nested <redirector>s"); | |||
| } | |||
| public void testRedirector2() throws IOException { | |||
| executeTarget("redirector2"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", | |||
| getProject().getProperty("ant.file") + " out\n" | |||
| + getProject().getProperty("ant.file") + " err\n", | |||
| getFileString("redirector.out")); | |||
| } | |||
| public void testRedirector3() throws IOException { | |||
| executeTarget("redirector3"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", | |||
| getProject().getProperty("ant.file") + " out\n", | |||
| getFileString("redirector.out")); | |||
| assertEquals("unexpected error output", | |||
| getProject().getProperty("ant.file") + " err\n", | |||
| getFileString("redirector.err")); | |||
| } | |||
| public void testRedirector4() throws IOException { | |||
| executeTarget("redirector4"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n"; | |||
| assertEquals("unexpected log content", | |||
| getProject().getProperty("ant.file") + " err", getLog()); | |||
| assertEquals("unexpected output", expectedOut, | |||
| getFileString("redirector.out")); | |||
| assertPropertyEquals("redirector.out", expectedOut.trim()); | |||
| } | |||
| public void testRedirector5() throws IOException { | |||
| testRedirector5or6("redirector5"); | |||
| } | |||
| public void testRedirector6() throws IOException { | |||
| testRedirector5or6("redirector6"); | |||
| } | |||
| private void testRedirector5or6(String target) throws IOException { | |||
| executeTarget(target); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n"; | |||
| String expectedErr = getProject().getProperty("ant.file") + " err\n"; | |||
| assertEquals("unexpected output", expectedOut, | |||
| getFileString("redirector.out")); | |||
| assertPropertyEquals("redirector.out", expectedOut.trim()); | |||
| assertEquals("unexpected error output", expectedErr, | |||
| getFileString("redirector.err")); | |||
| assertPropertyEquals("redirector.err", expectedErr.trim()); | |||
| } | |||
| public void testRedirector7() throws IOException { | |||
| executeTarget("redirector7"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = getProject().getProperty("ant.file") + " out\n"; | |||
| String expectedErr = getProject().getProperty("ant.file") + " ERROR!!!\n"; | |||
| assertEquals("unexpected output", expectedOut, | |||
| getFileString("redirector.out")); | |||
| assertPropertyEquals("redirector.out", expectedOut.trim()); | |||
| assertEquals("unexpected error output", expectedErr, | |||
| getFileString("redirector.err")); | |||
| assertPropertyEquals("redirector.err", expectedErr.trim()); | |||
| } | |||
| public void testRedirector8() throws IOException { | |||
| executeTarget("redirector8"); | |||
| if (getProject().getProperty("wc.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected output", "3", getFileString("redirector.out").trim()); | |||
| assertEquals("property redirector.out", "3", | |||
| getProject().getProperty("redirector.out").trim()); | |||
| assertNull("unexpected error output", getFileString("redirector.err")); | |||
| assertPropertyEquals("redirector.err", ""); | |||
| } | |||
| public void testRedirector9() throws IOException { | |||
| testRedirector9Thru12("redirector9"); | |||
| } | |||
| public void testRedirector10() throws IOException { | |||
| testRedirector9Thru12("redirector10"); | |||
| } | |||
| public void testRedirector11() throws IOException { | |||
| testRedirector9Thru12("redirector11"); | |||
| } | |||
| public void testRedirector12() throws IOException { | |||
| testRedirector9Thru12("redirector12"); | |||
| } | |||
| private void testRedirector9Thru12(String target) throws IOException { | |||
| executeTarget(target); | |||
| if (getProject().getProperty("cat.can.run") == null) { | |||
| return; | |||
| } | |||
| String expectedOut = "blah after blah"; | |||
| assertEquals("unexpected output", | |||
| expectedOut, getFileString("redirector.out").trim()); | |||
| assertPropertyEquals("redirector.out", expectedOut.trim()); | |||
| assertNull("unexpected error output", getFileString("redirector.err")); | |||
| assertPropertyEquals("redirector.err", ""); | |||
| } | |||
| public void testRedirector13() { | |||
| executeTarget("redirector13"); | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| String antfile = getProject().getProperty("ant.file"); | |||
| try { | |||
| //no point in setting a message | |||
| assertEquals(antfile + " OUTPUT???" + antfile + " ERROR!!!", getLog()); | |||
| } catch (ComparisonFailure cf) { | |||
| assertEquals("unexpected log content", | |||
| antfile + " ERROR!!!" + antfile + " OUTPUT???", getLog()); | |||
| } | |||
| } | |||
| public void testRedirector14() { | |||
| executeTarget("redirector14"); | |||
| if (getProject().getProperty("cat.can.run") == null) { | |||
| return; | |||
| } | |||
| assertEquals("unexpected log output", "blah after blah", getLog()); | |||
| } | |||
| public void testRedirector15() throws IOException { | |||
| executeTarget("redirector15"); | |||
| if (getProject().getProperty("cat.can.run") == null) { | |||
| return; | |||
| } | |||
| assertTrue("error with transcoding", | |||
| FILE_UTILS.contentEquals( | |||
| getProject().resolveFile("expected/utf-8"), | |||
| getProject().resolveFile("redirector.out"))); | |||
| } | |||
| public void testRedirector16() { | |||
| executeTarget("redirector16"); | |||
| } | |||
| public void testRedirector17() { | |||
| executeTarget("redirector17"); | |||
| } | |||
| public void testRedirector18() { | |||
| if (getProject().getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| expectLog("redirector18", getProject().getProperty("ant.file") | |||
| + " out" + getProject().getProperty("ant.file") + " err"); | |||
| } | |||
| public void testspawn() { | |||
| project.executeTarget("init"); | |||
| if (project.getProperty("test.can.run") == null) { | |||
| return; | |||
| } | |||
| myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn"); | |||
| logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir(), false, false); | |||
| logFile = FILE_UTILS.createTempFile("spawn", "log", project.getBaseDir(), false, false); | |||
| // this is guaranteed by FileUtils#createTempFile | |||
| assertTrue("log file not existing", !logFile.exists()); | |||
| // make the spawned process run 4 seconds | |||
| @@ -366,7 +84,9 @@ public class ExecTaskTest extends BuildFileTest { | |||
| GregorianCalendar now = new GregorianCalendar(); | |||
| // security | |||
| if (now.getTime().getTime() - startwait.getTime().getTime() > MAX_BUILD_TIME) { | |||
| System.out.println("aborting wait, too long " + (now.getTime().getTime() - startwait.getTime().getTime()) + "milliseconds"); | |||
| System.out.println("aborting wait, too long " | |||
| + (now.getTime().getTime() - startwait.getTime().getTime()) | |||
| + "milliseconds"); | |||
| break; | |||
| } | |||
| } | |||
| @@ -378,24 +98,12 @@ public class ExecTaskTest extends BuildFileTest { | |||
| } | |||
| // time of the build in milli seconds | |||
| long elapsed = myBuild.getTimeElapsed(); | |||
| assertTrue("we waited more than the process lasted", TIME_TO_WAIT * 1000 | |||
| + SECURITY_MARGIN > elapsed); | |||
| assertTrue("we waited more than the process lasted", | |||
| TIME_TO_WAIT * 1000 + SECURITY_MARGIN > elapsed); | |||
| logFile = new File(logFile.getAbsolutePath()); | |||
| assertTrue("log file found after spawn", logFile.exists()); | |||
| } | |||
| public void testExecUnknownOS() { | |||
| executeTarget("testExecUnknownOS"); | |||
| } | |||
| public void testExecOSFamily() { | |||
| executeTarget("testExecOSFamily"); | |||
| } | |||
| public void testExecInconsistentSettings() { | |||
| executeTarget("testExecInconsistentSettings"); | |||
| } | |||
| private static class MonitoredBuild implements Runnable { | |||
| private Thread worker; | |||
| private File myBuildFile = null; | |||
| @@ -419,15 +127,17 @@ public class ExecTaskTest extends BuildFileTest { | |||
| public void addBuildListener(BuildListener bl) { | |||
| project.addBuildListener(bl); | |||
| } | |||
| public MonitoredBuild(File buildFile, String target) { | |||
| myBuildFile = buildFile; | |||
| this.target = target; | |||
| project=new Project(); | |||
| project = new Project(); | |||
| project = new Project(); | |||
| project.init(); | |||
| project.setUserProperty( "ant.file" , myBuildFile.getAbsolutePath() ); | |||
| project.setUserProperty("ant.file", myBuildFile.getAbsolutePath()); | |||
| ProjectHelper.configureProject(project, myBuildFile); | |||
| } | |||
| /** | |||
| * | |||
| * @return time in millis of the build | |||
| @@ -435,19 +145,23 @@ public class ExecTaskTest extends BuildFileTest { | |||
| public long getTimeElapsed() { | |||
| return timeFinished.getTime().getTime() - timeStarted.getTime().getTime(); | |||
| } | |||
| public void start() { | |||
| worker = new Thread(this, myBuildFile.toString() + "/" + target); | |||
| worker.start(); | |||
| } | |||
| public void run() { | |||
| startProject(); | |||
| } | |||
| private void startProject() { | |||
| timeStarted = new GregorianCalendar(); | |||
| project.executeTarget(target); | |||
| timeFinished = new GregorianCalendar(); | |||
| } | |||
| } | |||
| private class MonitoredBuildListener implements BuildListener { | |||
| public void buildStarted(BuildEvent event) { | |||
| } | |||
| @@ -474,18 +188,4 @@ public class ExecTaskTest extends BuildFileTest { | |||
| } | |||
| } | |||
| //borrowed from TokenFilterTest | |||
| private String getFileString(String filename) throws IOException { | |||
| String result = null; | |||
| FileReader reader = null; | |||
| try { | |||
| reader = new FileReader(getProject().resolveFile(filename)); | |||
| result = FileUtils.readFully(reader); | |||
| } catch (IOException eyeOhEx) { | |||
| } finally { | |||
| FileUtils.close(reader); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||