23 |
23 |
24 package jdk.jpackage.test; |
24 package jdk.jpackage.test; |
25 |
25 |
26 import java.util.ArrayList; |
26 import java.util.ArrayList; |
27 import java.util.List; |
27 import java.util.List; |
|
28 import java.util.function.Function; |
28 import java.util.function.Predicate; |
29 import java.util.function.Predicate; |
29 import java.util.stream.Collectors; |
30 import java.util.stream.Collectors; |
30 import static jdk.jpackage.test.TestBuilder.CMDLINE_ARG_PREFIX; |
31 import static jdk.jpackage.test.TestBuilder.CMDLINE_ARG_PREFIX; |
31 |
32 |
32 |
33 |
34 public static void main(String args[]) throws Throwable { |
35 public static void main(String args[]) throws Throwable { |
35 boolean listTests = false; |
36 boolean listTests = false; |
36 List<TestInstance> tests = new ArrayList<>(); |
37 List<TestInstance> tests = new ArrayList<>(); |
37 try (TestBuilder testBuilder = new TestBuilder(tests::add)) { |
38 try (TestBuilder testBuilder = new TestBuilder(tests::add)) { |
38 for (var arg : args) { |
39 for (var arg : args) { |
39 if (TKit.VERBOSE_TEST_SETUP) { |
40 TestBuilder.trace(String.format("Parsing [%s]...", arg)); |
40 TKit.log(String.format("Parsing [%s]...", arg)); |
|
41 } |
|
42 |
41 |
43 if ((CMDLINE_ARG_PREFIX + "list").equals(arg)) { |
42 if ((CMDLINE_ARG_PREFIX + "list").equals(arg)) { |
44 listTests = true; |
43 listTests = true; |
45 continue; |
44 continue; |
46 } |
45 } |
60 } |
59 } |
61 } |
60 } |
62 } |
61 } |
63 |
62 |
64 // Order tests by their full names to have stable test sequence. |
63 // Order tests by their full names to have stable test sequence. |
65 tests = tests.stream().sorted((a, b) -> a.fullName().compareTo( |
64 List<TestInstance> orderedTests = tests.stream() |
66 b.fullName())).collect(Collectors.toList()); |
65 .sorted((a, b) -> a.fullName().compareTo(b.fullName())) |
|
66 .collect(Collectors.toList()); |
67 |
67 |
68 if (listTests) { |
68 if (listTests) { |
69 // Just list the tests |
69 // Just list the tests |
70 tests.stream().forEach(test -> System.out.println(test.fullName())); |
70 orderedTests.stream().forEach(test -> System.out.println(String.format( |
|
71 "%s; workDir=[%s]", test.fullName(), test.workDir()))); |
71 return; |
72 return; |
72 } |
73 } |
73 |
74 |
|
75 TKit.withExtraLogStream(() -> runTests(orderedTests)); |
|
76 } |
|
77 |
|
78 private static void runTests(List<TestInstance> tests) { |
74 TKit.runTests(tests); |
79 TKit.runTests(tests); |
75 |
80 |
76 final long passedCount = tests.stream().filter(TestInstance::passed).count(); |
81 final long passedCount = tests.stream().filter(TestInstance::passed).count(); |
77 TKit.log(String.format("[==========] %d tests ran", tests.size())); |
82 TKit.log(String.format("[==========] %d tests ran", tests.size())); |
78 TKit.log(String.format("[ PASSED ] %d %s", passedCount, |
83 TKit.log(String.format("[ PASSED ] %d %s", passedCount, |
79 passedCount == 1 ? "test" : "tests")); |
84 passedCount == 1 ? "test" : "tests")); |
80 |
85 |
81 reportDetails(tests, "[ SKIPPED ]", TestInstance::skipped); |
86 reportDetails(tests, "[ SKIPPED ]", TestInstance::skipped, false); |
82 reportDetails(tests, "[ FAILED ]", TestInstance::failed); |
87 reportDetails(tests, "[ FAILED ]", TestInstance::failed, true); |
83 |
88 |
84 var withSkipped = reportSummary(tests, "SKIPPED", TestInstance::skipped); |
89 var withSkipped = reportSummary(tests, "SKIPPED", TestInstance::skipped); |
85 var withFailures = reportSummary(tests, "FAILED", TestInstance::failed); |
90 var withFailures = reportSummary(tests, "FAILED", TestInstance::failed); |
86 |
91 |
87 if (withFailures != null) { |
92 if (withFailures != null) { |
92 tests.stream().filter(TestInstance::skipped).findFirst().get().rethrowIfSkipped(); |
97 tests.stream().filter(TestInstance::skipped).findFirst().get().rethrowIfSkipped(); |
93 } |
98 } |
94 } |
99 } |
95 |
100 |
96 private static long reportDetails(List<TestInstance> tests, |
101 private static long reportDetails(List<TestInstance> tests, |
97 String label, Predicate<TestInstance> selector) { |
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 |
98 final long count = tests.stream().filter(selector).count(); |
112 final long count = tests.stream().filter(selector).count(); |
99 if (count != 0) { |
113 if (count != 0) { |
100 TKit.log(String.format("%s %d %s, listed below", label, count, count |
114 TKit.log(String.format("%s %d %s, listed below", label, count, count |
101 == 1 ? "test" : "tests")); |
115 == 1 ? "test" : "tests")); |
102 tests.stream().filter(selector).forEach(test -> TKit.log( |
116 tests.stream().filter(selector).map(makeMessage).forEachOrdered( |
103 String.format("%s %s", label, test.fullName()))); |
117 TKit::log); |
104 } |
118 } |
105 |
119 |
106 return count; |
120 return count; |
107 } |
121 } |
108 |
122 |