Browse Source

Add some tests for manifest task - realized that empty manifest aren't

that empty.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270133 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
ddc395dffa
4 changed files with 67 additions and 3 deletions
  1. +3
    -1
      build.xml
  2. +17
    -1
      src/etc/testcases/taskdefs/manifest.xml
  3. +4
    -1
      src/main/org/apache/tools/ant/taskdefs/Manifest.java
  4. +43
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java

+ 3
- 1
build.xml View File

@@ -842,6 +842,7 @@




<junit printsummary="no" haltonfailure="yes" <junit printsummary="no" haltonfailure="yes"
filtertrace="off"
fork="${junit.fork}"> fork="${junit.fork}">
<!-- <jvmarg value="-classic"/> --> <!-- <jvmarg value="-classic"/> -->
<classpath refid="tests-classpath"/> <classpath refid="tests-classpath"/>
@@ -922,7 +923,8 @@


<target name="run-single-test" if="testcase" depends="compile-tests"> <target name="run-single-test" if="testcase" depends="compile-tests">


<junit printsummary="no" haltonfailure="yes" fork="${junit.fork}">
<junit printsummary="no" haltonfailure="yes" fork="${junit.fork}"
filtertrace="off">
<!-- <jvmarg value="-classic"/> --> <!-- <jvmarg value="-classic"/> -->
<sysproperty key="build.tests" value="${build.tests}"/> <sysproperty key="build.tests" value="${build.tests}"/>
<classpath location="${java.home}/lib/classes.zip" /> <classpath location="${java.home}/lib/classes.zip" />


+ 17
- 1
src/etc/testcases/taskdefs/manifest.xml View File

@@ -100,9 +100,25 @@
</jar> </jar>
</target> </target>


<target name="testNoFile">
<manifest />
</target>

<target name="testReplace">
<copy file="manifests/test2.mf" toFile="mftest.mf" />
<manifest file="mftest.mf" />
</target>

<target name="testUpdate">
<copy file="manifests/test2.mf" toFile="mftest.mf" />
<manifest file="mftest.mf" mode="update">
<attribute name="Foo" value="Bar" />
</manifest>
</target>

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

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

@@ -544,6 +544,7 @@ public class Manifest extends Task {
public Manifest() { public Manifest() {
mode = new Mode(); mode = new Mode();
mode.setValue("replace"); mode.setValue("replace");
manifestVersion = null;
} }


/** /**
@@ -613,7 +614,9 @@ public class Manifest extends Task {
* to the Manifest spec. * to the Manifest spec.
*/ */
public void merge(Manifest other) throws ManifestException { public void merge(Manifest other) throws ManifestException {
manifestVersion = other.manifestVersion;
if (other.manifestVersion != null) {
manifestVersion = other.manifestVersion;
}
mainSection.merge(other.mainSection); mainSection.merge(other.mainSection);
for (Enumeration e = other.sections.keys(); e.hasMoreElements();) { for (Enumeration e = other.sections.keys(); e.hasMoreElements();) {
String sectionName = (String)e.nextElement(); String sectionName = (String)e.nextElement();


+ 43
- 0
src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -55,6 +55,8 @@
package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileTest;


@@ -192,5 +194,46 @@ public class ManifestTest extends BuildFileTest {
executeTarget("test14"); executeTarget("test14");
} }
/**
* file attribute for manifest task is required.
*/
public void testNoFile() {
expectBuildException("testNoFile", "file is required");
}
/**
* replace changes Manifest-Version from 2.0 to 1.0
*/
public void testReplace() throws IOException, ManifestException {
executeTarget("testReplace");
Manifest mf = getManifest();
assertNotNull(mf);
assertEquals(Manifest.getDefaultManifest(), mf);
}

/**
* update keeps the Manifest-Version and adds a new attribute Foo
*/
public void testUpdate() throws IOException, ManifestException {
executeTarget("testUpdate");
Manifest mf = getManifest();
assertNotNull(mf);
assertTrue(!Manifest.getDefaultManifest().equals(mf));
String mfAsString = mf.toString();
assertNotNull(mfAsString);
assertTrue(mfAsString.startsWith("Manifest-Version: 2.0"));
assertTrue(mfAsString.indexOf("Foo: Bar") > -1);
}

/**
* Reads mftest.mf.
*/
private Manifest getManifest() throws IOException, ManifestException {
FileReader r = new FileReader("src/etc/testcases/taskdefs/mftest.mf");
try {
return new Manifest(r);
} finally {
r.close();
}
}
} }

Loading…
Cancel
Save