Browse Source

Add tests. Document the regexp for attribute name.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@530664 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 18 years ago
parent
commit
c7f7d99c3d
4 changed files with 42 additions and 12 deletions
  1. +3
    -1
      docs/manual/CoreTasks/manifest.html
  2. +18
    -0
      src/etc/testcases/taskdefs/manifest.xml
  3. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
  4. +17
    -7
      src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java

+ 3
- 1
docs/manual/CoreTasks/manifest.html View File

@@ -94,7 +94,9 @@ not nested into a section will be added to the "Main" section.</p>
</tr>
<tr>
<td valign="top">name</td>
<td valign="top">the name of the attribute.</td>
<td valign="top">the name of the attribute, <br>
must match the regexp <tt>[A-Za-z0-9][A-Za-z0-9-_]*</tt>.
</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>


+ 18
- 0
src/etc/testcases/taskdefs/manifest.xml View File

@@ -227,6 +227,24 @@
</manifest>
</target>

<target name="testIllegalNameBegin">
<manifest file="mftestillegalnamebegin.mf">
<attribute name="-name" value="value"/>
</manifest>
</target>

<target name="testIllegalName2">
<manifest file="mftestillegalnamebegin.mf">
<attribute name="has.point" value="value"/>
</manifest>
</target>

<target name="testIllegalName3">
<manifest file="mftestillegalnamebegin.mf">
<attribute name="has*star" value="value"/>
</manifest>
</target>

<target name="clean">
<delete>
<fileset dir="." includes="mftest*"/>


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/ManifestTask.java View File

@@ -139,20 +139,20 @@ public class ManifestTask extends Task {
* check each character.
*
* @param attribute The attribute to check
* @throws ManifestException if the check fails
* @throws BuildException if the check fails
*/
private void checkAttribute(Manifest.Attribute attribute) throws ManifestException {
private void checkAttribute(Manifest.Attribute attribute) throws BuildException {
String name = attribute.getName();
char ch = name.charAt(0);

if (ch == '-' || ch == '_') {
throw new ManifestException("Manifest attribute names must not contain '" + ch + "'");
throw new BuildException("Manifest attribute names must not contain '" + ch + "' at the begin.");
}
for (int i = 0; i < name.length(); i++) {
ch = name.charAt(i);
if (VALID_ATTRIBUTE_CHARS.indexOf(ch) < 0) {
throw new ManifestException("Manifest attribute names must not contain '" + ch + "'");
throw new BuildException("Manifest attribute names must not contain '" + ch + "'");
}
}
}


+ 17
- 7
src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -331,17 +331,27 @@ public class ManifestTest extends BuildFileTest {
public void testFrom() {
expectLogContaining("testFrom", Manifest.ERROR_FROM_FORBIDDEN);
}
public void testIllegalName() {
//expectBuildException("testIllegalName", "Attribute name is not valid according to the specification.");
expectBuildException("testIllegalName", "Manifest attribute names must not contain ' '");
}
public void testIllegalNameInSection() {
//expectBuildException("testIllegalNameInSection", "Attribute name is not valid according to the specification.");
expectBuildException("testIllegalNameInSection", "Manifest attribute names must not contain ' '");
}

public void testIllegalNameBegin() {
expectBuildException("testIllegalNameInSection", "Manifest attribute names must not contain '-' at the begin.");
}

public void testIllegalName2() {
expectBuildException("testIllegalName", "Manifest attribute names must not contain '.'");
}

public void testIllegalName3() {
expectBuildException("testIllegalName", "Manifest attribute names must not contain '*'");
}

/**
* Reads mftest.mf.
*/


Loading…
Cancel
Save