Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8346140: tools/jar/ExtractFilesTest.java and tools/jar/MultipleManifestTest.java fails with jtreg5.1 #612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions jdk/test/tools/jar/ExtractFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
* @run junit/othervm ExtractFilesTest
*/

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -51,13 +46,12 @@
import jdk.testlibrary.FileUtils;
import sun.tools.jar.Main;

@TestInstance(Lifecycle.PER_CLASS)
public class ExtractFilesTest {
private final String nl = System.lineSeparator();
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final PrintStream out = new PrintStream(baos);

@BeforeAll
@Before
public void setupJar() throws IOException {
mkdir("test1 test2");
echo("testfile1", "test1/testfile1");
Expand All @@ -66,7 +60,7 @@ public void setupJar() throws IOException {
rm("test1 test2");
}

@AfterAll
@After
public void cleanup() {
rm("test.jar");
}
Expand All @@ -83,7 +77,7 @@ public void testExtract() throws IOException {
" inflated: testfile1" + nl +
" inflated: testfile2" + nl;
rm("META-INF testfile1 testfile2");
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

/**
Expand All @@ -98,9 +92,9 @@ public void testOverwrite() throws IOException {
" inflated: META-INF/MANIFEST.MF" + nl +
" inflated: testfile1" + nl +
" inflated: testfile2" + nl;
Assertions.assertEquals("testfile1", cat("testfile1"));
Assert.assertEquals("testfile1", cat("testfile1"));
rm("META-INF testfile1 testfile2");
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

/**
Expand All @@ -115,10 +109,10 @@ public void testKeptOldFile() throws IOException {
" inflated: META-INF/MANIFEST.MF" + nl +
" skipped: testfile1 exists" + nl +
" inflated: testfile2" + nl;
Assertions.assertEquals("", cat("testfile1"));
Assertions.assertEquals("testfile2", cat("testfile2"));
Assert.assertEquals("", cat("testfile1"));
Assert.assertEquals("testfile2", cat("testfile2"));
rm("META-INF testfile1 testfile2");
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

/**
Expand All @@ -133,10 +127,10 @@ public void testGnuOptionsKeptOldFile() throws IOException {
" inflated: META-INF/MANIFEST.MF" + nl +
" skipped: testfile1 exists" + nl +
" skipped: testfile2 exists" + nl;
Assertions.assertEquals("", cat("testfile1"));
Assertions.assertEquals("", cat("testfile2"));
Assert.assertEquals("", cat("testfile1"));
Assert.assertEquals("", cat("testfile2"));
rm("META-INF testfile1 testfile2");
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

/**
Expand All @@ -152,8 +146,8 @@ public void testWarningOnInvalidKeepOption() throws IOException {
"testfile1" + nl +
"testfile2" + nl;

Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assertions.assertEquals("Warning: The k option is not valid with current usage, will be ignored." + nl, err);
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertEquals("Warning: The k option is not valid with current usage, will be ignored." + nl, err);
}

private Stream<Path> mkpath(String... args) {
Expand Down
31 changes: 10 additions & 21 deletions jdk/test/tools/jar/MultipleManifestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@

import java.io.ByteArrayOutputStream;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.*;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -60,8 +54,7 @@
import jdk.testlibrary.FileUtils;
import sun.tools.jar.Main;

@TestInstance(Lifecycle.PER_CLASS)
class MultipleManifestTest {
public class MultipleManifestTest {
private final String nl = System.lineSeparator();
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final PrintStream jarOut = new PrintStream(baos);
Expand All @@ -85,8 +78,9 @@ class MultipleManifestTest {
*
* @throws IOException if an unexpected IOException occurs
*/
@AfterAll
@After
public void cleanup() throws IOException {
rm("META-INF entry1.txt entry2.txt");
Files.deleteIfExists(zip);
}

Expand All @@ -95,7 +89,7 @@ public void cleanup() throws IOException {
*
* @throws IOException if an error occurs
*/
@BeforeAll
@Before
public void writeManifestAsFirstSecondAndFourthEntry() throws IOException {
int locPosA, locPosB, cenPos;
System.out.printf("%n%n*****Creating Jar with the Manifest as the 1st, 2nd and 4th entry*****%n%n");
Expand Down Expand Up @@ -132,25 +126,20 @@ public void writeManifestAsFirstSecondAndFourthEntry() throws IOException {
Files.write(zip, template);
}

@AfterEach
public void removeExtractedFiles() {
rm("META-INF entry1.txt entry2.txt");
}

/**
* Extract by default should have the last manifest.
*/
@Test
public void testOverwrite() throws IOException {
jar("xvf " + zip.toString());
println();
Assertions.assertEquals("3.0", getManifestVersion());
Assert.assertEquals("3.0", getManifestVersion());
String output = " inflated: META-INF/MANIFEST.MF" + nl +
" inflated: META-INF/MANIFEST.MF" + nl +
" inflated: entry1.txt" + nl +
" inflated: META-INF/MANIFEST.MF" + nl +
" inflated: entry2.txt" + nl;
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

/**
Expand All @@ -160,13 +149,13 @@ public void testOverwrite() throws IOException {
public void testKeptOldFile() throws IOException {
jar("xkvf " + zip.toString());
println();
Assertions.assertEquals("1.0", getManifestVersion());
Assert.assertEquals("1.0", getManifestVersion());
String output = " inflated: META-INF/MANIFEST.MF" + nl +
" skipped: META-INF/MANIFEST.MF exists" + nl +
" inflated: entry1.txt" + nl +
" skipped: META-INF/MANIFEST.MF exists" + nl +
" inflated: entry2.txt" + nl;
Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes());
Assert.assertArrayEquals(baos.toByteArray(), output.getBytes());
}

private String getManifestVersion() throws IOException {
Expand Down Expand Up @@ -216,4 +205,4 @@ private void rm(String cmdline) {
}
});
}
}
}