Skip to content

Commit

Permalink
Adding ability to run all mutants by running the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Garethp committed Jun 25, 2020
1 parent 663d7d8 commit 1df9476
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
11 changes: 10 additions & 1 deletion src/main/kotlin/com/blackfireweb/stryker/run/StrykerConstants.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package com.blackfireweb.stryker.run

val MUTANT_PROTOCOL = "stryker-mutant"
val MUTANT_PROTOCOL = "stryker-mutant"

fun isConfigFile(name: String): Boolean {
return when {
name.endsWith("stryker.conf.js") -> true
name.endsWith("stryker.conf.ts") -> true
name.endsWith("stryker.conf.json") -> true
else -> false
}
}
16 changes: 7 additions & 9 deletions src/main/kotlin/com/blackfireweb/stryker/run/StrykerRunConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,16 @@ class StrykerRunConfig(project: Project, factory: ConfigurationFactory) : Locata
}

override fun suggestedName(): String? {
return when (myRunSettings.kind) {
TestKind.DIRECTORY -> "Mutate All Files in ${getRelativePath(project, myRunSettings.specsDir ?: return null)}"
TestKind.SPEC -> "Mutate ${getRelativePath(project, myRunSettings.specFile ?: return null)}"
TestKind.TEST -> "Mutate ${myRunSettings.allNames?.joinToString(" -> ") ?: return null}"
}
return actionName
}

override fun getActionName(): String? {
return when (myRunSettings.kind) {
TestKind.DIRECTORY -> "Mutate All Files in ${getLastPathComponent(myRunSettings.specsDir ?: return null)}"
TestKind.SPEC -> "Mutate ${getLastPathComponent(myRunSettings.specFile ?: return null)}"
TestKind.TEST -> "Mutate ${myRunSettings.allNames?.joinToString(" -> ") ?: return null}"
return when {
myRunSettings.kind === TestKind.DIRECTORY -> "Mutate All Files in ${getRelativePath(project, myRunSettings.specsDir ?: return null)}"
myRunSettings.kind === TestKind.SPEC && isConfigFile(myRunSettings.specFile ?: "") -> "Run Stryker"
myRunSettings.kind === TestKind.SPEC -> "Mutate ${getRelativePath(project, myRunSettings.specFile ?: return null)}"
myRunSettings.kind === TestKind.TEST -> "Mutate ${myRunSettings.allNames?.joinToString(" -> ") ?: return null}"
else -> null
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/main/kotlin/com/blackfireweb/stryker/run/StrykerRunState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class StrykerRunState(private val myEnv: ExecutionEnvironment, private val myRun
val interpreter: NodeJsInterpreter = NodeJsInterpreterRef.create(this.myRunConfiguration.getPersistentData().nodeJsRef).resolveNotNull(myEnv.project)
val commandLine = NodeCommandLineUtil.createCommandLine(if (SystemInfo.isWindows) false else null)
val reporter = myRunConfiguration.getStrykerIntelliJReporterFile()
var onlyElement = this.configureCommandLine(commandLine, interpreter, reporter)
this.configureCommandLine(commandLine, interpreter, reporter)
val processHandler = NodeCommandLineUtil.createProcessHandler(commandLine, false)
val consoleProperties = StrykerConsoleProperties(this.myRunConfiguration, this.myEnv.executor, StrykerTestLocationProvider(), NodeCommandLineUtil.shouldUseTerminalConsole(processHandler))
val consoleView: ConsoleView = if (reporter != null) this.createSMTRunnerConsoleView(commandLine.workDirectory, consoleProperties) else ConsoleViewImpl(myProject, false)
Expand Down Expand Up @@ -63,7 +63,6 @@ class StrykerRunState(private val myEnv: ExecutionEnvironment, private val myRun
}

private fun configureCommandLine(commandLine: GeneralCommandLine, interpreter: NodeJsInterpreter, reporter: NodePackage?) {
var onlyFile: PsiElement? = null
commandLine.charset = StandardCharsets.UTF_8
val data = this.myRunConfiguration.getPersistentData()

Expand Down Expand Up @@ -99,29 +98,29 @@ class StrykerRunState(private val myEnv: ExecutionEnvironment, private val myRun
commandLine.addParameter("--reporters")
commandLine.addParameter("intellij")
}
if (data.kind == StrykerRunConfig.TestKind.TEST || data.kind == StrykerRunConfig.TestKind.SPEC) {
if ((data.kind == StrykerRunConfig.TestKind.TEST || data.kind == StrykerRunConfig.TestKind.SPEC) && !isConfigFile(data.specFile ?: "")) {
addMutateOrDie(commandLine, data)
}

if (data.kind == StrykerRunConfig.TestKind.DIRECTORY) {
addMutateDirectoryOrDie(commandLine, data);
addMutateDirectoryOrDie(commandLine, data)
}

NodeCommandLineConfigurator.find(interpreter).configure(commandLine)
}

private fun addMutateOrDie(commandLine: GeneralCommandLine, data: StrykerRunConfig.StrykerRunSettings) {
var file = data.specFile ?: return
val file = data.specFile ?: return
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(File(file)) ?: return
val extension = virtualFile.extension;
val extension = virtualFile.extension

commandLine.addParameter("--mutate")
commandLine.addParameter(if (".spec.$extension\$".toRegex().containsMatchIn(file)) file.replace(".spec.$extension", ".$extension") else file)

}

private fun addMutateDirectoryOrDie(commandLine: GeneralCommandLine, data: StrykerRunConfig.StrykerRunSettings) {
var directory = data.specsDir ?: return
val directory = data.specsDir ?: return

commandLine.addParameter("--mutate")
commandLine.addParameter("${directory}/**/*.ts,js,tsx,jsx,!${directory}/**/*.spec.ts,spec.js,spec.tsx,spec.jsx,!${directory}/**/*.test.ts,test.js,test.tsx,test.jsx")
Expand Down

0 comments on commit 1df9476

Please sign in to comment.