Skip to content

Commit d270974

Browse files
committed
8344326: Move jpackage tests from "jdk.jpackage.tests" package to the default package
Reviewed-by: mbaesken Backport-of: 2c509a158fad63e69a8072fa4a7588eaacf37dc0
1 parent 63406ab commit d270974

21 files changed

+120
-74
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
import java.nio.file.WatchService;
3939
import java.text.SimpleDateFormat;
4040
import java.util.ArrayList;
41+
import java.util.Arrays;
4142
import java.util.Collection;
4243
import java.util.Collections;
4344
import java.util.Comparator;
4445
import java.util.Date;
46+
import java.util.HashSet;
4547
import java.util.Iterator;
4648
import java.util.List;
4749
import java.util.Map;
@@ -54,13 +56,14 @@
5456
import java.util.function.Predicate;
5557
import java.util.function.Supplier;
5658
import java.util.stream.Collectors;
59+
import static java.util.stream.Collectors.toSet;
5760
import java.util.stream.Stream;
5861
import jdk.jpackage.test.Functional.ExceptionBox;
5962
import jdk.jpackage.test.Functional.ThrowingConsumer;
6063
import jdk.jpackage.test.Functional.ThrowingRunnable;
6164
import jdk.jpackage.test.Functional.ThrowingSupplier;
6265

63-
final public class TKit {
66+
public final class TKit {
6467

6568
private static final String OS = System.getProperty("os.name").toLowerCase();
6669

@@ -81,7 +84,7 @@ final public class TKit {
8184
return TEST_SRC_ROOT.resolve("../../../../src/jdk.jpackage").normalize().toAbsolutePath();
8285
}).get();
8386

84-
public final static String ICON_SUFFIX = Functional.identity(() -> {
87+
public static final String ICON_SUFFIX = Functional.identity(() -> {
8588
if (isOSX()) {
8689
return ".icns";
8790
}
@@ -741,6 +744,86 @@ public static void assertUnexpected(String msg) {
741744
error(concatMessages("Unexpected", msg));
742745
}
743746

747+
public static DirectoryContentVerifier assertDirectoryContent(Path dir) {
748+
return new DirectoryContentVerifier(dir);
749+
}
750+
public static final class DirectoryContentVerifier {
751+
public DirectoryContentVerifier(Path baseDir) {
752+
this(baseDir, ThrowingSupplier.toSupplier(() -> {
753+
try (var files = Files.list(baseDir)) {
754+
return files.map(Path::getFileName).collect(toSet());
755+
}
756+
}).get());
757+
}
758+
public void match(Path ... expected) {
759+
DirectoryContentVerifier.this.match(Set.of(expected));
760+
}
761+
public void match(Set<Path> expected) {
762+
currentTest.notifyAssert();
763+
var comm = Comm.compare(content, expected);
764+
if (!comm.unique1.isEmpty() && !comm.unique2.isEmpty()) {
765+
error(String.format(
766+
"assertDirectoryContentEquals(%s): Some expected %s. Unexpected %s. Missing %s",
767+
baseDir, format(comm.common), format(comm.unique1), format(comm.unique2)));
768+
} else if (!comm.unique1.isEmpty()) {
769+
error(String.format(
770+
"assertDirectoryContentEquals%s: Expected %s. Unexpected %s",
771+
baseDir, format(comm.common), format(comm.unique1)));
772+
} else if (!comm.unique2.isEmpty()) {
773+
error(String.format(
774+
"assertDirectoryContentEquals(%s): Some expected %s. Missing %s",
775+
baseDir, format(comm.common), format(comm.unique2)));
776+
} else {
777+
traceAssert(String.format(
778+
"assertDirectoryContentEquals(%s): Expected %s",
779+
baseDir, format(expected)));
780+
}
781+
}
782+
public void contains(Path ... expected) {
783+
contains(Set.of(expected));
784+
}
785+
public void contains(Set<Path> expected) {
786+
currentTest.notifyAssert();
787+
var comm = Comm.compare(content, expected);
788+
if (!comm.unique2.isEmpty()) {
789+
error(String.format(
790+
"assertDirectoryContentContains(%s): Some expected %s. Missing %s",
791+
baseDir, format(comm.common), format(comm.unique2)));
792+
} else {
793+
traceAssert(String.format(
794+
"assertDirectoryContentContains(%s): Expected %s",
795+
baseDir, format(expected)));
796+
}
797+
}
798+
public DirectoryContentVerifier removeAll(Path ... paths) {
799+
Set<Path> newContent = new HashSet<>(content);
800+
newContent.removeAll(List.of(paths));
801+
return new DirectoryContentVerifier(baseDir, newContent);
802+
}
803+
private DirectoryContentVerifier(Path baseDir, Set<Path> contents) {
804+
this.baseDir = baseDir;
805+
this.content = contents;
806+
}
807+
private static record Comm(Set<Path> common, Set<Path> unique1, Set<Path> unique2) {
808+
static Comm compare(Set<Path> a, Set<Path> b) {
809+
Set<Path> common = new HashSet<>(a);
810+
common.retainAll(b);
811+
Set<Path> unique1 = new HashSet<>(a);
812+
unique1.removeAll(common);
813+
Set<Path> unique2 = new HashSet<>(b);
814+
unique2.removeAll(common);
815+
return new Comm(common, unique1, unique2);
816+
}
817+
}
818+
private static String format(Set<Path> paths) {
819+
return Arrays.toString(
820+
paths.stream().sorted().map(Path::toString).toArray(
821+
String[]::new));
822+
}
823+
private final Path baseDir;
824+
private final Set<Path> content;
825+
}
826+
744827
public static void assertStringListEquals(List<String> expected,
745828
List<String> actual, String msg) {
746829
currentTest.notifyAssert();
@@ -790,7 +873,7 @@ public static void assertStringListEquals(List<String> expected,
790873
}
791874
}
792875

793-
public final static class TextStreamVerifier {
876+
public static final class TextStreamVerifier {
794877
TextStreamVerifier(String value) {
795878
this.value = value;
796879
predicate(String::contains);
@@ -853,7 +936,7 @@ public void apply(Stream<String> lines) {
853936
private String label;
854937
private boolean negate;
855938
private Supplier<RuntimeException> createException;
856-
final private String value;
939+
private final String value;
857940
}
858941

859942
public static TextStreamVerifier assertTextStream(String what) {

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,6 @@ private static Path getInstallationSubDirectory(JPackageCommand cmd) {
6161
return Path.of(cmd.getArgumentValue("--install-dir", cmd::name));
6262
}
6363

64-
// Tests have problems on windows where path in the temp dir are too long
65-
// for the wix tools. We can't use a tempDir outside the TKit's WorkDir, so
66-
// we minimize both the tempRoot directory name (above) and the tempDir name
67-
// (below) to the extension part (which is necessary to differenciate between
68-
// the multiple PackageTypes that will be run for one JPackageCommand).
69-
// It might be beter if the whole work dir name was shortened from:
70-
// jtreg_open_test_jdk_tools_jpackage_share_jdk_jpackage_tests_BasicTest_java.
71-
public static Path getTempDirectory(JPackageCommand cmd, Path tempRoot) {
72-
String ext = cmd.outputBundle().getFileName().toString();
73-
int i = ext.lastIndexOf(".");
74-
if (i > 0 && i < (ext.length() - 1)) {
75-
ext = ext.substring(i+1);
76-
}
77-
return tempRoot.resolve(ext);
78-
}
79-
8064
private static void runMsiexecWithRetries(Executor misexec) {
8165
Executor.Result result = null;
8266
for (int attempt = 0; attempt < 8; ++attempt) {

test/jdk/tools/jpackage/share/jdk/jpackage/tests/AppVersionTest.java renamed to test/jdk/tools/jpackage/share/AppVersionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.io.IOException;
2726
import java.util.Collection;
@@ -46,7 +45,7 @@
4645
* @build jdk.jpackage.test.*
4746
* @compile AppVersionTest.java
4847
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
49-
* --jpt-run=jdk.jpackage.tests.AppVersionTest
48+
* --jpt-run=AppVersionTest
5049
*/
5150

5251
public final class AppVersionTest {

test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java renamed to test/jdk/tools/jpackage/share/BasicTest.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.io.IOException;
2726
import java.nio.file.Files;
@@ -42,16 +41,14 @@
4241
import jdk.jpackage.test.Annotations.Test;
4342
import jdk.jpackage.test.Annotations.Parameter;
4443

45-
import static jdk.jpackage.test.WindowsHelper.getTempDirectory;
46-
4744
/*
4845
* @test
4946
* @summary jpackage basic testing
5047
* @library /test/jdk/tools/jpackage/helpers
5148
* @build jdk.jpackage.test.*
5249
* @compile BasicTest.java
5350
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
54-
* --jpt-run=jdk.jpackage.tests.BasicTest
51+
* --jpt-run=BasicTest
5552
*/
5653

5754
public final class BasicTest {
@@ -285,7 +282,7 @@ public void testTemp(TestTempType type) throws IOException {
285282
// Force save of package bundle in test work directory.
286283
.addInitializer(JPackageCommand::setDefaultInputOutput)
287284
.addInitializer(cmd -> {
288-
Path tempDir = getTempDirectory(cmd, tempRoot);
285+
Path tempDir = tempRoot.resolve(cmd.packageType().name());
289286
switch (type) {
290287
case TEMPDIR_EMPTY -> Files.createDirectories(tempDir);
291288
case TEMPDIR_NOT_EXIST -> Files.createDirectories(tempDir.getParent());
@@ -302,20 +299,16 @@ public void testTemp(TestTempType type) throws IOException {
302299
if (TestTempType.TEMPDIR_NOT_EMPTY.equals(type)) {
303300
pkgTest.setExpectedExitCode(1).addBundleVerifier(cmd -> {
304301
// Check jpackage didn't use the supplied directory.
305-
Path tempDir = getTempDirectory(cmd, tempRoot);
306-
String[] tempDirContents = tempDir.toFile().list();
307-
TKit.assertStringListEquals(List.of("foo.txt"), List.of(
308-
tempDirContents), String.format(
309-
"Check the contents of the supplied temporary directory [%s]",
310-
tempDir));
302+
Path tempDir = Path.of(cmd.getArgumentValue("--temp"));
303+
TKit.assertDirectoryContent(tempDir).match(Path.of("foo.txt"));
311304
TKit.assertStringListEquals(List.of("Hello Duke!"),
312-
Files.readAllLines(tempDir.resolve(tempDirContents[0])),
305+
Files.readAllLines(tempDir.resolve("foo.txt")),
313306
"Check the contents of the file in the supplied temporary directory");
314307
});
315308
} else {
316309
pkgTest.addBundleVerifier(cmd -> {
317310
// Check jpackage used the supplied directory.
318-
Path tempDir = getTempDirectory(cmd, tempRoot);
311+
Path tempDir = Path.of(cmd.getArgumentValue("--temp"));
319312
TKit.assertDirectoryNotEmpty(tempDir);
320313
});
321314
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.io.IOException;
2726
import java.nio.file.Files;
@@ -46,7 +45,7 @@
4645
* @build jdk.jpackage.test.*
4746
* @compile CookedRuntimeTest.java
4847
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
49-
* --jpt-run=jdk.jpackage.tests.CookedRuntimeTest
48+
* --jpt-run=CookedRuntimeTest
5049
*/
5150

5251
public final class CookedRuntimeTest {

test/jdk/tools/jpackage/share/jdk/jpackage/tests/DotInNameTest.java renamed to test/jdk/tools/jpackage/share/DotInNameTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import jdk.jpackage.test.JPackageCommand;
2726
import jdk.jpackage.test.HelloApp;
@@ -37,7 +36,7 @@
3736
* @build jdk.jpackage.test.*
3837
* @compile DotInNameTest.java
3938
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
40-
* --jpt-run=jdk.jpackage.tests.DotInNameTest
39+
* --jpt-run=DotInNameTest
4140
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault
4241
*/
4342

test/jdk/tools/jpackage/share/jdk/jpackage/tests/ErrorTest.java renamed to test/jdk/tools/jpackage/share/ErrorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.util.Collection;
2726
import java.util.List;
@@ -37,7 +36,7 @@
3736
* @build jdk.jpackage.test.*
3837
* @compile ErrorTest.java
3938
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
40-
* --jpt-run=jdk.jpackage.tests.ErrorTest
39+
* --jpt-run=ErrorTest
4140
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useExecutableByDefault
4241
*/
4342

@@ -48,7 +47,7 @@
4847
* @build jdk.jpackage.test.*
4948
* @compile ErrorTest.java
5049
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
51-
* --jpt-run=jdk.jpackage.tests.ErrorTest
50+
* --jpt-run=ErrorTest
5251
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault
5352
*/
5453

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.util.Collection;
2726
import java.util.List;
@@ -37,7 +36,7 @@
3736
* @build jdk.jpackage.test.*
3837
* @compile JLinkOptionsTest.java
3938
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
40-
* --jpt-run=jdk.jpackage.tests.JLinkOptionsTest
39+
* --jpt-run=JLinkOptionsTest
4140
*/
4241

4342
public final class JLinkOptionsTest {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jpackage.tests;
2524

2625
import java.util.Collection;
2726
import java.util.List;
@@ -39,7 +38,7 @@
3938
* @build jdk.jpackage.test.*
4039
* @compile JavaOptionsEqualsTest.java
4140
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
42-
* --jpt-run=jdk.jpackage.tests.JavaOptionsEqualsTest
41+
* --jpt-run=JavaOptionsEqualsTest
4342
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useExecutableByDefault
4443
*/
4544

@@ -50,7 +49,7 @@
5049
* @build jdk.jpackage.test.*
5150
* @compile JavaOptionsEqualsTest.java
5251
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
53-
* --jpt-run=jdk.jpackage.tests.JavaOptionsEqualsTest
52+
* --jpt-run=JavaOptionsEqualsTest
5453
* --jpt-before-run=jdk.jpackage.test.JPackageCommand.useToolProviderByDefault
5554
*/
5655

0 commit comments

Comments
 (0)