blob: 574da0b2ec0732f2c67388d966d537a5ef0a86db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package ignore;
import japa.parser.JavaParser;
import japa.parser.ParseException;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
/*
* Created on 14/10/2007
*/
/**
* @author Julio Vilmar Gesser
*/
public class TestRunner {
private static final File ROOT = //
new File("D:/Downloads/openjdk-7-ea-src-b27-22_may_2008/openjdk/langtools/test/tools/javac" //
//"C:/Documents and Settings/jgesser/Desktop/openjdk-7-ea-src-b27-22_may_2008/openjdk" //
//"C:/Documents and Settings/jgesser/Desktop/openjdk-6-src-b09-11_apr_2008/jdk" //
);
public static void main(String[] args) {
new TestRunner().run();
}
private void visitAllJavaFiles(FileFilter callback, File dir) {
File[] listFiles = dir.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isDirectory() || file.getName().endsWith(".java");
}
});
if (listFiles != null) {
for (File element : listFiles) {
if (element.isDirectory()) {
visitAllJavaFiles(callback, element);
} else {
callback.accept(element);
}
}
}
}
int runCount = 0;
long runTime = 0;
public void run() {
visitAllJavaFiles(new FileFilter() {
public boolean accept(File javaFile) {
//System.out.println("Visiting file: " + javaFile.getPath());
try {
runTest(javaFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
return false;
}
}, ROOT);
System.out.println("Compiled " + runCount + " in " + runTime + " ms, avarage of " + (((double) runTime) / runCount));
}
private void runTest(File javaFile) throws IOException {
// try {
// JavaParser.parse(javaFile);
// } catch (ParseException e) {
// System.out.println("<<error>> " + e.getMessage());
// }
StringBuilder buf = new StringBuilder();
try {
FileInputStream in = new FileInputStream(javaFile);
try {
int i;
while ((i = in.read()) >= 0) {
buf.append((char) i);
}
} finally {
in.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (buf.indexOf("@test") < 0) {
return;
// System.out.println("Skiping file: " + javaFile.getPath());
}
boolean fail = false;
// if (buf.indexOf("@compile ") == -1) {
// fail = buf.indexOf("compile/fail") >= 0;
// }
if (!(buf.indexOf("@compile ") >= 0 && buf.indexOf("compile/fail") < 0)) {
return;
}
try {
//System.out.println("Parsing file: " + javaFile.getPath());
runCount++;
long time = System.currentTimeMillis();
JavaParser.parse(javaFile);
runTime += System.currentTimeMillis() - time;
if (fail) {
System.out.println("Testing file: " + javaFile.getPath());
System.out.println(" >>Parser error expected but not ocurred");
}
} catch (ParseException e) {
if (!fail) {
System.out.println("Testing file: " + javaFile.getPath());
System.out.println(" >>Parser error not expected: " + e.getMessage());
}
} catch (Error e) {
System.out.println("Testing file: " + javaFile.getPath());
System.out.println(" >>Unknow error: " + e.getMessage());
}
}
}
|