Simplified JetCodeConformanceTest.

This commit is contained in:
Evgeny Gerashchenko
2012-12-28 14:50:54 +04:00
parent 55acb2a675
commit 6d95bb7f70
@@ -16,62 +16,27 @@
package org.jetbrains.jet.parsing;
import junit.framework.Test;
import com.intellij.openapi.util.io.FileUtil;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author abreslav
*/
public class JetCodeConformanceTest extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
TestSuite ats = new TestSuite("Side-effect-free at()'s in assertions");
suite.addTest(ats);
File parsingSourceDir = new File("./compiler/frontend/src/org/jetbrains/jet/lang/parsing");
for (File sourceFile : parsingSourceDir.listFiles()) {
if (sourceFile.getName().endsWith(".java")) {
ats.addTest(new JetCodeConformanceTest(sourceFile.getName(), sourceFile));
public class JetCodeConformanceTest extends TestCase {
private static final Pattern JAVA_FILE_PATTERN = Pattern.compile(".+\\.java");
public void testParserCode() throws Exception {
for (File sourceFile : FileUtil.findFilesByMask(JAVA_FILE_PATTERN, new File("compiler/frontend/src/org/jetbrains/jet/lang/parsing"))) {
String source = FileUtil.loadFile(sourceFile);
Pattern atPattern = Pattern.compile("assert.*?[^_]at.*?$", Pattern.MULTILINE);
Matcher matcher = atPattern.matcher(source);
if (matcher.find()) {
fail("An at-method with side-effects is used inside assert: " + matcher.group() + "\nin file: " + sourceFile);
}
}
return suite;
}
private final File sourceFile;
public JetCodeConformanceTest(String name, File sourceFile) {
super(name);
this.sourceFile = sourceFile;
}
@Override
protected void runTest() throws Throwable {
checkSourceFile(sourceFile);
}
private void checkSourceFile(File sourceFile) throws IOException {
FileReader reader = new FileReader(sourceFile);
StringBuilder builder = new StringBuilder();
int c;
while ((c = reader.read()) >= 0) {
builder.append((char) c);
}
String source = builder.toString();
Pattern atPattern = Pattern.compile("assert.*?[^_]at.*?$", Pattern.MULTILINE);
Matcher matcher = atPattern.matcher(source);
boolean match = matcher.find();
if (match) {
fail("An at-method with side-ffects is used inside assert: " + matcher.group());
}
}
}