From 2e7e1a85deb3aa0ac71d86ebfc10ba4ce7139caf Mon Sep 17 00:00:00 2001 From: Vfrolov Date: Fri, 3 Sep 2021 17:07:15 +0300 Subject: [PATCH] Change test storage from List to class in Fix plugin What's done: * Change test storage from List to class in plugin Closes #221 --- .../org/cqfn/save/core/plugin/Plugin.kt | 5 ++--- .../plugins/fixandwarn/FixAndWarnPlugin.kt | 4 ++-- .../org/cqfn/save/plugins/fix/FixPlugin.kt | 20 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) 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 950b4671b..08f1f3243 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 @@ -85,8 +85,8 @@ abstract class Plugin( } return if (testFiles.isNotEmpty()) { - rawTestFiles.filter { path -> - testFiles.any { it in path.test.toString() } + rawTestFiles.filter { rawTestFile -> + testFiles.any { it in rawTestFile.test.toString() } } } else { rawTestFiles @@ -97,7 +97,6 @@ abstract class Plugin( // 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.test.createRelativePathToTheRoot(testRepositoryRoot).toPath() / testFiles.test.name) diff --git a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt index c0ca1b87d..15a74c1ec 100644 --- a/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt +++ b/save-plugins/fix-and-warn-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fixandwarn/FixAndWarnPlugin.kt @@ -67,7 +67,7 @@ class FixAndWarnPlugin( override fun handleFiles(files: Sequence): Sequence { // Need to update private fields after validation initOrUpdateConfigs() - val expectedFiles = files.map { it as FixPlugin.Test }.map { it.expected } + val expectedFiles = files.map { it as FixPlugin.FixTestFiles }.map { it.expected } // Remove (in place) warnings from test files before fix plugin execution val filesAndTheirWarningsMap = removeWarningsFromExpectedFiles(expectedFiles) @@ -77,7 +77,7 @@ class FixAndWarnPlugin( val (fixTestResultsPassed, fixTestResultsFailed) = fixTestResults.partition { it.status is Pass } val expectedFilesWithPass = expectedFiles.filter { expectedFile -> - fixTestResultsPassed.map { it.resources.toList()[0] }.contains(expectedFile) + fixTestResultsPassed.map { it.resources.toList()[1] }.contains(expectedFile) } // Fill back original data with warnings diff --git a/save-plugins/fix-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fix/FixPlugin.kt b/save-plugins/fix-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fix/FixPlugin.kt index 254486820..04ea1c13d 100644 --- a/save-plugins/fix-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fix/FixPlugin.kt +++ b/save-plugins/fix-plugin/src/commonMain/kotlin/org/cqfn/save/plugins/fix/FixPlugin.kt @@ -50,11 +50,11 @@ class FixPlugin( val fixPluginConfig = testConfig.pluginConfigs.filterIsInstance().single() val generalConfig = testConfig.pluginConfigs.filterIsInstance().single() - return files.map { it as Test }.chunked(fixPluginConfig.batchSize!!.toInt()).map { chunk -> - val pathMap = chunk.map { it.expected to it.test } - val pathCopyMap = pathMap.map { (expected, test) -> expected to createTestFile(test, generalConfig) } + return files.map { it as FixTestFiles }.chunked(fixPluginConfig.batchSize!!.toInt()).map { chunk -> + val pathMap = chunk.map { it.test to it.expected } + val pathCopyMap = pathMap.map { (test, expected) -> createTestFile(test, generalConfig) to expected } val testCopyNames = - pathCopyMap.joinToString(separator = fixPluginConfig.batchSeparator!!) { (_, testCopy) -> testCopy.toString() } + pathCopyMap.joinToString(separator = fixPluginConfig.batchSeparator!!) { (testCopy, _) -> testCopy.toString() } val execCmd = "${(generalConfig.execCmd)} ${fixPluginConfig.execFlags} $testCopyNames" val executionResult = try { @@ -62,7 +62,7 @@ class FixPlugin( } catch (ex: ProcessExecutionException) { return@map chunk.map { TestResult( - pathMap.map { (expected, test) -> listOf(expected, test) }.flatten(), + pathMap.map { (test, expected) -> listOf(test, expected) }.flatten(), Fail(ex.describe(), ex.describe()), DebugInfo(null, ex.message, null) ) @@ -72,14 +72,14 @@ class FixPlugin( val stdout = executionResult.stdout val stderr = executionResult.stderr - pathCopyMap.map { (expected, testCopy) -> + pathCopyMap.map { (testCopy, expected) -> val fixedLines = fs.readLines(testCopy) val expectedLines = fs.readLines(expected) - val test = pathMap.first { (_, test) -> test.name == testCopy.name }.second + val test = pathMap.first { (test, _) -> test.name == testCopy.name }.first TestResult( - listOf(expected, test), + listOf(test, expected), checkStatus(expectedLines, fixedLines), DebugInfo( stdout.filter { it.contains(testCopy.name) }.joinToString("\n"), @@ -134,7 +134,7 @@ class FixPlugin( .filter { it.value.size > 1 && it.key != null } .mapValues { (name, group) -> require(group.size == 2) { "Files should be grouped in pairs, but for name $name these files have been discovered: $group" } - Test( + FixTestFiles( group.first { it.name.contains("$resourceNameTest.") }, group.first { it.name.contains("$resourceNameExpected.") }, ) @@ -176,5 +176,5 @@ class FixPlugin( * @property test test file * @property expected expected file */ - class Test(override val test: Path, val expected: Path) : TestFiles + class FixTestFiles(override val test: Path, val expected: Path) : TestFiles }