⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exectasktest.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  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. * */package org.apache.tools.ant.taskdefs;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 &lt;exec&gt; task. */public class ExecTaskTest extends BuildFileTest {    private static final String BUILD_PATH = "src/etc/testcases/taskdefs/exec/";    private static final String BUILD_FILE = BUILD_PATH + "exec.xml";    private static final int TIME_TO_WAIT = 1;    /** 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    /** Utilities used for file operations */    private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();    private File logFile;    private MonitoredBuild myBuild = null;    volatile private boolean buildFinished = false;    public ExecTaskTest(String name) {        super(name);    }    public void setUp() {        configureProject(BUILD_FILE);    }    public void tearDown() {        if (logFile != null && logFile.exists()) {            getProject().setProperty("logFile", logFile.getAbsolutePath());        }        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,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -