Skip to content

Commit f24dfe6

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

23 files changed

+167
-80
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package jdk.jpackage.test;
24+
25+
import java.util.HashSet;
26+
import java.util.Set;
27+
28+
record Comm<T>(Set<T> common, Set<T> unique1, Set<T> unique2) {
29+
30+
static <T> Comm<T> compare(Set<T> a, Set<T> b) {
31+
Set<T> common = new HashSet<>(a);
32+
common.retainAll(b);
33+
Set<T> unique1 = new HashSet<>(a);
34+
unique1.removeAll(common);
35+
Set<T> unique2 = new HashSet<>(b);
36+
unique2.removeAll(common);
37+
return new Comm(common, unique1, unique2);
38+
}
39+
}

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
import java.nio.file.WatchService;
4141
import java.text.SimpleDateFormat;
4242
import java.util.ArrayList;
43+
import java.util.Arrays;
4344
import java.util.Collection;
4445
import java.util.Collections;
4546
import java.util.Comparator;
4647
import java.util.Date;
48+
import java.util.HashSet;
4749
import java.util.Iterator;
4850
import java.util.List;
4951
import java.util.Map;
@@ -57,6 +59,7 @@
5759
import java.util.function.Predicate;
5860
import java.util.function.Supplier;
5961
import java.util.stream.Collectors;
62+
import static java.util.stream.Collectors.toSet;
6063
import java.util.stream.Stream;
6164
import jdk.jpackage.test.Functional.ExceptionBox;
6265
import jdk.jpackage.test.Functional.ThrowingConsumer;
@@ -732,6 +735,94 @@ public static void assertUnexpected(String msg) {
732735
error(concatMessages("Unexpected", msg));
733736
}
734737

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

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/linux/jdk/jpackage/tests/UsrTreeTest.java renamed to test/jdk/tools/jpackage/linux/UsrTreeTest.java

File renamed without changes.

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
}

test/jdk/tools/jpackage/share/jdk/jpackage/tests/CookedRuntimeTest.java renamed to test/jdk/tools/jpackage/share/CookedRuntimeTest.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.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

test/jdk/tools/jpackage/share/jdk/jpackage/tests/JLinkOptionsTest.java renamed to test/jdk/tools/jpackage/share/JLinkOptionsTest.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.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 {

0 commit comments

Comments
 (0)