author | alundblad |
Tue, 22 Apr 2014 16:51:10 +0200 | |
changeset 24067 | 76e7b6bbbd85 |
child 32337 | c9d3ab9f601c |
permissions | -rw-r--r-- |
24067
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
1 |
/* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
4 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
10 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
15 |
* accompanied this code). |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
16 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
20 |
* |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
23 |
* questions. |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
24 |
*/ |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
25 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
26 |
package util; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
27 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
28 |
import java.nio.file.Path; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
29 |
import java.util.Collection; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
30 |
import java.util.HashSet; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
31 |
import java.util.Iterator; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
32 |
import java.util.List; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
33 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
34 |
import com.sun.tools.sjavac.options.SourceLocation; |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
35 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
36 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
37 |
public class OptionTestUtil { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
38 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
39 |
public static void checkFilesFound(Collection<String> found, Path... expected) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
40 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
41 |
Collection<String> expectedStrs = new HashSet<String>(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
42 |
for (Path p : expected) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
43 |
expectedStrs.add(p.toString()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
44 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
45 |
if (!expectedStrs.containsAll(found)) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
46 |
throw new AssertionError("Expected (" + expectedStrs + ") does not " + |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
47 |
"contain all actual (" + found + ")"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
48 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
49 |
if (!found.containsAll(expectedStrs)) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
50 |
throw new AssertionError("Actual (" + found + ") does not " + |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
51 |
"contain all expected (" + expectedStrs + ")"); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
52 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
53 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
54 |
public static void assertEquals(List<SourceLocation> expected, List<SourceLocation> actual) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
55 |
if (expected.size() != actual.size()) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
56 |
throw new AssertionError("Expected locs of length " + expected.size() + " but got something of size " + actual.size()); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
57 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
58 |
Iterator<SourceLocation> iter1 = expected.iterator(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
59 |
Iterator<SourceLocation> iter2 = actual.iterator(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
60 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
61 |
while (iter1.hasNext()) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
62 |
SourceLocation sl1 = iter1.next(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
63 |
SourceLocation sl2 = iter2.next(); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
64 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
65 |
if (!sl1.getPath().equals(sl2.getPath()) || |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
66 |
!sl1.getIncludes().equals(sl2.getIncludes()) || |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
67 |
!sl1.getExcludes().equals(sl2.getExcludes()) || |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
68 |
!sl1.getIncludedFiles().equals(sl2.getIncludedFiles()) || |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
69 |
!sl1.getExcludedFiles().equals(sl2.getExcludedFiles())) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
70 |
throw new AssertionError("Expected " + sl1 + " but got " + sl2); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
71 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
72 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
73 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
74 |
public static void assertEquals(Object expected, Object actual) { |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
75 |
if (!expected.equals(actual)) |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
76 |
throw new AssertionError("Expected " + expected + " but got " + actual); |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
77 |
} |
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
78 |
|
76e7b6bbbd85
8035063: Option handling in sjavac needs to be rewritten
alundblad
parents:
diff
changeset
|
79 |
} |