author | jjg |
Fri, 03 May 2013 09:56:56 -0700 | |
changeset 17544 | 80db48a54a9f |
parent 16555 | cc07dc956ff6 |
child 22444 | c79ee1e6742f |
permissions | -rw-r--r-- |
16555
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
1 |
/* |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
4 |
* |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
8 |
* |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
14 |
* |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
18 |
* |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
21 |
* questions. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
22 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
23 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
24 |
import java.io.*; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
25 |
import java.util.*; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
26 |
import java.lang.annotation.*; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
27 |
import java.lang.reflect.InvocationTargetException; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
28 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
29 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
30 |
* {@code Tester} is an abstract test-driver that provides the logic |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
31 |
* to execute test-cases, grouped by test classes. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
32 |
* A test class is a main class extending this class, that instantiate |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
33 |
* itself, and calls the {@link run} method, passing any command line |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
34 |
* arguments. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
35 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
36 |
* The {@code run} method, expects arguments to identify test-case classes. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
37 |
* A test-case class is a class extending the test class, and annotated |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
38 |
* with {@code TestCase}. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
39 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
40 |
* If no test-cases are specified, the test class directory is searched for |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
41 |
* co-located test-case classes (i.e. any class extending the test class, |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
42 |
* annotated with {@code TestCase}). |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
43 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
44 |
* Besides serving to group test-cases, extending the driver allow |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
45 |
* setting up a test-case template, and possibly overwrite default |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
46 |
* test-driver behaviour. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
47 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
48 |
public abstract class Tester { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
49 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
50 |
private static boolean debug = false; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
51 |
private static final PrintStream out = System.err; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
52 |
private static final PrintStream err = System.err; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
53 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
54 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
55 |
protected void run(String... args) throws Exception { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
56 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
57 |
final File classesdir = new File(System.getProperty("test.classes", ".")); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
58 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
59 |
String[] classNames = args; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
60 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
61 |
// If no test-cases are specified, we regard all co-located classes |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
62 |
// as potential test-cases. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
63 |
if (args.length == 0) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
64 |
final String pattern = ".*\\.class"; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
65 |
final File classFiles[] = classesdir.listFiles(new FileFilter() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
66 |
public boolean accept(File f) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
67 |
return f.getName().matches(pattern); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
68 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
69 |
}); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
70 |
ArrayList<String> names = new ArrayList<String>(classFiles.length); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
71 |
for (File f : classFiles) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
72 |
String fname = f.getName(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
73 |
names.add(fname.substring(0, fname.length() -6)); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
74 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
75 |
classNames = names.toArray(new String[names.size()]); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
76 |
} else { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
77 |
debug = true; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
78 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
79 |
// Test-cases must extend the driver type, and be marked |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
80 |
// @TestCase. Other arguments (classes) are ignored. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
81 |
// Test-cases are instantiated, and thereby executed. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
82 |
for (String clname : classNames) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
83 |
try { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
84 |
final Class tclass = Class.forName(clname); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
85 |
if (!getClass().isAssignableFrom(tclass)) continue; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
86 |
TestCase anno = (TestCase) tclass.getAnnotation(TestCase.class); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
87 |
if (anno == null) continue; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
88 |
if (!debug) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
89 |
ignore i = (ignore) tclass.getAnnotation(ignore.class); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
90 |
if (i != null) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
91 |
out.println("Ignore: " + clname); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
92 |
ignored++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
93 |
continue; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
94 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
95 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
96 |
out.println("TestCase: " + clname); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
97 |
cases++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
98 |
Tester tc = (Tester) tclass.getConstructor().newInstance(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
99 |
if (tc.errors > 0) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
100 |
error("" + tc.errors + " test points failed in " + clname); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
101 |
errors += tc.errors - 1; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
102 |
fcases++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
103 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
104 |
} catch(ReflectiveOperationException roe) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
105 |
error("Warning: " + clname + " - ReflectiveOperationException"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
106 |
roe.printStackTrace(err); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
107 |
} catch(Exception unknown) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
108 |
error("Warning: " + clname + " - uncaught exception"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
109 |
unknown.printStackTrace(err); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
110 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
111 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
112 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
113 |
String imsg = ignored > 0 ? " (" + ignored + " ignored)" : ""; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
114 |
if (errors > 0) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
115 |
throw new Error(errors + " error, in " + fcases + " of " + cases + " test-cases" + imsg); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
116 |
else |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
117 |
err.println("" + cases + " test-cases executed" + imsg + ", no errors"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
118 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
119 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
120 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
121 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
122 |
* Test-cases must be marked with the {@code TestCase} annotation, |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
123 |
* as well as extend {@code Tester} (or an driver extension |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
124 |
* specified as the first argument to the {@code main()} method. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
125 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
126 |
@Retention(RetentionPolicy.RUNTIME) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
127 |
@interface TestCase { } |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
128 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
129 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
130 |
* Individual test-cases failing due to product bugs, may temporarily |
17544
80db48a54a9f
8012728: Normalize @ignore comments on langtools tests
jjg
parents:
16555
diff
changeset
|
131 |
* be excluded by marking them like this, (where "at-" is replaced by "@") |
80db48a54a9f
8012728: Normalize @ignore comments on langtools tests
jjg
parents:
16555
diff
changeset
|
132 |
* at-ignore // 1234567: bug synopsis |
16555
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
133 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
134 |
@Retention(RetentionPolicy.RUNTIME) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
135 |
@interface ignore { } |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
136 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
137 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
138 |
* Test-cases are classes extending {@code Tester}, and |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
139 |
* calling {@link setSrc}, followed by one or more invocations |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
140 |
* of {@link verify} in the body of the constructor. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
141 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
142 |
* Sets a default test-case template, which is empty except |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
143 |
* for a key of {@code "TESTCASE"}. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
144 |
* Subclasses will typically call {@code setSrc(TestSource)} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
145 |
* to setup a useful test-case template. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
146 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
147 |
public Tester() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
148 |
this.testCase = this.getClass().getName(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
149 |
src = new TestSource("TESTCASE"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
150 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
151 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
152 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
153 |
* Set the top-level source template. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
154 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
155 |
protected Tester setSrc(TestSource src) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
156 |
this.src = src; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
157 |
return this; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
158 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
159 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
160 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
161 |
* Convenience method for calling {@code innerSrc("TESTCASE", ...)}. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
162 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
163 |
protected Tester setSrc(String... lines) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
164 |
return innerSrc("TESTCASE", lines); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
165 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
166 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
167 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
168 |
* Convenience method for calling {@code innerSrc(key, new TestSource(...))}. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
169 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
170 |
protected Tester innerSrc(String key, String... lines) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
171 |
return innerSrc(key, new TestSource(lines)); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
172 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
173 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
174 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
175 |
* Specialize the testcase template, setting replacement content |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
176 |
* for the specified key. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
177 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
178 |
protected Tester innerSrc(String key, TestSource content) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
179 |
if (src == null) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
180 |
src = new TestSource(key); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
181 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
182 |
src.setInner(key, content); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
183 |
return this; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
184 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
185 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
186 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
187 |
* On the first invocation, call {@code execute()} to compile |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
188 |
* the test-case source and process the resulting class(se) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
189 |
* into verifiable output. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
190 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
191 |
* Verify that the output matches each of the regular expressions |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
192 |
* given as argument. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
193 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
194 |
* Any failure to match constitutes a test failure, but doesn't |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
195 |
* abort the test-case. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
196 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
197 |
* Any exception (e.g. bad regular expression syntax) results in |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
198 |
* a test failure, and aborts the test-case. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
199 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
200 |
protected void verify(String... expect) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
201 |
if (!didExecute) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
202 |
try { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
203 |
execute(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
204 |
} catch(Exception ue) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
205 |
throw new Error(ue); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
206 |
} finally { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
207 |
didExecute = true; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
208 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
209 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
210 |
if (output == null) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
211 |
error("output is null"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
212 |
return; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
213 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
214 |
for (String e: expect) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
215 |
// Escape regular expressions (to allow input to be literals). |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
216 |
// Notice, characters to be escaped are themselves identified |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
217 |
// using regular expressions |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
218 |
String rc[] = { "(", ")", "[", "]", "{", "}", "$" }; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
219 |
for (String c : rc) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
220 |
e = e.replace(c, "\\" + c); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
221 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
222 |
// DEBUG: Uncomment this to test modulo constant pool index. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
223 |
// e = e.replaceAll("#[0-9]{2}", "#[0-9]{2}"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
224 |
if (!output.matches("(?s).*" + e + ".*")) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
225 |
if (!didPrint) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
226 |
out.println(output); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
227 |
didPrint = true; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
228 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
229 |
error("not matched: '" + e + "'"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
230 |
} else if(debug) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
231 |
out.println("matched: '" + e + "'"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
232 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
233 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
234 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
235 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
236 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
237 |
* Calls {@code writeTestFile()} to write out the test-case source |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
238 |
* content to a file, then call {@code compileTestFile()} to |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
239 |
* compile it, and finally run the {@link process} method to produce |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
240 |
* verifiable output. The default {@code process} method runs javap. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
241 |
* <p> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
242 |
* If an exception occurs, it results in a test failure, and |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
243 |
* aborts the test-case. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
244 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
245 |
protected void execute() throws IOException { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
246 |
err.println("TestCase: " + testCase); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
247 |
writeTestFile(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
248 |
compileTestFile(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
249 |
process(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
250 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
251 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
252 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
253 |
* Generate java source from test-case. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
254 |
* TBD: change to use javaFileObject, possibly make |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
255 |
* this class extend JavaFileObject. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
256 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
257 |
protected void writeTestFile() throws IOException { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
258 |
javaFile = new File("Test.java"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
259 |
FileWriter fw = new FileWriter(javaFile); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
260 |
BufferedWriter bw = new BufferedWriter(fw); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
261 |
PrintWriter pw = new PrintWriter(bw); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
262 |
for (String line : src) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
263 |
pw.println(line); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
264 |
if (debug) out.println(line); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
265 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
266 |
pw.close(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
267 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
268 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
269 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
270 |
* Compile the Java source code. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
271 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
272 |
protected void compileTestFile() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
273 |
String path = javaFile.getPath(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
274 |
String params[] = { "-source", "1.8", "-g", path }; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
275 |
int rc = com.sun.tools.javac.Main.compile(params); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
276 |
if (rc != 0) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
277 |
throw new Error("compilation failed. rc=" + rc); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
278 |
classFile = new File(path.substring(0, path.length() - 5) + ".class"); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
279 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
280 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
281 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
282 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
283 |
* Process class file to generate output for verification. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
284 |
* The default implementation simply runs javap. This might be |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
285 |
* overwritten to generate output in a different manner. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
286 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
287 |
protected void process() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
288 |
String testClasses = "."; //System.getProperty("test.classes", "."); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
289 |
StringWriter sw = new StringWriter(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
290 |
PrintWriter pw = new PrintWriter(sw); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
291 |
String[] args = { "-v", "-classpath", testClasses, "Test" }; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
292 |
int rc = com.sun.tools.javap.Main.run(args, pw); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
293 |
if (rc != 0) |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
294 |
throw new Error("javap failed. rc=" + rc); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
295 |
pw.close(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
296 |
output = sw.toString(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
297 |
if (debug) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
298 |
out.println(output); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
299 |
didPrint = true; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
300 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
301 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
302 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
303 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
304 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
305 |
private String testCase; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
306 |
private TestSource src; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
307 |
private File javaFile = null; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
308 |
private File classFile = null; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
309 |
private String output = null; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
310 |
private boolean didExecute = false; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
311 |
private boolean didPrint = false; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
312 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
313 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
314 |
protected void error(String msg) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
315 |
err.println("Error: " + msg); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
316 |
errors++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
317 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
318 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
319 |
private int cases; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
320 |
private int fcases; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
321 |
private int errors; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
322 |
private int ignored; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
323 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
324 |
/** |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
325 |
* The TestSource class provides a simple container for |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
326 |
* test cases. It contains an array of source code lines, |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
327 |
* where zero or more lines may be markers for nested lines. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
328 |
* This allows representing templates, with specialization. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
329 |
* <P> |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
330 |
* This may be generalized to support more advance combo |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
331 |
* tests, but presently it's only used with a static template, |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
332 |
* and one level of specialization. |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
333 |
*/ |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
334 |
public class TestSource implements Iterable<String> { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
335 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
336 |
private String[] lines; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
337 |
private Hashtable<String, TestSource> innerSrc; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
338 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
339 |
public TestSource(String... lines) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
340 |
this.lines = lines; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
341 |
innerSrc = new Hashtable<String, TestSource>(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
342 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
343 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
344 |
public void setInner(String key, TestSource inner) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
345 |
innerSrc.put(key, inner); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
346 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
347 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
348 |
public void setInner(String key, String... lines) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
349 |
innerSrc.put(key, new TestSource(lines)); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
350 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
351 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
352 |
public Iterator<String> iterator() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
353 |
return new LineIterator(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
354 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
355 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
356 |
private class LineIterator implements Iterator<String> { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
357 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
358 |
int nextLine = 0; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
359 |
Iterator<String> innerIt = null; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
360 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
361 |
public boolean hasNext() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
362 |
return nextLine < lines.length; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
363 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
364 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
365 |
public String next() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
366 |
if (!hasNext()) throw new NoSuchElementException(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
367 |
String str = lines[nextLine]; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
368 |
TestSource inner = innerSrc.get(str); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
369 |
if (inner == null) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
370 |
nextLine++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
371 |
return str; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
372 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
373 |
if (innerIt == null) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
374 |
innerIt = inner.iterator(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
375 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
376 |
if (innerIt.hasNext()) { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
377 |
return innerIt.next(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
378 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
379 |
innerIt = null; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
380 |
nextLine++; |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
381 |
return next(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
382 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
383 |
|
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
384 |
public void remove() { |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
385 |
throw new UnsupportedOperationException(); |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
386 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
387 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
388 |
} |
cc07dc956ff6
8005220: RFE to write javap tests for repeating annotations.
jjg
parents:
diff
changeset
|
389 |
} |