Skip to content

Commit de386c4

Browse files
committed
fix: harden version detection, config-type id, command-run executor, coverage error
- TestoVersionDetector.parse: reject output without the 'Testo ' prefix (substringAfter now uses missingDelimiterValue "") instead of returning it as a version; updated TestoVersionDetectorTest to the corrected contract. - TestoRunConfigurationType.ID: pin the literal "TestoRunConfiguration" so a class rename can't silently break persisted run configs. - TestoRunCommandAction: run via DefaultRunExecutor instead of the order-dependent EXECUTOR_EXTENSION_NAME.extensionList.first(). - Coverage: throw RuntimeConfigurationError (not IllegalArgumentException) for an unsupported engine.
1 parent 5acb2c5 commit de386c4

5 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/kotlin/com/github/xepozz/testo/coverage/TestoCoverageProgramRunner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.xepozz.testo.coverage
22

33
import com.github.xepozz.testo.tests.run.TestoRunConfiguration
44
import com.intellij.execution.configurations.RunProfile
5+
import com.intellij.execution.configurations.RuntimeConfigurationError
56
import com.intellij.execution.configurations.RunProfileState
67
import com.intellij.execution.runners.ExecutionEnvironment
78
import com.jetbrains.php.config.commandLine.PhpCommandSettings
@@ -75,7 +76,7 @@ open class TestoCoverageProgramRunner : PhpCoverageRunner() {
7576
.createXdebugConfigurations()
7677

7778
CoverageEngine.PCOV -> listOf(PhpConfigurationOption("pcov.enabled", 1))
78-
else -> throw IllegalArgumentException("Unsupported coverage engine $coverageEngine.")
79+
else -> throw RuntimeConfigurationError("Unsupported Testo coverage engine: $coverageEngine.")
7980
}
8081
command.addConfigurationOptions(options)
8182
setAdditionalMapping(localCoverage, targetCoverage, command)

src/main/kotlin/com/github/xepozz/testo/tests/TestoVersionDetector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object TestoVersionDetector : PhpTestFrameworkVersionDetector<String>() {
1010
public override fun getVersionOptions() = arrayOf("--version", "--no-ansi")
1111

1212
public override fun parse(s: String): String {
13-
val version = s.substringAfter("Testo ")
13+
val version = s.substringAfter("Testo ", "") // "" on miss so non-Testo output is rejected below
1414
if (version.isEmpty()) {
1515
throw ExecutionException(TestoBundle.message("testo.version.error"))
1616
}

src/main/kotlin/com/github/xepozz/testo/tests/actions/TestoRunCommandAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.github.xepozz.testo.TestoBundle
44
import com.github.xepozz.testo.TestoIcons
55
import com.github.xepozz.testo.tests.run.TestoRunConfiguration
66
import com.github.xepozz.testo.tests.run.TestoRunConfigurationProducer
7-
import com.intellij.execution.Executor
7+
import com.intellij.execution.executors.DefaultRunExecutor
88
import com.intellij.execution.RunManagerEx
99
import com.intellij.execution.runners.ExecutionUtil
1010
import com.intellij.openapi.actionSystem.AnAction
@@ -34,6 +34,6 @@ class TestoRunCommandAction(val commandName: String) : AnAction() {
3434
val configuration = runManager.createConfiguration(runConfiguration, configurationFactory)
3535

3636
runManager.setTemporaryConfiguration(configuration)
37-
ExecutionUtil.runConfiguration(configuration, Executor.EXECUTOR_EXTENSION_NAME.extensionList.first())
37+
ExecutionUtil.runConfiguration(configuration, DefaultRunExecutor.getRunExecutorInstance())
3838
}
3939
}

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationType.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class TestoRunConfigurationType :
1818
TestoRunConfiguration(project, this)
1919

2020
companion object Companion {
21-
val ID = TestoRunConfiguration::class.java.simpleName
21+
// Pinned literal (was ::class.simpleName): a future class rename must not silently change the
22+
// persisted run-configuration type id and break users' saved configs.
23+
const val ID = "TestoRunConfiguration"
2224

2325
val INSTANCE
2426
get() = findConfigurationType(TestoRunConfigurationType::class.java)

src/test/kotlin/com/github/xepozz/testo/TestoVersionDetectorTest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ class TestoVersionDetectorTest : TestCase() {
2424
}
2525

2626
fun testParse_noPrefix() {
27-
// "substringAfter" returns original string if delimiter not found
28-
assertEquals("SomeOtherOutput", TestoVersionDetector.parse("SomeOtherOutput"))
27+
// Output without the "Testo " prefix is not a version and must be rejected (previously it leaked through).
28+
try {
29+
TestoVersionDetector.parse("SomeOtherOutput")
30+
fail("Expected ExecutionException for non-Testo output")
31+
} catch (_: ExecutionException) {
32+
// expected
33+
}
2934
}
3035

3136
fun testGetVersionOptions() {

0 commit comments

Comments
 (0)