diff --git a/README.md b/README.md index 50d60ca6d..af85c585b 100644 --- a/README.md +++ b/README.md @@ -139,12 +139,8 @@ description = "My suite description" suiteName = DocsCheck, CaseCheck, NpeTests, e.t.c # excluded tests in the suite (optional). Here you can provide names of excluded tests, separated by comma. By the default no tests are excluded. -# names can have 'Test' postifix or can be without a postfix - this does not matter. Save will detect tests for both cases -excludedTests = NameWithTestPostfix, NameWithoutPostfix, e.t.c - -# tests included in the suite (optional). Here you can provide names of tests, that are included in this suite. - By the default all tests in the same directory with 'save.toml' file are included in the suite. -includedTests = NameWithTestPostfix, NameWithoutPostfix, e.t.c +# to exclude tests use relative path to the root of test project (to the root directory of `save.toml`) +excludedTests = ["warn/chapter1/GarbageTest.kt", "warn/otherDir/NewTest.kt"], e.t.c ``` ## Using plugins for specific test-scenarios diff --git a/examples/kotlin-diktat/warn/chapter1/GarbageTest.kt b/examples/kotlin-diktat/warn/chapter1/GarbageTest.kt new file mode 100644 index 000000000..e69de29bb diff --git a/examples/kotlin-diktat/warn/chapter1/save.toml b/examples/kotlin-diktat/warn/chapter1/save.toml index d0aacb186..69c4c4013 100644 --- a/examples/kotlin-diktat/warn/chapter1/save.toml +++ b/examples/kotlin-diktat/warn/chapter1/save.toml @@ -2,5 +2,6 @@ tags = ["tag1"] description = "My suite description" suiteName = "DocsCheck" +excludedTests = ["warn/chapter1/GarbageTest.kt"] [warn] diff --git a/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt b/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt index 4e788e0f8..68e0054f5 100644 --- a/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt +++ b/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/Plugin.kt @@ -10,6 +10,7 @@ import org.cqfn.save.core.utils.ProcessBuilder import okio.FileSystem import okio.Path +import okio.Path.Companion.toPath /** * Plugin that can be injected into SAVE during execution. Plugins accept contents of configuration file and then perform some work. @@ -40,8 +41,8 @@ abstract class Plugin( */ fun execute(): Sequence { clean() - // todo: pass individual groups of files to handleFiles? Or it will play bad with batch mode? val testFilesSequence = discoverTestFiles(testConfig.directory) + return if (testFilesSequence.any()) { logDebug("Discovered the following test resources: ${testFilesSequence.toList()}") handleFiles(testFilesSequence) @@ -66,7 +67,23 @@ abstract class Plugin( * @return a sequence of files, grouped by test */ fun discoverTestFiles(root: Path): Sequence> { + val excludedTests = + testConfig + .pluginConfigs + .filterIsInstance() + .singleOrNull() + ?.excludedTests + + if (!excludedTests.isNullOrEmpty()) { + logDebug("Excluded tests for [${testConfig.location}] : $excludedTests") + } + val rawTestFiles = rawDiscoverTestFiles(root.resourceDirectories()) + // removing excluded test resources + .filterNot { + isExcludedTest(it, excludedTests) + } + return if (testFiles.isNotEmpty()) { rawTestFiles.filter { resourcesGroup -> // test can be specified by the name of one of it's files @@ -79,6 +96,24 @@ abstract class Plugin( } } + private fun isExcludedTest(testFiles: List, excludedTests: List?): Boolean { + // common root of the test repository (not a location of a current test) + val testRepositoryRoot = testConfig.getRootConfig().location + // creating relative to root path from a test file + // FixMe: https://github.com/cqfn/save/issues/241 here we are incorrectly using testFiles[0], as for example it is + // "Expected" file for Fix plugin + val testFileRelative = + (testFiles[0].createRelativePathToTheRoot(testRepositoryRoot).toPath() / testFiles[0].name) + .toString() + .replace('\\', '/') + + // excluding tests that are included in the excluded list + return excludedTests + ?.map { it.replace('\\', '/') } + ?.contains(testFileRelative) + ?: false + } + /** * Discover groups of resource files which will be used to run tests. * diff --git a/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/PluginConfig.kt b/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/PluginConfig.kt index 198f7c696..7d85f1918 100644 --- a/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/PluginConfig.kt +++ b/save-common/src/commonMain/kotlin/org/cqfn/save/core/plugin/PluginConfig.kt @@ -55,7 +55,6 @@ interface PluginConfig { * @property description free text with a description * @property suiteName name of test suite that can be visible from save-cloud * @property excludedTests excluded tests from the run - * @property includedTests if specified - only these tests will be run * @property expectedWarningsPattern - pattern with warnings that are expected from the test file */ @Serializable @@ -65,7 +64,6 @@ data class GeneralConfig( val description: String? = null, val suiteName: String? = null, val excludedTests: List? = null, - val includedTests: List? = null, val expectedWarningsPattern: Regex? = null, ) : PluginConfig { override val type = TestConfigSections.GENERAL @@ -87,7 +85,6 @@ data class GeneralConfig( this.description ?: other.description, this.suiteName ?: other.suiteName, this.excludedTests ?: other.excludedTests, - this.includedTests ?: other.includedTests, this.expectedWarningsPattern ?: other.expectedWarningsPattern, ) } @@ -111,7 +108,6 @@ data class GeneralConfig( description, suiteName, excludedTests ?: emptyList(), - includedTests ?: emptyList(), expectedWarningsPattern ?: defaultInputPattern, ) } diff --git a/save-core/src/commonNonJsMain/kotlin/org/cqfn/save/core/Save.kt b/save-core/src/commonNonJsMain/kotlin/org/cqfn/save/core/Save.kt index ac5eff5b5..4b3cc0a20 100644 --- a/save-core/src/commonNonJsMain/kotlin/org/cqfn/save/core/Save.kt +++ b/save-core/src/commonNonJsMain/kotlin/org/cqfn/save/core/Save.kt @@ -118,12 +118,13 @@ class Save( logDebug("=> Executing plugin: ${plugin::class.simpleName} for [${plugin.testConfig.location}]") reporter.onPluginExecutionStart(plugin) try { - val rootDir = plugin.testConfig.getRootConfig().location + val testRepositoryRootPath = plugin.testConfig.getRootConfig().location + plugin.execute() .onEach { event -> // calculate relative paths, because reporters don't need paths higher than root dir val resourcesRelative = - event.resources.map { it.createRelativePathToTheRoot(rootDir).toPath() / it.name } + event.resources.map { it.createRelativePathToTheRoot(testRepositoryRootPath).toPath() / it.name } reporter.onEvent(event.copy(resources = resourcesRelative)) } .forEach(this::handleResult) diff --git a/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/MergeConfigsTest.kt b/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/MergeConfigsTest.kt index ce6affa1a..ae9e7f98f 100644 --- a/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/MergeConfigsTest.kt +++ b/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/MergeConfigsTest.kt @@ -26,10 +26,10 @@ internal val toml4 = nestedDir2 / "nestedDir3" / "nestedDir4" / "save.toml" @Suppress("TOO_LONG_FUNCTION", "LOCAL_VARIABLE_EARLY_DECLARATION") class MergeConfigsTest { - private val generalConfig1 = GeneralConfig("", listOf("Tag11", "Tag12"), "Description1", "suiteName1", listOf("excludedTests: test1"), listOf("includedTests: test2")) - private val generalConfig2 = GeneralConfig("", listOf("Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4")) + private val generalConfig1 = GeneralConfig("", listOf("Tag11", "Tag12"), "Description1", "suiteName1", listOf("excludedTests: test1")) + private val generalConfig2 = GeneralConfig("", listOf("Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3")) private val generalConfig3 = GeneralConfig("", listOf("Tag21", "Tag31", "Tag32"), "Description2", "suiteName3", listOf("excludedTests: test5", "includedTests: test6")) - private val generalConfig4 = GeneralConfig("", listOf("Tag11", "Tag21"), "Description2", "suiteName4", listOf("excludedTests: test7"), listOf("includedTests: test8")) + private val generalConfig4 = GeneralConfig("", listOf("Tag11", "Tag21"), "Description2", "suiteName4", listOf("excludedTests: test7")) private val warningsOutputPattern1 = Regex(".*") private val warningsOutputPattern2 = Regex("\\w+ - (\\d+)/(\\d+) - (.*)$") private val warnConfig1 = WarnPluginConfig("execCmd1", warningsOutputPattern2, @@ -58,7 +58,7 @@ class MergeConfigsTest { assertEquals(1, config2.pluginConfigs.size) val expectedGeneralConfig = - GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4")) + GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3")) val actualGeneralConfig = config2.pluginConfigs.filterIsInstance().first() @@ -76,7 +76,7 @@ class MergeConfigsTest { assertEquals(2, config2.pluginConfigs.size) val expectedGeneralConfig = - GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4")) + GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3")) val actualGeneralConfig = config2.pluginConfigs.filterIsInstance().first() val actualWarnConfig = config2.pluginConfigs.filterIsInstance().first() @@ -113,7 +113,7 @@ class MergeConfigsTest { assertEquals(3, config2.pluginConfigs.size) val expectedGeneralConfig = - GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3"), listOf("includedTests: test4")) + GeneralConfig("", listOf("Tag11", "Tag12", "Tag21"), "Description2", "suiteName2", listOf("excludedTests: test3")) val expectedWarnConfig = WarnPluginConfig("execCmd3", warningsOutputPattern2, true, false, 1, ", ", 3, 3, 3, 3, 3, 3, 3, true) val expectedFixConfig = FixPluginConfig("fixCmd2", 1, "Suffix") @@ -139,7 +139,7 @@ class MergeConfigsTest { assertEquals(3, config4.pluginConfigs.size) val expectedGeneralConfig = - GeneralConfig("", listOf("Tag11", "Tag12", "Tag21", "Tag31", "Tag32"), "Description2", "suiteName4", listOf("excludedTests: test7"), listOf("includedTests: test8")) + GeneralConfig("", listOf("Tag11", "Tag12", "Tag21", "Tag31", "Tag32"), "Description2", "suiteName4", listOf("excludedTests: test7")) val expectedWarnConfig = WarnPluginConfig("execCmd4", warningsOutputPattern2, true, false, 1, ", ", 4, 4, 4, 4, 4, 4, 4, true) val expectedFixConfig = FixPluginConfig("fixCmd4", 1, "Suffix") diff --git a/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/ValidationTest.kt b/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/ValidationTest.kt index cd49c3c70..61701047f 100644 --- a/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/ValidationTest.kt +++ b/save-core/src/commonNonJsTest/kotlin/org/cqfn/save/core/ValidationTest.kt @@ -26,7 +26,6 @@ class ValidationTest { val actualGeneralConfig1 = config.pluginConfigs.filterIsInstance().first() assertEquals(emptyList(), actualGeneralConfig1.excludedTests) - assertEquals(emptyList(), actualGeneralConfig1.includedTests) } @Test @@ -41,7 +40,7 @@ class ValidationTest { assertEquals( """ Error: Couldn't find `execCmd` in [general] section of `${generalConfig.configLocation}` config. - Current configuration: execCmd=null, tags=null, description=null, suiteName=null, excludedTests=null, includedTests=null, expectedWarningsPattern=null + Current configuration: execCmd=null, tags=null, description=null, suiteName=null, excludedTests=null, expectedWarningsPattern=null Please provide it in this, or at least in one of the parent configs. """.trimIndent(), ex.message