Author: bodewig Date: Wed Jun 16 09:36:08 2010 New Revision: 955166 URL: http://svn.apache.org/viewvc?rev=955166&view=rev Log: use a more robust approach that doesn't rely on stream redirections
Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java?rev=955166&r1=955165&r2=955166&view=diff ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java Wed Jun 16 09:36:08 2010 @@ -19,40 +19,44 @@ package org.apache.tools.ant; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; -import java.io.PrintStream; import junit.framework.TestCase; +import org.apache.tools.ant.util.FileUtils; public class PropertyFileCLITest extends TestCase { public void testPropertyResolution() throws Exception { - File props = File.createTempFile("propertyfilecli", ".properties"); - props.deleteOnExit(); - FileWriter fw = new FileWriter(props); - fw.write("w=world\nmessage=Hello, ${w}\n"); - fw.close(); - File build = File.createTempFile("propertyfilecli", ".xml"); - build.deleteOnExit(); - fw = new FileWriter(build); - fw.write("<project><echo>${message}</echo></project>"); - fw.close(); - PrintStream sysOut = System.out; - StringBuffer sb = new StringBuffer(); + FileUtils fu = FileUtils.getFileUtils(); + File props = fu.createTempFile("propertyfilecli", ".properties", + null, true, true); + File build = fu.createTempFile("propertyfilecli", ".xml", null, true, + true); + File log = fu.createTempFile("propertyfilecli", ".log", null, true, + true); + FileWriter fw = null; + FileReader fr = null; try { - PrintStream out = - new PrintStream(new BuildFileTest.AntOutputStream(sb)); - System.setOut(out); + fw = new FileWriter(props); + fw.write("w=world\nmessage=Hello, ${w}\n"); + fw.close(); + fw = new FileWriter(build); + fw.write("<project><echo>${message}</echo></project>"); + fw.close(); + fw = null; Main m = new NoExitMain(); m.startAnt(new String[] { "-propertyfile", props.getAbsolutePath(), - "-f", build.getAbsolutePath() + "-f", build.getAbsolutePath(), + "-l", log.getAbsolutePath() }, null, null); + String l = FileUtils.safeReadFully(fr = new FileReader(log)); + assertTrue("expected log to contain 'Hello, world' but was " + l, + l.indexOf("Hello, world") > -1); } finally { - System.setOut(sysOut); + FileUtils.close(fw); + FileUtils.close(fr); } - String log = sb.toString(); - assertTrue("expected log to contain 'Hello, world' but was " + log, - log.indexOf("Hello, world") > -1); } private static class NoExitMain extends Main {