Added test checking for @author in code.
This commit is contained in:
@@ -16,16 +16,34 @@
|
||||
|
||||
package org.jetbrains.jet.parsing;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class JetCodeConformanceTest extends TestCase {
|
||||
private static final Pattern JAVA_FILE_PATTERN = Pattern.compile(".+\\.java");
|
||||
private static final Pattern SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.jet|.+\\.js)");
|
||||
private static final List<File> EXCLUDED_FILES_AND_DIRS = Arrays.asList(
|
||||
new File("dependencies"),
|
||||
new File("examples"),
|
||||
new File("js/js.translator/qunit/qunit.js"),
|
||||
new File("libraries/tools/kotlin-js-tests/src/test/web/qunit.js"),
|
||||
new File("out"),
|
||||
new File("dist"),
|
||||
new File("docs"),
|
||||
new File("ideaSDK"),
|
||||
new File("compiler/tests/org/jetbrains/jet/parsing/JetCodeConformanceTest.java"));
|
||||
public static final Pattern JAVADOC_PATTERN = Pattern.compile("/\\*.+@author.+\\*/", Pattern.DOTALL);
|
||||
|
||||
public void testParserCode() throws Exception {
|
||||
for (File sourceFile : FileUtil.findFilesByMask(JAVA_FILE_PATTERN, new File("compiler/frontend/src/org/jetbrains/jet/lang/parsing"))) {
|
||||
@@ -39,4 +57,34 @@ public class JetCodeConformanceTest extends TestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testForAuthorJavadoc() throws IOException {
|
||||
List<File> filesWithAuthorJavadoc = Lists.newArrayList();
|
||||
|
||||
for (File sourceFile : FileUtil.findFilesByMask(SOURCES_FILE_PATTERN, new File("."))) {
|
||||
if (excludeFile(sourceFile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String source = FileUtil.loadFile(sourceFile);
|
||||
|
||||
if (source.contains("@author") && JAVADOC_PATTERN.matcher(source).find()) { // .contains() is invoked for optimization
|
||||
filesWithAuthorJavadoc.add(sourceFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (!filesWithAuthorJavadoc.isEmpty()) {
|
||||
fail(String.format("%d source files contain @author javadoc tag. Please remove them:\n%s",
|
||||
filesWithAuthorJavadoc.size(), StringUtil.join(filesWithAuthorJavadoc, "\n")));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean excludeFile(@NotNull File file) {
|
||||
for (File excludedFileOrDir : EXCLUDED_FILES_AND_DIRS) {
|
||||
if (FileUtil.isAncestor(excludedFileOrDir, file, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user