author | smarks |
Tue, 01 Nov 2016 11:28:16 -0700 | |
changeset 41863 | 98b049c8b848 |
parent 41439 | ee4857e4fa85 |
child 41933 | 8114041bc6b0 |
permissions | -rw-r--r-- |
40596 | 1 |
/* |
2 |
* Copyright (c) 2016, 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 |
/* |
|
25 |
* @test |
|
26 |
* @summary Basic test of jdeprscan's scanning phase. |
|
27 |
* @modules jdk.jdeps/com.sun.tools.jdeprscan |
|
28 |
* @library ../../../cases |
|
29 |
* @library ../../../usage |
|
30 |
* @build jdk.deprcases.members.* jdk.deprcases.types.* |
|
31 |
* @build jdk.deprusage.* |
|
32 |
* @build jdk.jdeprscan.TestScan |
|
33 |
* @run testng jdk.jdeprscan.TestScan |
|
34 |
*/ |
|
35 |
||
36 |
package jdk.jdeprscan; |
|
37 |
||
38 |
import com.sun.tools.jdeprscan.Main; |
|
39 |
import java.io.BufferedReader; |
|
40 |
import java.io.ByteArrayInputStream; |
|
41 |
import java.io.ByteArrayOutputStream; |
|
42 |
import java.io.IOException; |
|
43 |
import java.io.InputStreamReader; |
|
44 |
import java.io.PrintStream; |
|
45 |
import java.nio.charset.StandardCharsets; |
|
46 |
import java.nio.file.Files; |
|
47 |
import java.nio.file.Path; |
|
48 |
import java.nio.file.Paths; |
|
49 |
import java.util.HashSet; |
|
50 |
import java.util.Set; |
|
51 |
import java.util.stream.Collectors; |
|
52 |
import org.testng.Assert; |
|
53 |
||
54 |
import org.testng.annotations.Test; |
|
55 |
||
56 |
import static org.testng.Assert.assertTrue; |
|
57 |
||
58 |
||
59 |
public class TestScan { |
|
60 |
Set<String> loadExpected() throws IOException { |
|
61 |
Path expFile = Paths.get(System.getProperty("test.src"), "TestScanExpected.txt"); |
|
62 |
return new HashSet<>(Files.readAllLines(expFile, StandardCharsets.UTF_8)); |
|
63 |
} |
|
64 |
||
65 |
@Test |
|
66 |
public void testScanAgainstReferenceFile() throws IOException { |
|
67 |
String testclasses = System.getProperty("test.classes"); |
|
68 |
String deprcases = testclasses + "/../../../cases"; |
|
69 |
String deprusage = testclasses + "/../../../usage"; |
|
70 |
||
71 |
Set<String> expected = loadExpected(); |
|
72 |
System.out.println("expected = " + expected); |
|
73 |
||
74 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
75 |
try (PrintStream out = new PrintStream(baos, false, "UTF-8")) { |
|
76 |
boolean r = Main.call(out, System.err, |
|
41439
ee4857e4fa85
8161338: (jdeprscan) remove JEP 293 non-conforming -cp option
smarks
parents:
40596
diff
changeset
|
77 |
"--class-path", deprcases, "--Xload-dir", deprcases, deprusage); |
40596 | 78 |
assertTrue(r); |
79 |
} |
|
80 |
byte[] bytes = baos.toByteArray(); |
|
81 |
||
82 |
System.out.println("--- output ---"); |
|
83 |
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); |
|
84 |
bais.transferTo(System.out); |
|
85 |
System.out.println("--- end output ---"); |
|
86 |
||
87 |
Set<String> actual = |
|
88 |
new BufferedReader( |
|
89 |
new InputStreamReader( |
|
90 |
new ByteArrayInputStream(bytes), StandardCharsets.UTF_8)) |
|
91 |
.lines() |
|
41863
98b049c8b848
8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents:
41439
diff
changeset
|
92 |
.filter(line -> !line.endsWith(":")) |
40596 | 93 |
.map(line -> line.split(" +")) |
94 |
.map(array -> array[1]) |
|
95 |
.collect(Collectors.toSet()); |
|
96 |
System.out.println("actual = " + actual); |
|
97 |
||
98 |
Set<String> diff1 = new HashSet<>(expected); |
|
99 |
diff1.removeAll(actual); |
|
100 |
Set<String> diff2 = new HashSet<>(actual); |
|
101 |
diff2.removeAll(expected); |
|
102 |
||
103 |
if (diff1.size() > 0 || diff2.size() > 0) { |
|
104 |
System.out.println("missing items: " + diff1); |
|
105 |
System.out.println("extra items: " + diff2); |
|
106 |
} |
|
107 |
||
108 |
Assert.assertEquals(diff1.size(), 0); |
|
109 |
Assert.assertEquals(diff2.size(), 0); |
|
110 |
} |
|
111 |
} |