Browse Source

use a more robust approach that doesn't rely on stream redirections

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@955166 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
fb2d2b20ba
1 changed files with 25 additions and 21 deletions
  1. +25
    -21
      src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java

+ 25
- 21
src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java View File

@@ -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 {


Loading…
Cancel
Save