Unregistered bunch directives and files test
This commit is contained in:
committed by
Nikolay Krasko
parent
412c562572
commit
5fc6fa8619
@@ -26,6 +26,8 @@ class CodeConformanceTest : TestCase() {
|
|||||||
companion object {
|
companion object {
|
||||||
private val JAVA_FILE_PATTERN = Pattern.compile(".+\\.java")
|
private val JAVA_FILE_PATTERN = Pattern.compile(".+\\.java")
|
||||||
private val SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)")
|
private val SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)")
|
||||||
|
private val SOURCES_BUNCH_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)(\\.\\w+)?")
|
||||||
|
private const val MAX_STEPS_COUNT = 100
|
||||||
private val EXCLUDED_FILES_AND_DIRS = listOf(
|
private val EXCLUDED_FILES_AND_DIRS = listOf(
|
||||||
"android.tests.dependencies",
|
"android.tests.dependencies",
|
||||||
"buildSrc",
|
"buildSrc",
|
||||||
@@ -97,6 +99,46 @@ class CodeConformanceTest : TestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isCorrectExtension(filename: String, extensions: Set<String>): Boolean {
|
||||||
|
val additionalExtensions = listOf(
|
||||||
|
"after", "new", "before", "expected",
|
||||||
|
"todo", "delete", "touch", "prefix", "postfix", "map",
|
||||||
|
"fragment", "after2", "result", "log", "messages", "conflicts", "match", "imports", "txt", "xml"
|
||||||
|
)
|
||||||
|
val possibleAdditionalExtensions = extensions.plus(additionalExtensions)
|
||||||
|
val fileExtensions = filename.split("\\.").drop(1)
|
||||||
|
if (fileExtensions.size < 2) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val extension = fileExtensions.last()
|
||||||
|
|
||||||
|
return !(extension !in possibleAdditionalExtensions && extension.toIntOrNull() ?: MAX_STEPS_COUNT >= MAX_STEPS_COUNT)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testForgottenBunchDirectivesAndFiles() {
|
||||||
|
val root = File("").absoluteFile
|
||||||
|
val extensions = File(root, ".bunch").readLines().map { it.split("_") }.flatten().toSet()
|
||||||
|
val failBuilder = mutableListOf<String>()
|
||||||
|
for (sourceFile in FileUtil.findFilesByMask(SOURCES_BUNCH_FILE_PATTERN, root)) {
|
||||||
|
if (EXCLUDED_FILES_AND_DIRS.any { FileUtil.isAncestor(it, sourceFile, false) }) continue
|
||||||
|
|
||||||
|
val matches = Regex("BUNCH: (\\w+)").findAll(sourceFile.readText())
|
||||||
|
.map { it.groupValues[1] }.toSet().filterNot { it in extensions }
|
||||||
|
for (bunch in matches) {
|
||||||
|
val filename = FileUtil.toSystemIndependentName(sourceFile.absoluteFile.toRelativeString(root))
|
||||||
|
failBuilder.add("$filename has unregistered $bunch bunch directive")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isCorrectExtension(sourceFile.name, extensions)) {
|
||||||
|
val filename = FileUtil.toSystemIndependentName(sourceFile.absoluteFile.toRelativeString(root))
|
||||||
|
failBuilder.add("$filename has unknown bunch extension")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (failBuilder.isNotEmpty()) {
|
||||||
|
fail("\n" + failBuilder.joinToString("\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun testNoBadSubstringsInProjectCode() {
|
fun testNoBadSubstringsInProjectCode() {
|
||||||
class TestData(val message: String, val filter: (String) -> Boolean) {
|
class TestData(val message: String, val filter: (String) -> Boolean) {
|
||||||
val result: MutableList<File> = ArrayList()
|
val result: MutableList<File> = ArrayList()
|
||||||
|
|||||||
@@ -39,19 +39,6 @@ class ScratchFileModuleInfoProvider(val project: Project) : ProjectComponent {
|
|||||||
val ktFile = scratchFile.getPsiFile() as? KtFile ?: return
|
val ktFile = scratchFile.getPsiFile() as? KtFile ?: return
|
||||||
val file = ktFile.virtualFile ?: return
|
val file = ktFile.virtualFile ?: return
|
||||||
|
|
||||||
// BUNCH: 181 scratch files are created with .kt extension
|
|
||||||
if (file.extension == KotlinFileType.EXTENSION) {
|
|
||||||
runWriteAction {
|
|
||||||
var newName = file.nameWithoutExtension + STD_SCRIPT_EXT
|
|
||||||
var i = 1
|
|
||||||
while (file.parent.findChild(newName) != null) {
|
|
||||||
newName = file.nameWithoutExtension + "_" + i + STD_SCRIPT_EXT
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
file.rename(this, newName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.extension != STD_SCRIPT_SUFFIX) {
|
if (file.extension != STD_SCRIPT_SUFFIX) {
|
||||||
LOG.error("Kotlin Scratch file should have .kts extension. Cannot add scratch panel for ${file.path}")
|
LOG.error("Kotlin Scratch file should have .kts extension. Cannot add scratch panel for ${file.path}")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user