Skip to content

Commit

Permalink
store line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Jun 27, 2023
1 parent 88dff1d commit ac86de7
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 101 deletions.
6 changes: 3 additions & 3 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
<!-- <sourceFeatures>@src/test/resources/cucumber-feature-list.txt</sourceFeatures> -->

<!-- process a folder that hosts text files containing paths to features and line numbers (as it is written by the Cucumber rerun formatter) -->
<sourceFeatures>@src/test/resources</sourceFeatures>
<!-- <sourceFeatures>@src/test/resources</sourceFeatures>-->

<!-- process a specific feature file and specific line numbers in the given directory -->
<!--<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature:8:19</sourceFeatures>-->
<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature</sourceFeatures>

<generatedFeatureDirectory>${generated.feature.directory}</generatedFeatureDirectory>
<generatedRunnerDirectory>${generated.runner.directory}</generatedRunnerDirectory>
Expand All @@ -100,7 +100,7 @@

<!-- optional: number of test runs to create runners and features multiple times
if set to a number greater than 1 -->
<!--<numberOfTestRuns>1</numberOfTestRuns>-->
<!-- <numberOfTestRuns>1</numberOfTestRuns> -->

<!-- optional: generate a fixed number of runners and distribute all features round-robin.
This can only be used if desiredNumberOfFeaturesPerRunner is NOT used! -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.inject.Singleton;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.LinkedTransferQueue;

import static com.trivago.logging.CucableLogger.CucableLogLevel.*;

Expand Down Expand Up @@ -92,22 +93,41 @@ public FeatureFileConverter(
public void generateParallelizableFeatures(
final List<CucableFeature> cucableFeatures) throws CucablePluginException {

StringBuilder propertiesFileContent = new StringBuilder();

int featureFileCounter = 0;
List<String> allGeneratedFeaturePaths = new ArrayList<>();

for (CucableFeature cucableFeature : cucableFeatures) {
System.out.println("SOURCE " + cucableFeature.getOrigin());
System.out.println("SOURCE " + cucableFeature.getLineNumbers());

List<Path> paths = fileSystemManager.getPathsFromCucableFeature(cucableFeature);
if (paths.size() == 0) {
logger.warn("No features and runners could be created. Please check your properties!");
}
for (Path path : paths) {
System.out.println("PATH " + path);
List<String> generatedFeatureFilePaths =
generateParallelizableFeatures(path, cucableFeature.getLineNumbers());

for (String generatedFeatureFilePath : generatedFeatureFilePaths) {
propertiesFileContent
.append(generatedFeatureFilePath)
.append("=")
.append(path)
.append("\n");
}

allGeneratedFeaturePaths.addAll(generatedFeatureFilePaths);
featureFileCounter += generatedFeatureFilePaths.size();
}
}

System.out.println("/////////////////////");
System.out.println(propertiesFileContent);
System.out.println("/////////////////////");

for (Map.Entry<String, Integer> entry : singleFeatureCounters.entrySet()) {
logFeatureFileConversionMessage(entry.getKey(), entry.getValue());
}
Expand Down Expand Up @@ -153,6 +173,16 @@ private List<String> generateParallelizableFeatures(
return generateFeaturesWithScenariosParallelizationMode(sourceFeatureFilePath, lineNumbers);
}

private List<String> generateParallelizableFeatures(
final Path sourceFeatureFilePath,
final Integer lineNumber) throws CucablePluginException {

if (propertyManager.getParallelizationMode() == PropertyManager.ParallelizationMode.FEATURES) {
return generateFeaturesWithFeaturesParallelizationMode(sourceFeatureFilePath);
}
return generateFeaturesWithScenariosParallelizationMode(sourceFeatureFilePath, Collections.singletonList(lineNumber));
}

/**
* Generate features with parallelization mode 'features'.
*
Expand Down Expand Up @@ -193,6 +223,7 @@ private List<String> generateFeaturesWithScenariosParallelizationMode(
featureFilePathString,
lineNumbers
);

return generateFeatureFiles(sourceFeatureFilePath, singleScenarios);
}

Expand Down Expand Up @@ -442,7 +473,7 @@ private void logFeatureFileConversionMessage(
createdScenarios,
Language.singularPlural(createdScenarios, "scenario from", "scenarios from"),
featureFileName
), DEFAULT);
), DEFAULT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public List<SingleScenario> getSingleScenariosFromFeature(
final String featureFilePath,
final List<Integer> scenarioLineNumbers
) throws CucablePluginException {

String escapedFeatureContent = featureContent.replace("\\n", "\\\\n");
GherkinDocument gherkinDocument;
try {
Expand Down Expand Up @@ -117,6 +116,11 @@ public List<SingleScenario> getSingleScenariosFromFeature(
continue;
}

System.out.println(".....");
System.out.println(featureFilePath);
System.out.println(scenarioDefinition.getLocation().getLine());
System.out.println(".....");

if (scenarioDefinition instanceof Scenario) {
Scenario scenario = (Scenario) scenarioDefinition;
if (scenarioLineNumbers == null
Expand All @@ -129,6 +133,7 @@ public List<SingleScenario> getSingleScenariosFromFeature(
featureLanguage,
featureDescription,
scenarioName,
scenario.getLocation().getLine(),
scenarioDescription,
featureTags,
backgroundSteps
Expand Down Expand Up @@ -222,6 +227,7 @@ private List<SingleScenario> getSingleScenariosFromOutline(
featureLanguage,
featureDescription,
replacePlaceholderInString(scenarioName, exampleMap, rowIndex),
scenarioOutline.getLocation().getLine(),
scenarioDescription,
featureTags,
backgroundSteps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String getGeneratedRunnerDirectory() {
}

public void setGeneratedRunnerDirectory(final String generatedRunnerDirectory) {
this.generatedRunnerDirectory = generatedRunnerDirectory;
this.generatedRunnerDirectory = generatedRunnerDirectory.replaceAll("/$", "");
}

public List<CucableFeature> getSourceFeatures() {
Expand Down Expand Up @@ -159,7 +159,7 @@ public String getGeneratedFeatureDirectory() {
}

public void setGeneratedFeatureDirectory(final String generatedFeatureDirectory) {
this.generatedFeatureDirectory = generatedFeatureDirectory;
this.generatedFeatureDirectory = generatedFeatureDirectory.replaceAll("/$", "");
}

public int getNumberOfTestRuns() {
Expand Down
7 changes: 7 additions & 0 deletions plugin-code/src/main/java/com/trivago/vo/SingleScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class SingleScenario {
private final String featureLanguage;
private final String featureDescription;
private final String scenarioName;
private final int lineNumber;
private final String scenarioDescription;
private final List<String> featureTags;
private final List<Step> backgroundSteps;
Expand All @@ -42,6 +43,7 @@ public SingleScenario(
final String featureLanguage,
final String featureDescription,
final String scenarioName,
final int lineNumber,
final String scenarioDescription,
final List<String> featureTags,
final List<Step> backgroundSteps
Expand All @@ -51,6 +53,7 @@ public SingleScenario(
this.featureLanguage = featureLanguage;
this.featureDescription = featureDescription;
this.scenarioName = scenarioName;
this.lineNumber = lineNumber;
this.scenarioDescription = scenarioDescription;
this.featureTags = featureTags;
this.backgroundSteps = backgroundSteps;
Expand Down Expand Up @@ -128,4 +131,8 @@ public String toString() {
", steps=" + steps +
'}';
}

public int getLineNumber() {
return lineNumber;
}
}
Loading

0 comments on commit ac86de7

Please sign in to comment.