Skip to content

Commit c1c6eaa

Browse files
authored
Introduced not applicable counter for FixPlugin (#437)
1 parent ff844eb commit c1c6eaa

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

  • save-common/src/commonMain/kotlin/com/saveourtool/save/core/result
  • save-plugins/fix-plugin/src

save-common/src/commonMain/kotlin/com/saveourtool/save/core/result/DebugInfo.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,24 @@ data class CountWarnings(
3535
val matched: Int,
3636
val expected: Int,
3737
val unexpected: Int,
38-
)
38+
) {
39+
companion object {
40+
private const val NOT_APPLICABLE_COUNTER: Int = -99
41+
42+
/**
43+
* [CountWarnings] is not applicable for current run
44+
*/
45+
val notApplicable = CountWarnings(
46+
NOT_APPLICABLE_COUNTER,
47+
NOT_APPLICABLE_COUNTER,
48+
NOT_APPLICABLE_COUNTER,
49+
NOT_APPLICABLE_COUNTER
50+
)
51+
52+
/**
53+
* @param counter value of counter to be checked
54+
* @return true if provided value has value which means that current counter is not applicable (FixPlugin for example), otherwise -- false
55+
*/
56+
fun isNotApplicable(counter: Int): Boolean = NOT_APPLICABLE_COUNTER == counter
57+
}
58+
}

save-plugins/fix-plugin/src/commonMain/kotlin/com/saveourtool/save/plugins/fix/FixPlugin.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.saveourtool.save.core.plugin.ExtraFlagsExtractor
1313
import com.saveourtool.save.core.plugin.GeneralConfig
1414
import com.saveourtool.save.core.plugin.Plugin
1515
import com.saveourtool.save.core.plugin.resolvePlaceholdersFrom
16+
import com.saveourtool.save.core.result.CountWarnings
1617
import com.saveourtool.save.core.result.DebugInfo
1718
import com.saveourtool.save.core.result.Fail
1819
import com.saveourtool.save.core.result.Pass
@@ -123,7 +124,8 @@ class FixPlugin(
123124
execCmd,
124125
stdout.filter { it.contains(testCopy.name) }.joinToString("\n"),
125126
stderr.filter { it.contains(testCopy.name) }.joinToString("\n"),
126-
null
127+
null,
128+
CountWarnings.notApplicable,
127129
)
128130
)
129131
}
@@ -139,7 +141,7 @@ class FixPlugin(
139141
TestResult(
140142
it,
141143
Fail(ex.describe(), ex.describe()),
142-
DebugInfo(execCmd, null, ex.message, null)
144+
DebugInfo(execCmd, null, ex.message, null, CountWarnings.notApplicable)
143145
)
144146
}
145147

save-plugins/fix-plugin/src/commonNonJsTest/kotlin/com/saveourtool/save/plugins/fix/FixPluginTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.saveourtool.save.core.config.TestConfig
55
import com.saveourtool.save.core.files.createFile
66
import com.saveourtool.save.core.files.fs
77
import com.saveourtool.save.core.plugin.GeneralConfig
8+
import com.saveourtool.save.core.result.CountWarnings
89
import com.saveourtool.save.core.result.DebugInfo
910
import com.saveourtool.save.core.result.Pass
1011
import com.saveourtool.save.core.result.TestResult
@@ -61,6 +62,7 @@ class FixPluginTest {
6162
assertEquals("Test2Expected.java", pairs.single().second.name)
6263
}
6364

65+
@Suppress("TOO_LONG_FUNCTION")
6466
@Test
6567
fun `should calculate diff of discovered files`() {
6668
val config = fs.createFile(tmpDir / "save.toml")
@@ -90,8 +92,14 @@ class FixPluginTest {
9092
assertEquals(1, results.size, "Size of results should equal number of pairs")
9193
val testResult = results.single()
9294
assertEquals(
93-
TestResult(FixPlugin.FixTestFiles(testFile, expectedFile), Pass(null), DebugInfo(
94-
testResult.debugInfo?.execCmd, testResult.debugInfo?.stdout, testResult.debugInfo?.stderr, null)
95+
TestResult(FixPlugin.FixTestFiles(testFile, expectedFile), Pass(null),
96+
DebugInfo(
97+
testResult.debugInfo?.execCmd,
98+
testResult.debugInfo?.stdout,
99+
testResult.debugInfo?.stderr,
100+
null,
101+
CountWarnings.notApplicable,
102+
)
95103
),
96104
testResult
97105
)

0 commit comments

Comments
 (0)