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;
|
|
28 |
import java.util.stream.Collectors;
|
|
29 |
import static jdk.jpackage.test.TestBuilder.CMDLINE_ARG_PREFIX;
|
|
30 |
|
|
31 |
|
|
32 |
public final class Main {
|
|
33 |
public static void main(String args[]) throws Throwable {
|
|
34 |
boolean listTests = false;
|
|
35 |
List<TestInstance> tests = new ArrayList<>();
|
|
36 |
try (TestBuilder testBuilder = new TestBuilder(tests::add)) {
|
|
37 |
for (var arg : args) {
|
|
38 |
if (TKit.VERBOSE_TEST_SETUP) {
|
|
39 |
TKit.log(String.format("Parsing [%s]...", arg));
|
|
40 |
}
|
|
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.
|
|
64 |
tests = tests.stream().sorted((a, b) -> a.fullName().compareTo(
|
|
65 |
b.fullName())).collect(Collectors.toList());
|
|
66 |
|
|
67 |
if (listTests) {
|
|
68 |
// Just list the tests
|
|
69 |
tests.stream().forEach(test -> System.out.println(test.fullName()));
|
|
70 |
return;
|
|
71 |
}
|
|
72 |
|
|
73 |
TKit.runTests(tests);
|
|
74 |
|
|
75 |
final long failedCount = tests.stream().filter(Functional.identity(
|
|
76 |
TestInstance::passed).negate()).count();
|
|
77 |
final long passedCount = tests.size() - failedCount;
|
|
78 |
|
|
79 |
TKit.log(String.format("[==========] %d tests ran", tests.size()));
|
|
80 |
TKit.log(String.format("[ PASSED ] %d %s", passedCount,
|
|
81 |
passedCount == 1 ? "test" : "tests"));
|
|
82 |
if (failedCount != 0) {
|
|
83 |
TKit.log(String.format("[ FAILED ] %d %s, listed below",
|
|
84 |
failedCount,
|
|
85 |
failedCount == 1 ? "test" : "tests"));
|
|
86 |
tests.stream().filter(
|
|
87 |
Functional.identity(TestInstance::passed).negate()).forEach(
|
|
88 |
test -> TKit.log(String.format("[ FAILED ] %s",
|
|
89 |
test.fullName())));
|
|
90 |
|
|
91 |
final String errorMessage = String.format("%d FAILED %s",
|
|
92 |
failedCount, failedCount == 1 ? "TEST" : "TESTS");
|
|
93 |
TKit.log(errorMessage);
|
|
94 |
throw new RuntimeException(errorMessage);
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|