author | herrick |
Wed, 16 Oct 2019 10:32:08 -0400 | |
branch | JDK-8200758-branch |
changeset 58648 | 3bf53ffa9ae7 |
parent 58464 | d82489644b15 |
permissions | -rw-r--r-- |
58416 | 1 |
/* |
2 |
* Copyright (c) 2019, 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 |
||
24 |
package jdk.jpackage.test; |
|
25 |
||
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
58648 | 28 |
import java.util.function.Function; |
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
29 |
import java.util.function.Predicate; |
58416 | 30 |
import java.util.stream.Collectors; |
31 |
import static jdk.jpackage.test.TestBuilder.CMDLINE_ARG_PREFIX; |
|
32 |
||
33 |
||
34 |
public final class Main { |
|
35 |
public static void main(String args[]) throws Throwable { |
|
36 |
boolean listTests = false; |
|
37 |
List<TestInstance> tests = new ArrayList<>(); |
|
38 |
try (TestBuilder testBuilder = new TestBuilder(tests::add)) { |
|
39 |
for (var arg : args) { |
|
58648 | 40 |
TestBuilder.trace(String.format("Parsing [%s]...", arg)); |
58416 | 41 |
|
42 |
if ((CMDLINE_ARG_PREFIX + "list").equals(arg)) { |
|
43 |
listTests = true; |
|
44 |
continue; |
|
45 |
} |
|
46 |
||
47 |
boolean success = false; |
|
48 |
try { |
|
49 |
testBuilder.processCmdLineArg(arg); |
|
50 |
success = true; |
|
51 |
} catch (Throwable throwable) { |
|
52 |
TKit.unbox(throwable); |
|
53 |
} finally { |
|
54 |
if (!success) { |
|
55 |
TKit.log( |
|
56 |
String.format("Error processing parameter=[%s]", |
|
57 |
arg)); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
// Order tests by their full names to have stable test sequence. |
|
58648 | 64 |
List<TestInstance> orderedTests = tests.stream() |
65 |
.sorted((a, b) -> a.fullName().compareTo(b.fullName())) |
|
66 |
.collect(Collectors.toList()); |
|
58416 | 67 |
|
68 |
if (listTests) { |
|
69 |
// Just list the tests |
|
58648 | 70 |
orderedTests.stream().forEach(test -> System.out.println(String.format( |
71 |
"%s; workDir=[%s]", test.fullName(), test.workDir()))); |
|
58416 | 72 |
return; |
73 |
} |
|
74 |
||
58648 | 75 |
TKit.withExtraLogStream(() -> runTests(orderedTests)); |
76 |
} |
|
77 |
||
78 |
private static void runTests(List<TestInstance> tests) { |
|
58416 | 79 |
TKit.runTests(tests); |
80 |
||
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
81 |
final long passedCount = tests.stream().filter(TestInstance::passed).count(); |
58416 | 82 |
TKit.log(String.format("[==========] %d tests ran", tests.size())); |
83 |
TKit.log(String.format("[ PASSED ] %d %s", passedCount, |
|
84 |
passedCount == 1 ? "test" : "tests")); |
|
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
85 |
|
58648 | 86 |
reportDetails(tests, "[ SKIPPED ]", TestInstance::skipped, false); |
87 |
reportDetails(tests, "[ FAILED ]", TestInstance::failed, true); |
|
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
88 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
89 |
var withSkipped = reportSummary(tests, "SKIPPED", TestInstance::skipped); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
90 |
var withFailures = reportSummary(tests, "FAILED", TestInstance::failed); |
58416 | 91 |
|
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
92 |
if (withFailures != null) { |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
93 |
throw withFailures; |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
94 |
} |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
95 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
96 |
if (withSkipped != null) { |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
97 |
tests.stream().filter(TestInstance::skipped).findFirst().get().rethrowIfSkipped(); |
58416 | 98 |
} |
99 |
} |
|
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
100 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
101 |
private static long reportDetails(List<TestInstance> tests, |
58648 | 102 |
String label, Predicate<TestInstance> selector, boolean printWorkDir) { |
103 |
||
104 |
final Function<TestInstance, String> makeMessage = test -> { |
|
105 |
if (printWorkDir) { |
|
106 |
return String.format("%s %s; workDir=[%s]", label, |
|
107 |
test.fullName(), test.workDir()); |
|
108 |
} |
|
109 |
return String.format("%s %s", label, test.fullName()); |
|
110 |
}; |
|
111 |
||
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
112 |
final long count = tests.stream().filter(selector).count(); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
113 |
if (count != 0) { |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
114 |
TKit.log(String.format("%s %d %s, listed below", label, count, count |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
115 |
== 1 ? "test" : "tests")); |
58648 | 116 |
tests.stream().filter(selector).map(makeMessage).forEachOrdered( |
117 |
TKit::log); |
|
58464
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
118 |
} |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
119 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
120 |
return count; |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
121 |
} |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
122 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
123 |
private static RuntimeException reportSummary(List<TestInstance> tests, |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
124 |
String label, Predicate<TestInstance> selector) { |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
125 |
final long count = tests.stream().filter(selector).count(); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
126 |
if (count != 0) { |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
127 |
final String message = String.format("%d %s %s", count, label, count |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
128 |
== 1 ? "TEST" : "TESTS"); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
129 |
TKit.log(message); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
130 |
return new RuntimeException(message); |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
131 |
} |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
132 |
|
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
133 |
return null; |
d82489644b15
8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
58416
diff
changeset
|
134 |
} |
58416 | 135 |
} |