Browse Source

reject empty test names. Submitted by Clark Archer. PR 43586

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@926465 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
d46268dc56
5 changed files with 34 additions and 0 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +16
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  5. +9
    -0
      src/tests/antunit/taskdefs/optional/junit/junit-test.xml

+ 1
- 0
CONTRIBUTORS View File

@@ -48,6 +48,7 @@ Christoph Wilhelms
Christophe Labouisse
Christopher A. Longo
Christopher Charlier
Clark Archer
Clemens Hammacher
Clement OUDOT
Conor MacNeill


+ 4
- 0
WHATSNEW View File

@@ -96,6 +96,10 @@ Other changes:
meaningful error message
Bugzilla Report 48834
* <junit> will now throw an exception if a test name is empty. This
used to manifest itself in unrelated errors like
Bugzilla Report 43586.

Changes from Ant 1.8.0RC1 TO Ant 1.8.0
======================================



+ 4
- 0
contributors.xml View File

@@ -214,6 +214,10 @@
<first>Christopher</first>
<last>Charlier</last>
</name>
<name>
<first>Clark</first>
<last>Archer</last>
</name>
<name>
<first>Clemens</first>
<last>Hammacher</last>


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

@@ -789,6 +789,8 @@ public class JUnitTask extends Task {
* @throws BuildException in case of test failures or errors
*/
protected void execute(JUnitTest arg) throws BuildException {
validateTestName(arg.getName());

JUnitTest test = (JUnitTest) arg.clone();
// set the default values if not specified
//@todo should be moved to the test class instead.
@@ -812,6 +814,20 @@ public class JUnitTask extends Task {
actOnTestResult(result, test, "Test " + test.getName());
}

/**
* Throws a <code>BuildException</code> if the given test name is invalid.
* Validity is defined as not <code>null</code>, not empty, and not the
* string &quot;null&quot;.
* @param testName the test name to be validated
* @throws BuildException if <code>testName</code> is not a valid test name
*/
private void validateTestName(String testName) throws BuildException {
if (testName == null || testName.length() == 0
|| testName.equals("null")) {
throw new BuildException("test name must be specified");
}
}

/**
* Execute a list of tests in a single forked Java VM.
* @param testList the list of tests to execute.


+ 9
- 0
src/tests/antunit/taskdefs/optional/junit/junit-test.xml View File

@@ -289,4 +289,13 @@ public class BTest extends TestCase {
<au:assertLogDoesntContain text="Running test.HTest"/>
</target>

<target name="testMissingTestName">
<property name="test.name" value="null"/>
<au:expectfailure message="test name must be specified">
<junit fork="false">
<test name="${test.name}"/>
</junit>
</au:expectfailure>
</target>

</project>

Loading…
Cancel
Save