author | prr |
Wed, 29 Nov 2017 09:47:02 -0800 (2017-11-29) | |
changeset 47982 | 44371ff1ee9a |
parent 47216 | 71c04702a3d5 |
child 48914 | 0a185d6fafa1 |
permissions | -rw-r--r-- |
42167
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
1 |
/* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
4 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
8 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
13 |
* accompanied this code). |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
14 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
18 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
21 |
* questions. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
22 |
*/ |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
23 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
24 |
/* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
25 |
* @test |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
26 |
* @summary Tests to verify jimage 'list' action |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
27 |
* @library /test/lib |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
28 |
* @modules jdk.jlink/jdk.tools.jimage |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
29 |
* @build jdk.test.lib.Asserts |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
30 |
* @run main JImageListTest |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
31 |
*/ |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
32 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
33 |
import java.io.IOException; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
34 |
import java.nio.file.Files; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
35 |
import java.nio.file.Path; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
37 |
import java.util.*; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
38 |
import java.util.stream.Collectors; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
39 |
import java.util.stream.Stream; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
40 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
41 |
import static jdk.test.lib.Asserts.assertEquals; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
42 |
import static jdk.test.lib.Asserts.assertFalse; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
43 |
import static jdk.test.lib.Asserts.assertTrue; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
44 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
45 |
public class JImageListTest extends JImageCliTest { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
46 |
public void testList() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
47 |
jimage("list", getImagePath()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
48 |
.assertSuccess() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
49 |
.resultChecker(r -> { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
50 |
String[] lines = r.output.split(System.lineSeparator()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
51 |
assertTrue(lines.length > 0, "Option --list has output."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
52 |
assertTrue(lines[0].startsWith("jimage: " + getImagePath()), |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
53 |
"Output should start with jimage path."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
54 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
55 |
List<String> modules = Stream.of(lines) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
56 |
.filter(s -> s.startsWith("Module: ")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
57 |
.map(s -> s.substring(s.indexOf(':') + 1).trim()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
58 |
.collect(Collectors.toList()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
59 |
assertTrue(modules.size() > 0, "Image contains at least one module."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
60 |
assertTrue(modules.indexOf("java.base") > 0, "Module java.base found."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
61 |
}); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
62 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
63 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
64 |
public void testListHelp() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
65 |
for (String opt : Arrays.asList("-h", "--help")) { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
66 |
jimage("list", opt) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
67 |
.assertSuccess() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
68 |
.resultChecker(r -> { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
69 |
// list - descriptive text |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
70 |
assertMatches("\\s+list\\s+-\\s+.*", r.output); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
71 |
}); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
72 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
73 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
74 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
75 |
public void testListVerbose() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
76 |
jimage("list", "--verbose", getImagePath()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
77 |
.assertSuccess() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
78 |
.resultChecker(r -> { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
79 |
assertMatches("Offset\\s+Size\\s+Compressed\\s+Entry", r.output); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
80 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
81 |
String[] lines = r.output.split("[" + System.lineSeparator() + "]+"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
82 |
assertTrue(lines.length > 0, "Option --list has output."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
83 |
assertTrue(lines[0].startsWith("jimage: " + getImagePath()), |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
84 |
"Output should start with jimage path."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
85 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
86 |
List<String> modules = Stream.of(lines) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
87 |
.filter(s -> s.startsWith("Module: ")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
88 |
.map(s -> s.substring(s.indexOf(':') + 1).trim()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
89 |
.collect(Collectors.toList()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
90 |
assertTrue(modules.size() > 0, "Image contains at least one module."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
91 |
assertTrue(modules.indexOf("java.base") > 0, "Module java.base found."); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
92 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
93 |
Set<String> entries = Stream.of(lines) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
94 |
.filter(s -> { return !s.startsWith("Module: ") && !s.startsWith("Offset"); }) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
95 |
// Offset \d+ Size \d+ Compressed \d+ Entry \.* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
96 |
.filter(s -> !s.matches("\\s+\\d+\\s+\\d+\\s+\\d+\\s+.*")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
97 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
98 |
assertEquals(entries, new HashSet<>() {{ add("jimage: " + getImagePath()); }}, |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
99 |
"All entries should be in format: Offset Size Compressed Entry"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
100 |
}); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
101 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
102 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
103 |
public void testListIncludeAllWithGlob() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
104 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
105 |
JImageResult listAllGlob = jimage("list", "--include", "**", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
106 |
assertEquals(listAllGlob.output, listAll.output, "--include ** should produce the same output"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
107 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
108 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
109 |
public void testListIncludeWithGlob() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
110 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
111 |
Set<String> expected = Stream.of(listAll.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
112 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
113 |
.filter(s -> s.startsWith("java/util/zip")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
114 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
115 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
116 |
JImageResult listJavaUtil = jimage("list", "--include", "/java.base/java/util/zip/**", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
117 |
Set<String> actual = Stream.of(listJavaUtil.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
118 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
119 |
.filter(s -> !s.startsWith("jimage:") && !s.startsWith("Module:")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
120 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
121 |
assertEquals(actual, expected, "All java.util.zip classes are listed"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
122 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
123 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
124 |
public void testListIncludeNoMatchWithGlob() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
125 |
JImageResult listNotMatching = jimage("list", "--include", "not_matching", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
126 |
Set<String> entries = Stream.of(listNotMatching.output.split("["+ System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
127 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
128 |
.filter(s -> !s.startsWith("jimage:") && !s.startsWith("Module:")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
129 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
130 |
assertEquals(entries, Collections.emptySet(), "No java.util classes are listed"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
131 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
132 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
133 |
public void testListIncludeAllWithExplicitGlob() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
134 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
135 |
JImageResult listAllGlob = jimage("list", "--include", "glob:**", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
136 |
assertEquals(listAllGlob.output, listAll.output, "--include glob:** should produce the same output"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
137 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
138 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
139 |
public void testListIncludeAllWithRegex() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
140 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
141 |
JImageResult listAllRegex = jimage("list", "--include", "regex:.*", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
142 |
assertEquals(listAllRegex.output, listAll.output, "--include regex:.* should produce the same output"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
143 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
144 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
145 |
public void testListIncludeWithRegex() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
146 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
147 |
Set<String> expected = Stream.of(listAll.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
148 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
149 |
.filter(s -> s.startsWith("java/text/")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
150 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
151 |
assertFalse(expected.isEmpty(), "There should be classes from java.text package"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
152 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
153 |
JImageResult listJavaText = jimage("list", "--include", "regex:/java.base/java/text/.*", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
154 |
Set<String> actual = Stream.of(listJavaText.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
155 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
156 |
.filter(s -> !s.startsWith("jimage:") && !s.startsWith("Module:")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
157 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
158 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
159 |
assertEquals(actual, expected, "All java.text classes are listed"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
160 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
161 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
162 |
public void testListIncludeNoMatchWithRegex() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
163 |
JImageResult listNotMatching = jimage("list", "--include", "regex:not_matching", |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
164 |
getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
165 |
Set<String> entries = Stream.of(listNotMatching.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
166 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
167 |
.filter(s -> !s.startsWith("jimage:") && !s.startsWith("Module:")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
168 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
169 |
assertEquals(entries, Collections.emptySet(), "No classes are listed"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
170 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
171 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
172 |
public void testListIncludeMultiplePatterns() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
173 |
JImageResult listAll = jimage("list", getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
174 |
Set<String> expected = Stream.of(listAll.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
175 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
176 |
.filter(s -> s.startsWith("java/time/") || s.startsWith("java/util/zip")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
177 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
178 |
assertFalse(expected.isEmpty(), "There should be classes from java.time and java.io packages"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
179 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
180 |
JImageResult listMatched = jimage("list", "--include", "glob:/java.base/java/time/**,regex:/java.base/java/util/zip/.*", |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
181 |
getImagePath()).assertSuccess(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
182 |
Set<String> actual = Stream.of(listMatched.output.split("[" + System.lineSeparator() + "]+")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
183 |
.map(String::trim) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
184 |
.filter(s -> !s.startsWith("jimage:") && !s.startsWith("Module:")) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
185 |
.collect(Collectors.toSet()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
186 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
187 |
assertEquals(actual, expected, "All java.time and java.util.zip classes are listed"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
188 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
189 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
190 |
public void testListNoImageSpecified() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
191 |
jimage("list", "") |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
192 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
193 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
194 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
195 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
196 |
public void testListEmptyFile() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
197 |
Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "empty_file"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
198 |
jimage("list", tmp.toString()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
199 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
200 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
201 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
202 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
203 |
public void testListNotAnImage() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
204 |
Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
205 |
Files.write(tmp, "This is not an image".getBytes()); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
206 |
jimage("list", tmp.toString()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
207 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
208 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
209 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
210 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
211 |
public void testListNotExistingImage() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
212 |
Path tmp = Paths.get(".", "not_existing_image"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
213 |
Files.deleteIfExists(tmp); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
214 |
jimage("list", tmp.toString()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
215 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
216 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
217 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
218 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
219 |
public void testListWithUnknownOption() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
220 |
jimage("list", "--unknown") |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
221 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
222 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
223 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
224 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
225 |
public static void main(String[] args) throws Throwable { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
226 |
new JImageListTest().runTests(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
227 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
228 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
229 |