generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nikolaymatrosov/feature/run-from-gherkin
Enable running Features/Scenarios from Gherkin file.
- Loading branch information
Showing
7 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/github/nikolaymatrosov/cucumbergo/godog/GodogEventsConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.nikolaymatrosov.cucumbergo.godog | ||
|
||
import com.goide.execution.testing.GoTestEventsJsonConverter | ||
import com.intellij.execution.testframework.TestConsoleProperties | ||
|
||
class GodogEventsConverter(s: String, consoleProperties: TestConsoleProperties) : GoTestEventsJsonConverter( | ||
"Godog", s, consoleProperties | ||
) |
68 changes: 68 additions & 0 deletions
68
src/main/kotlin/com/github/nikolaymatrosov/cucumbergo/godog/GodogFramework.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.github.nikolaymatrosov.cucumbergo.godog | ||
|
||
import com.github.nikolaymatrosov.cucumbergo.GODOG_PACKAGE | ||
import com.github.nikolaymatrosov.cucumbergo.run.GodogRunningState | ||
import com.goide.GoFileType | ||
import com.goide.execution.testing.GoTestFramework | ||
import com.goide.execution.testing.GoTestRunConfiguration | ||
import com.goide.execution.testing.GoTestRunningState | ||
import com.goide.psi.GoFile | ||
import com.goide.psi.GoFunctionOrMethodDeclaration | ||
import com.intellij.execution.runners.ExecutionEnvironment | ||
import com.intellij.execution.testframework.TestConsoleProperties | ||
import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter | ||
import com.intellij.openapi.module.Module | ||
import com.intellij.psi.PsiFile | ||
|
||
|
||
class GodogFramework : GoTestFramework() { | ||
override fun getName(): String { | ||
return "Godog" | ||
} | ||
|
||
override fun isAvailable(module: Module?): Boolean { | ||
return true | ||
} | ||
|
||
override fun isAvailableOnFile(psiFile: PsiFile?): Boolean { | ||
return psiFile != null | ||
&& psiFile.fileType === GoFileType.INSTANCE | ||
&& (psiFile as GoFile).imports.any { it.path == GODOG_PACKAGE } | ||
} | ||
|
||
override fun isAvailableOnFunction(goFunctionOrMethodDeclaration: GoFunctionOrMethodDeclaration?): Boolean { | ||
return false | ||
} | ||
|
||
override fun supportsJsonTestsOutput(): Boolean { | ||
return true | ||
} | ||
|
||
override fun newRunningState( | ||
executionEnvironment: ExecutionEnvironment, | ||
module: Module, | ||
goTestRunConfiguration: GoTestRunConfiguration | ||
): GoTestRunningState { | ||
return GodogRunningState(executionEnvironment, module, goTestRunConfiguration) | ||
} | ||
|
||
override fun createTestEventsConverter( | ||
s: String, | ||
testConsoleProperties: TestConsoleProperties, | ||
module: Module? | ||
): OutputToGeneralTestEventsConverter { | ||
return GodogEventsConverter(s, testConsoleProperties) | ||
} | ||
|
||
override fun getPackageConfigurationName(packageName: String): String { | ||
return "Godog" | ||
} | ||
|
||
companion object { | ||
val INSTANCE: GodogFramework = GodogFramework() | ||
|
||
init { | ||
all().add(INSTANCE) | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/com/github/nikolaymatrosov/cucumbergo/run/GodogRunConfigurationProducer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.github.nikolaymatrosov.cucumbergo.run | ||
|
||
import ai.grazie.utils.capitalize | ||
import com.github.nikolaymatrosov.cucumbergo.CucumberExtension | ||
import com.github.nikolaymatrosov.cucumbergo.godog.GodogFramework | ||
import com.goide.execution.GoBuildingRunConfiguration.Kind | ||
import com.goide.execution.GoRunUtil | ||
import com.goide.execution.testing.GoTestRunConfiguration | ||
import com.goide.execution.testing.GoTestRunConfigurationProducerBase | ||
import com.goide.psi.GoFile | ||
import com.intellij.execution.actions.ConfigurationContext | ||
import com.intellij.openapi.util.Ref | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import org.jetbrains.plugins.cucumber.psi.GherkinFile | ||
import org.jetbrains.plugins.cucumber.psi.GherkinScenario | ||
import org.jetbrains.plugins.cucumber.psi.GherkinScenarioOutline | ||
|
||
class GodogRunConfigurationProducer protected constructor() : | ||
GoTestRunConfigurationProducerBase(GodogFramework.INSTANCE) { | ||
override fun setupConfigurationFromContext( | ||
configuration: GoTestRunConfiguration, | ||
context: ConfigurationContext, | ||
sourceElement: Ref<*> | ||
): Boolean { | ||
val element = sourceElement.get() as PsiElement | ||
if (element.containingFile is GherkinFile) { | ||
val file = element.containingFile.virtualFile | ||
|
||
// assuming all steps are in the same directory | ||
CucumberExtension().getStepDefinitionContainers(element.containingFile as GherkinFile).first().let { | ||
configuration.workingDirectory = it.virtualFile.parent.path | ||
configuration.`package` = (it as GoFile).getImportPath(false).toString() | ||
} | ||
|
||
configuration.testFramework = GodogFramework.INSTANCE | ||
configuration.kind = Kind.PACKAGE | ||
configuration.goToolParams = GoRunUtil.filterOutInstallParameter(configuration.goToolParams) | ||
val scenario = PsiTreeUtil.getParentOfType( | ||
element, | ||
GherkinScenario::class.java | ||
) | ||
|
||
val scenarioOutline = PsiTreeUtil.getParentOfType( | ||
element, | ||
GherkinScenarioOutline::class.java | ||
) | ||
|
||
var pattern = "^\\QTest" + file.nameWithoutExtension.capitalize() + "\\E\$" | ||
|
||
if (scenario != null) { | ||
pattern = pattern + "/^" + scenario.scenarioName + "$" | ||
} else if (scenarioOutline != null) { | ||
pattern = pattern + "/^" + scenarioOutline.scenarioName + "(#\\d+)?$" | ||
} | ||
configuration.pattern = pattern | ||
|
||
configuration.setGeneratedName() | ||
return true | ||
} | ||
// if (element is PsiDirectory) { | ||
// val dir = element.virtualFile | ||
// if (!FileTypeIndex.containsFileOfType( | ||
// GherkinFileType.INSTANCE, | ||
// GlobalSearchScopesCore.directoryScope(element.getProject(), dir, true) | ||
// ) | ||
// ) { | ||
// return false | ||
// } | ||
// val directoryPath = dir.path | ||
// configuration.testFramework = GodogFramework.INSTANCE | ||
// configuration.directoryPath = directoryPath | ||
// configuration.workingDirectory = directoryPath | ||
// configuration.kind = Kind.DIRECTORY | ||
// configuration.goToolParams = GoRunUtil.filterOutInstallParameter(configuration.goToolParams) | ||
// configuration.setGeneratedName() | ||
// | ||
// return true | ||
// } | ||
return false | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/github/nikolaymatrosov/cucumbergo/run/GodogRunningState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.nikolaymatrosov.cucumbergo.run | ||
|
||
import com.goide.execution.testing.GoTestRunConfiguration | ||
import com.goide.execution.testing.GoTestRunningState | ||
import com.intellij.execution.runners.ExecutionEnvironment | ||
import com.intellij.openapi.module.Module | ||
|
||
|
||
class GodogRunningState(env: ExecutionEnvironment, module: Module, configuration: GoTestRunConfiguration) : | ||
GoTestRunningState(env, module, configuration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters