Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gherkin: compile empty scenarios to empty pickles #264

Merged
merged 9 commits into from
Oct 6, 2017
48 changes: 26 additions & 22 deletions gherkin/c/src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,24 @@ int Compiler_compile(Compiler* compiler, const GherkinDocument* gherkin_document
}
else if (feature->scenario_definitions->scenario_definitions[i]->type == Gherkin_Scenario) {
const Scenario* scenario = (const Scenario*)feature->scenario_definitions->scenario_definitions[i];
if (scenario->steps->step_count == 0) {
continue;
}
const PickleLocations* locations = PickleLocations_new_single(scenario->location.line, scenario->location.column);
const PickleTags* tags = create_pickle_tags(feature->tags, scenario->tags, 0);
PickleSteps* steps = (PickleSteps*)malloc(sizeof(PickleSteps));
steps->step_count = scenario->steps->step_count + background_step_count;
steps->steps = (PickleStep*)malloc(steps->step_count * sizeof(PickleStep));
if (background_steps) {
copy_steps(steps->steps, background_steps);
if (scenario->steps->step_count == 0) {
steps->step_count = 0;
steps->steps = 0;
} else {
steps->step_count = scenario->steps->step_count + background_step_count;
steps->steps = (PickleStep*)malloc(steps->step_count * sizeof(PickleStep));
if (background_steps) {
copy_steps(steps->steps, background_steps);
}
copy_steps(steps->steps + background_step_count, scenario->steps);
}
copy_steps(steps->steps + background_step_count, scenario->steps);
ItemQueue_add(compiler->pickle_list, (Item*)Pickle_new(feature->language, locations, tags, scenario->name, steps));
}
else if (feature->scenario_definitions->scenario_definitions[i]->type == Gherkin_ScenarioOutline) {
const ScenarioOutline* scenario_outline = (const ScenarioOutline*)feature->scenario_definitions->scenario_definitions[i];
if (scenario_outline->steps->step_count == 0) {
continue;
}
int k;
for (k = 0; k < scenario_outline->examples->example_count; ++k) {
ExampleTable* example_table = &scenario_outline->examples->example_table[k];
Expand All @@ -97,17 +96,22 @@ int Compiler_compile(Compiler* compiler, const GherkinDocument* gherkin_document
const TableRow* table_row = &example_table->table_body->table_rows[l];
const PickleLocations* locations = PickleLocations_new_double(table_row->location.line, table_row->location.column, scenario_outline->location.line, scenario_outline->location.column);
PickleSteps* steps = (PickleSteps*)malloc(sizeof(PickleSteps));
steps->step_count = scenario_outline->steps->step_count + + background_step_count;
steps->steps = (PickleStep*)malloc(steps->step_count * sizeof(PickleStep));
if (background_steps) {
copy_steps(steps->steps, background_steps);
}
int j;
for (j = 0; j < scenario_outline->steps->step_count; ++j) {
int column_offset = scenario_outline->steps->steps[j].keyword ? StringUtilities_code_point_length(scenario_outline->steps->steps[j].keyword) : 0;
const PickleLocations* step_locations = PickleLocations_new_double(table_row->location.line, table_row->location.column, scenario_outline->steps->steps[j].location.line, scenario_outline->steps->steps[j].location.column + column_offset);
const PickleStep* step = expand_outline_step(&scenario_outline->steps->steps[j], example_table->table_header, table_row, step_locations);
PickleStep_transfer(&steps->steps[background_step_count + j], (PickleStep*)step);
if (scenario_outline->steps->step_count == 0) {
steps->step_count = 0;
steps->steps = 0;
} else {
steps->step_count = scenario_outline->steps->step_count + + background_step_count;
steps->steps = (PickleStep*)malloc(steps->step_count * sizeof(PickleStep));
if (background_steps) {
copy_steps(steps->steps, background_steps);
}
int j;
for (j = 0; j < scenario_outline->steps->step_count; ++j) {
int column_offset = scenario_outline->steps->steps[j].keyword ? StringUtilities_code_point_length(scenario_outline->steps->steps[j].keyword) : 0;
const PickleLocations* step_locations = PickleLocations_new_double(table_row->location.line, table_row->location.column, scenario_outline->steps->steps[j].location.line, scenario_outline->steps->steps[j].location.column + column_offset);
const PickleStep* step = expand_outline_step(&scenario_outline->steps->steps[j], example_table->table_header, table_row, step_locations);
PickleStep_transfer(&steps->steps[background_step_count + j], (PickleStep*)step);
}
}
const wchar_t* new_name = create_expanded_text(scenario_outline->name, example_table->table_header, table_row);
ItemQueue_add(compiler->pickle_list, (Item*)Pickle_new(feature->language, locations, tags, new_name, steps));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"pickle":{"language":"en","locations":[{"column":7,"line":9},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":9},{"column":11,"line":4}],"text":"the foo"}],"tags":[{"location":{"column":5,"line":6},"name":"@foo"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":7,"line":14},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":14},{"column":11,"line":4}],"text":"the bar"}],"tags":[{"location":{"column":5,"line":11},"name":"@bar"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":17}],"name":"ha ok","steps":[],"tags":[{"location":{"column":3,"line":16},"name":"@zap"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
12 changes: 4 additions & 8 deletions gherkin/dotnet/Gherkin/Pickles/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public List<Pickle> Compile(GherkinDocument gherkinDocument)

protected virtual void CompileScenario(List<Pickle> pickles, IEnumerable<PickleStep> backgroundSteps, Scenario scenario, IEnumerable<Tag> featureTags, string language)
{
if (!scenario.Steps.Any())
return;

var steps = new List<PickleStep>();
steps.AddRange(backgroundSteps);
if (scenario.Steps.Any())
steps.AddRange(backgroundSteps);

var scenarioTags = new List<Tag>();
scenarioTags.AddRange(featureTags);
Expand All @@ -69,9 +67,6 @@ protected virtual IEnumerable<T> SingletonList<T>(T item)

protected virtual void CompileScenarioOutline(List<Pickle> pickles, IEnumerable<PickleStep> backgroundSteps, ScenarioOutline scenarioOutline, IEnumerable<Tag> featureTags, string language)
{
if (!scenarioOutline.Steps.Any())
return;

foreach (var examples in scenarioOutline.Examples)
{
if (examples.TableHeader == null) continue;
Expand All @@ -81,7 +76,8 @@ protected virtual void CompileScenarioOutline(List<Pickle> pickles, IEnumerable<
var valueCells = values.Cells;

var steps = new List<PickleStep>();
steps.AddRange(backgroundSteps);
if (scenarioOutline.Steps.Any())
steps.AddRange(backgroundSteps);

var tags = new List<Tag>();
tags.AddRange(featureTags);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"pickle":{"language":"en","locations":[{"column":7,"line":9},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":9},{"column":11,"line":4}],"text":"the foo"}],"tags":[{"location":{"column":5,"line":6},"name":"@foo"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":7,"line":14},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":14},{"column":11,"line":4}],"text":"the bar"}],"tags":[{"location":{"column":5,"line":11},"name":"@bar"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":17}],"name":"ha ok","steps":[],"tags":[{"location":{"column":3,"line":16},"name":"@zap"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
17 changes: 8 additions & 9 deletions gherkin/go/pickles.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (gd *GherkinDocument) Pickles() []*Pickle {
case *Background:
bgSteps = append(bgSteps, pickleSteps(t.Steps)...)
case *Scenario:
if len(t.Steps) == 0 {
continue
steps := make([]*PickleStep, 0)
if len(t.Steps) > 0 {
steps = append(bgSteps, pickleSteps(t.Steps)...)
}
steps := append(bgSteps, pickleSteps(t.Steps)...)
tags := pickleTags(append(gd.Feature.Tags, t.Tags...))
pickles = append(pickles, &Pickle{
Steps: steps,
Expand All @@ -72,10 +72,6 @@ func (gd *GherkinDocument) Pickles() []*Pickle {
Locations: []Location{*t.Location},
})
case *ScenarioOutline:
if len(t.Steps) == 0 {
continue
}

for _, examples := range t.Examples {
if examples.TableHeader == nil {
continue
Expand All @@ -85,7 +81,7 @@ func (gd *GherkinDocument) Pickles() []*Pickle {
vals := example.Cells
tags := pickleTags(append(gd.Feature.Tags, append(t.Tags, examples.Tags...)...))

var steps []*PickleStep
steps := make([]*PickleStep, 0)

// translate steps based on example
for _, step := range t.Steps {
Expand All @@ -112,8 +108,11 @@ func (gd *GherkinDocument) Pickles() []*Pickle {
name = strings.Replace(name, "<"+key.Value+">", vals[i].Value, -1)
}

if len(steps) > 0 {
steps = append(bgSteps, steps...)
}
pickles = append(pickles, &Pickle{
Steps: append(bgSteps, steps...),
Steps: steps,
Tags: tags,
Name: name,
Language: gd.Feature.Language,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"pickle":{"language":"en","locations":[{"column":7,"line":9},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":9},{"column":11,"line":4}],"text":"the foo"}],"tags":[{"location":{"column":5,"line":6},"name":"@foo"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":7,"line":14},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":14},{"column":11,"line":4}],"text":"the bar"}],"tags":[{"location":{"column":5,"line":11},"name":"@bar"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":17}],"name":"ha ok","steps":[],"tags":[{"location":{"column":3,"line":16},"name":"@zap"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
12 changes: 4 additions & 8 deletions gherkin/java/src/main/java/gherkin/pickles/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ public List<Pickle> compile(GherkinDocument gherkinDocument) {
}

private void compileScenario(List<Pickle> pickles, List<PickleStep> backgroundSteps, Scenario scenario, List<Tag> featureTags, String language) {
if (scenario.getSteps().isEmpty())
return;

List<PickleStep> steps = new ArrayList<>();
steps.addAll(backgroundSteps);
if (!scenario.getSteps().isEmpty())
steps.addAll(backgroundSteps);

List<Tag> scenarioTags = new ArrayList<>();
scenarioTags.addAll(featureTags);
Expand All @@ -74,17 +72,15 @@ private void compileScenario(List<Pickle> pickles, List<PickleStep> backgroundSt
}

private void compileScenarioOutline(List<Pickle> pickles, List<PickleStep> backgroundSteps, ScenarioOutline scenarioOutline, List<Tag> featureTags, String language) {
if (scenarioOutline.getSteps().isEmpty())
return;

for (final Examples examples : scenarioOutline.getExamples()) {
if (examples.getTableHeader() == null) continue;
List<TableCell> variableCells = examples.getTableHeader().getCells();
for (final TableRow values : examples.getTableBody()) {
List<TableCell> valueCells = values.getCells();

List<PickleStep> steps = new ArrayList<>();
steps.addAll(backgroundSteps);
if (!scenarioOutline.getSteps().isEmpty())
steps.addAll(backgroundSteps);

List<Tag> tags = new ArrayList<>();
tags.addAll(featureTags);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"pickle":{"language":"en","locations":[{"column":7,"line":9},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":9},{"column":11,"line":4}],"text":"the foo"}],"tags":[{"location":{"column":5,"line":6},"name":"@foo"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":7,"line":14},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":14},{"column":11,"line":4}],"text":"the bar"}],"tags":[{"location":{"column":5,"line":11},"name":"@bar"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":17}],"name":"ha ok","steps":[],"tags":[{"location":{"column":3,"line":16},"name":"@zap"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
8 changes: 2 additions & 6 deletions gherkin/javascript/dist/gherkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6229,9 +6229,7 @@ function Compiler() {
};

function compileScenario(featureTags, backgroundSteps, scenario, language, pickles) {
if (scenario.steps.length == 0) return;

var steps = [].concat(backgroundSteps);
var steps = scenario.steps.length == 0 ? [] : [].concat(backgroundSteps);

var tags = [].concat(featureTags).concat(scenario.tags);

Expand All @@ -6250,13 +6248,11 @@ function Compiler() {
}

function compileScenarioOutline(featureTags, backgroundSteps, scenarioOutline, language, pickles) {
if (scenarioOutline.steps.length == 0) return;

scenarioOutline.examples.filter(function(e) { return e.tableHeader != undefined; }).forEach(function (examples) {
var variableCells = examples.tableHeader.cells;
examples.tableBody.forEach(function (values) {
var valueCells = values.cells;
var steps = [].concat(backgroundSteps);
var steps = scenarioOutline.steps.length == 0 ? [] : [].concat(backgroundSteps);
var tags = [].concat(featureTags).concat(scenarioOutline.tags).concat(examples.tags);

scenarioOutline.steps.forEach(function (scenarioOutlineStep) {
Expand Down
2 changes: 1 addition & 1 deletion gherkin/javascript/dist/gherkin.min.js

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions gherkin/javascript/lib/gherkin/pickles/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ function Compiler() {
};

function compileScenario(featureTags, backgroundSteps, scenario, language, pickles) {
if (scenario.steps.length == 0) return;

var steps = [].concat(backgroundSteps);
var steps = scenario.steps.length == 0 ? [] : [].concat(backgroundSteps);

var tags = [].concat(featureTags).concat(scenario.tags);

Expand All @@ -45,13 +43,11 @@ function Compiler() {
}

function compileScenarioOutline(featureTags, backgroundSteps, scenarioOutline, language, pickles) {
if (scenarioOutline.steps.length == 0) return;

scenarioOutline.examples.filter(function(e) { return e.tableHeader != undefined; }).forEach(function (examples) {
var variableCells = examples.tableHeader.cells;
examples.tableBody.forEach(function (values) {
var valueCells = values.cells;
var steps = [].concat(backgroundSteps);
var steps = scenarioOutline.steps.length == 0 ? [] : [].concat(backgroundSteps);
var tags = [].concat(featureTags).concat(scenarioOutline.tags).concat(examples.tags);

scenarioOutline.steps.forEach(function (scenarioOutlineStep) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"pickle":{"language":"en","locations":[{"column":7,"line":9},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":9},{"column":11,"line":4}],"text":"the foo"}],"tags":[{"location":{"column":5,"line":6},"name":"@foo"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":7,"line":14},{"column":3,"line":3}],"name":"minimalistic","steps":[{"arguments":[],"locations":[{"column":7,"line":14},{"column":11,"line":4}],"text":"the bar"}],"tags":[{"location":{"column":5,"line":11},"name":"@bar"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
{"pickle":{"language":"en","locations":[{"column":3,"line":17}],"name":"ha ok","steps":[],"tags":[{"location":{"column":3,"line":16},"name":"@zap"}]},"type":"pickle","uri":"testdata/good/several_examples.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":3,"line":6}],"name":"no steps","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario.feature"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle":{"language":"en","locations":[{"column":5,"line":24},{"column":3,"line":20}],"name":"no steps, one example header","steps":[],"tags":[]},"type":"pickle","uri":"testdata/good/incomplete_scenario_outline.feature"}
Loading