From 8db588c7f04a299a2253846485629bb6466cc943 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 10 Aug 2020 14:29:08 +0300 Subject: [PATCH] Optimize testNoBadSubstringsInProjectCode test Don't visit ignored directories --- .../kotlin/code/CodeConformanceTest.kt | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt b/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt index 1eeb84848a2..7f98a1c5b74 100644 --- a/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt @@ -167,59 +167,62 @@ class CodeConformanceTest : TestCase() { val tests = listOf( TestData( - "%d source files contain @author javadoc tag.\nPlease remove them or exclude in this test:\n%s", - { source -> - // substring check is an optimization - "@author" in source && atAuthorPattern.matcher(source).find() && - "ASM: a very small and fast Java bytecode manipulation framework" !in source && - "package org.jetbrains.kotlin.tools.projectWizard.settings.version.maven" !in source - } - ), + "%d source files contain @author javadoc tag.\nPlease remove them or exclude in this test:\n%s" + ) { source -> + // substring check is an optimization + "@author" in source && atAuthorPattern.matcher(source).find() && + "ASM: a very small and fast Java bytecode manipulation framework" !in source && + "package org.jetbrains.kotlin.tools.projectWizard.settings.version.maven" !in source + }, TestData( "%d source files use something from com.beust.jcommander.internal package.\n" + "This code won't work when there's no TestNG in the classpath of our IDEA plugin, " + "because there's only an optional dependency on testng.jar.\n" + "Most probably you meant to use Guava's Lists, Maps or Sets instead. " + - "Please change references in these files to com.google.common.collect:\n%s", - { source -> - "com.beust.jcommander.internal" in source - } - ), + "Please change references in these files to com.google.common.collect:\n%s" + ) { source -> + "com.beust.jcommander.internal" in source + }, TestData( "%d source files contain references to package org.jetbrains.jet.\n" + "Package org.jetbrains.jet is deprecated now in favor of org.jetbrains.kotlin. " + - "Please consider changing the package in these files:\n%s", - { source -> - "org.jetbrains.jet" in source - } - ), + "Please consider changing the package in these files:\n%s" + ) { source -> + "org.jetbrains.jet" in source + }, TestData( "%d source files contain references to package kotlin.reflect.jvm.internal.impl.\n" + "This package contains internal reflection implementation and is a result of a " + "post-processing of kotlin-reflect.jar by jarjar.\n" + "Most probably you meant to use classes from org.jetbrains.kotlin.**.\n" + - "Please change references in these files or exclude them in this test:\n%s", - { source -> - "kotlin.reflect.jvm.internal.impl" in source - } - ), + "Please change references in these files or exclude them in this test:\n%s" + ) { source -> + "kotlin.reflect.jvm.internal.impl" in source + }, TestData( "%d source files contain references to package org.objectweb.asm.\n" + "Package org.jetbrains.org.objectweb.asm should be used instead to avoid troubles with different asm versions in classpath. " + - "Please consider changing the package in these files:\n%s", - { source -> - " org.objectweb.asm" in source - }) + "Please consider changing the package in these files:\n%s" + ) { source -> + " org.objectweb.asm" in source + } ) - for (sourceFile in FileUtil.findFilesByMask(SOURCES_FILE_PATTERN, File("."))) { - if (NON_SOURCE_EXCLUDED_FILES_AND_DIRS.any { FileUtil.isAncestor(it, sourceFile, false) }) continue - - val source = sourceFile.readText() - for (test in tests) { - if (test.filter(source)) test.result.add(sourceFile) + val root = File(".") + val nonSourceMatcher = FileMatcher(root, NON_SOURCE_EXCLUDED_FILES_AND_DIRS) + root.walkTopDown() + .onEnter { dir -> + !nonSourceMatcher.matchExact(dir) // Don't enter to ignored dirs + } + .filter { file -> !nonSourceMatcher.matchExact(file) } // filter ignored files + .filter { file -> SOURCES_FILE_PATTERN.matcher(file.name).matches() } + .filter { file -> file.isFile } + .forEach { sourceFile -> + val source = sourceFile.readText() + for (test in tests) { + if (test.filter(source)) test.result.add(sourceFile) + } } - } if (tests.flatMap { it.result }.isNotEmpty()) { fail(buildString {