Browse Source

Added usefile attribute to <formatter> to allow testoutput to be sent

to stdout instead of a file.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267989 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
409b0917b6
4 changed files with 60 additions and 17 deletions
  1. +3
    -1
      build.xml
  2. +10
    -3
      docs/junit.html
  3. +10
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  4. +37
    -12
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 3
- 1
build.xml View File

@@ -315,7 +315,9 @@
<pathelement path="${java.class.path}" />
</classpath>

<batchtest>
<formatter type="plain" usefile="false" />

<batchtest fork="yes">
<fileset dir="${src.tests.dir}">
<include name="**/*Test*" />
<exclude name="**/All*" />


+ 10
- 3
docs/junit.html View File

@@ -91,9 +91,10 @@ href="index.html#arg">Command line arguments</a>.</p>
<h4>formatter</h4>

<p>The results of the tests can be printed in different
formats. Output will always be sent to a file, the name of the file is
determined by the name of the test and can be set by the
<code>outfile</code> attribute of <code>&lt;test&gt;</code>.
formats. Output will always be sent to a file unless you set the
usefile attribute to false, the name of the file is determined by the
name of the test and can be set by the <code>outfile</code> attribute
of <code>&lt;test&gt;</code>.

<p>There are two predefined formatters, one prints the test results in
XML format, the other emits plain text. Custom formatters that need to
@@ -121,6 +122,12 @@ can be specified.</p>
<td valign="top">Extension to append to the output filename.</td>
<td align="center">Yes, if classname has been used.</td>
</tr>
<tr>
<td valign="top">usefile</td>
<td valign="top">Boolean that determines whether output should be
sent to a file.</td>
<td align="center">No, default true.</td>
</tr>
</table>

<h4>test</h4>


+ 10
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java View File

@@ -73,6 +73,7 @@ public class FormatterElement {
private String extension;
private OutputStream out = System.out;
private File outFile;
private boolean useFile = true;

public void setType(TypeAttribute type) {
if ("xml".equals(type.getValue())) {
@@ -108,6 +109,14 @@ public class FormatterElement {
this.out = out;
}

public void setUseFile(boolean useFile) {
this.useFile = useFile;
}

boolean getUseFile() {
return useFile;
}

JUnitResultFormatter createFormatter() throws BuildException {
if (classname == null) {
throw new BuildException("you must specify type or classname");
@@ -135,7 +144,7 @@ public class FormatterElement {

JUnitResultFormatter r = (JUnitResultFormatter) o;

if (outFile != null) {
if (useFile && outFile != null) {
try {
out = new FileOutputStream(outFile);
} catch (java.io.IOException e) {


+ 37
- 12
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -193,6 +193,9 @@ public class JUnitTask extends Task {
}

int exitValue = JUnitTestRunner.ERRORS;
System.err.println(test.getFork());

if (!test.getFork()) {
JUnitTestRunner runner =
new JUnitTestRunner(test, test.getHaltonerror(),
@@ -208,14 +211,22 @@ public class JUnitTask extends Task {

for (int i=0; i<formatters.size(); i++) {
FormatterElement fe = (FormatterElement) formatters.elementAt(i);
fe.setOutfile(project.resolveFile(test.getOutfile()
+fe.getExtension()));
if (fe.getUseFile()) {
fe.setOutfile(project.resolveFile(test.getOutfile()
+fe.getExtension()));
} else {
fe.setOutput(new LogOutputStream(this, Project.MSG_INFO));
}
runner.addFormatter(fe.createFormatter());
}
FormatterElement[] add = test.getFormatters();
for (int i=0; i<add.length; i++) {
add[i].setOutfile(project.resolveFile(test.getOutfile()
+add[i].getExtension()));
if (add[i].getUseFile()) {
add[i].setOutfile(project.resolveFile(test.getOutfile()
+add[i].getExtension()));
} else {
add[i].setOutput(new LogOutputStream(this, Project.MSG_INFO));
}
runner.addFormatter(add[i].createFormatter());
}

@@ -237,24 +248,38 @@ public class JUnitTask extends Task {
cmd.createArgument().setValue("formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter");
}

StringBuffer formatterArg = new StringBuffer();
for (int i=0; i<formatters.size(); i++) {
FormatterElement fe = (FormatterElement) formatters.elementAt(i);
cmd.createArgument().setValue("formatter=" +
fe.getClassname() + ","
+ project.resolveFile(test.getOutfile()
+fe.getExtension()).getAbsolutePath());
formatterArg.append("formatter=");
formatterArg.append(fe.getClassname());
if (fe.getUseFile()) {
formatterArg.append(",");
formatterArg.append(project.resolveFile(test.getOutfile()
+fe.getExtension())
.getAbsolutePath());
}
cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0);
}
FormatterElement[] add = test.getFormatters();
for (int i=0; i<add.length; i++) {
cmd.createArgument().setValue("formatter=" +
add[i].getClassname() + ","
+ project.resolveFile(test.getOutfile()
+add[i].getExtension()).getAbsolutePath());
formatterArg.append("formatter=");
formatterArg.append(add[i].getClassname());
if (add[i].getUseFile()) {
formatterArg.append(",");
formatterArg.append(project.resolveFile(test.getOutfile()
+add[i].getExtension())
.getAbsolutePath());
}
cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0);
}

Execute execute = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN), createWatchdog());
execute.setCommandline(cmd.getCommandline());
log("Executing: "+cmd.toString(), Project.MSG_VERBOSE);
try {
exitValue = execute.execute();
} catch (IOException e) {


Loading…
Cancel
Save