Skip to content

Commit

Permalink
Change test storage from List to class in Fix plugin
Browse files Browse the repository at this point in the history
What's done:
* Change test storage from List to class in plugin
Closes #221
  • Loading branch information
Cheshiriks committed Sep 3, 2021
1 parent ea0a17a commit 2e7e1a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FixAndWarnPlugin(
override fun handleFiles(files: Sequence<TestFiles>): Sequence<TestResult> {
// 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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ class FixPlugin(
val fixPluginConfig = testConfig.pluginConfigs.filterIsInstance<FixPluginConfig>().single()
val generalConfig = testConfig.pluginConfigs.filterIsInstance<GeneralConfig>().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 {
pb.exec("cd ${testConfig.getRootConfig().directory} && $execCmd", redirectTo)
} 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)
)
Expand All @@ -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"),
Expand Down Expand Up @@ -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.") },
)
Expand Down Expand Up @@ -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
}

0 comments on commit 2e7e1a8

Please sign in to comment.