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

Implement Rule #71

Merged
merged 14 commits into from
Jul 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
* @param background -
*/
virtual task visit_background(gherkin_pkg::background background);
$display({1{" "}}, background.keyword, ": ", background.scenario_definition_name);
$display(indent(1), background.keyword, ": ", background.scenario_definition_name);

if (background.description.len() > 0) begin
$write({2{" "}});
$write(string'(indent(2)));
foreach (background.description[i]) begin
byte c = background.description[i];

$write(string'(c));
if (c inside {"\n", CR}) begin
$write({2{" "}});
$write(indent(2));
end
end
$display();
Expand Down Expand Up @@ -109,16 +109,16 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
endtask : visit_doc_string

virtual task visit_examples(gherkin_pkg::examples examples);
$display({{2{" "}}, examples.keyword, ": ", examples.examples_name});
$display({indent(2), examples.keyword, ": ", examples.examples_name});

if (examples.description != "") begin
$write({2{" "}});
$write(indent(2));
foreach (examples.description[i]) begin
byte c = examples.description[i];

$write(string'(c));
if (c inside {"\n", CR}) begin
$write({2{" "}});
$write(indent(2));
end
end
$display();
Expand All @@ -145,20 +145,24 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito

$display(feature.keyword, ": ", feature.feature_name);

$write({1{" "}});
$write(indent(1));
foreach (feature.description[i]) begin
byte c = feature.description[i];

$write(string'(c));
if (c == "\n") begin
$write({1{" "}});
$write(indent(1));
end
end
$display();

foreach(feature.scenario_definitions[i]) begin
feature.scenario_definitions[i].accept(this);
end

foreach(feature.rules[i]) begin
feature.rules[i].accept(this);
end
endtask : visit_feature

virtual task visit_gherkin_document(gherkin_pkg::gherkin_document gherkin_document);
Expand All @@ -175,15 +179,15 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
scenario.tags[i].accept(this); // visit_tag(scenario.tags[i])
end

$display({1{" "}}, scenario.keyword, ": ", scenario.scenario_definition_name);
$display(indent(1), scenario.keyword, ": ", scenario.scenario_definition_name);

$write({2{" "}});
$write(indent(2));
foreach (scenario.description[i]) begin
byte c = scenario.description[i];

$write(string'(c));
if (c == "\n") begin
$write({2{" "}});
$write(indent(2));
end
end
$display();
Expand All @@ -203,15 +207,15 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
scenario_outline.tags[i].accept(this); // visit_tag(scenario_outline.tags[i])
end

$display({1{" "}}, scenario_outline.keyword, ": ", scenario_outline.scenario_definition_name);
$display(indent(1), scenario_outline.keyword, ": ", scenario_outline.scenario_definition_name);

$write({2{" "}});
$write(indent(2));
foreach (scenario_outline.description[i]) begin
byte c = scenario_outline.description[i];

$write(string'(c));
if (c == "\n") begin
$write({2{" "}});
$write(indent(2));
end
end
$display();
Expand All @@ -228,7 +232,7 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
endtask : visit_scenario_outline

virtual task visit_step(gherkin_pkg::step step);
$display({2{" "}}, step.keyword, " ", step.text);
$display(indent(2), step.keyword, " ", step.text);
if (step.argument != null) begin
step.argument.accept(this);
end
Expand All @@ -239,11 +243,11 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito
endtask : visit_step_argument

virtual task visit_table_cell(gherkin_pkg::table_cell table_cell);
$write({" ", table_cell.value, " |"});
$write(string'({" ", table_cell.value, " |"}));
endtask : visit_table_cell

virtual task visit_table_row(gherkin_pkg::table_row table_row);
$write({{2{" "}}, "|"});
$write(string'({indent(2), "|"}));
foreach (table_row.cells[i]) begin
table_row.cells[i].accept(this); // visit_table_cell(table_row.cells[i])
end
Expand All @@ -258,6 +262,35 @@ class gherkin_document_printer extends uvm_object implements gherkin_pkg::visito

endtask : visit_tag

virtual task visit_rule(gherkin_pkg::rule rule);

// foreach (rule.tags[i]) begin
// rule.tags[i].accept(this); // visit_tag(rule.tags[i])
// end

$display(rule.keyword, ": ", rule.rule_name);

$write(indent(1));
foreach (rule.description[i]) begin
byte c = rule.description[i];

$write(string'(c));
if (c == "\n") begin
$write(indent(1));
end
end
$display();

foreach(rule.scenario_definitions[i]) begin
rule.scenario_definitions[i].accept(this);
end
endtask : visit_rule


static function string indent(int n);
return string'({n{" "}});
endfunction : indent

endclass : gherkin_document_printer

`endif // __GHERKIN_DOCUMENT_PRINTER_SVH
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class gherkin_document_runner extends uvm_object implements gherkin_pkg::visitor

gherkin_pkg::gherkin_document document;
gherkin_pkg::background feature_background;
gherkin_pkg::background rule_background;

uvm_sequencer_base sequencer;
uvm_sequence_base parent_sequence;
Expand Down Expand Up @@ -276,18 +277,27 @@ class gherkin_document_runner extends uvm_object implements gherkin_pkg::visitor
end
end

start = this.starting_scenario_number;
stop = this.stopping_scenario_number;
while (start < 0) start += only_scenarios.size();
if (start > only_scenarios.size()) start = only_scenarios.size();
while (stop <= 0) stop += only_scenarios.size();
if (stop > only_scenarios.size()) stop = only_scenarios.size();

for(int i = start; i < stop; i++) begin
only_scenarios[i].accept(this);
if (only_scenarios.size() > 0) begin

start = this.starting_scenario_number;
stop = this.stopping_scenario_number;
while (start < 0) start += only_scenarios.size();
if (start > only_scenarios.size()) start = only_scenarios.size();
while (stop <= 0) stop += only_scenarios.size();
if (stop > only_scenarios.size()) stop = only_scenarios.size();

for(int i = start; i < stop; i++) begin
only_scenarios[i].accept(this);
end
end

// Run rules after loose scenarios
foreach (feature.rules[i]) begin
feature.rules[i].accept(this);
end

feature_tags.delete();
this.feature_background = null;
endtask : visit_feature

virtual task visit_gherkin_document(gherkin_pkg::gherkin_document gherkin_document);
Expand Down Expand Up @@ -538,6 +548,42 @@ class gherkin_document_runner extends uvm_object implements gherkin_pkg::visitor

endtask : visit_tag

virtual task visit_rule(gherkin_pkg::rule rule);
gherkin_pkg::background rule_background;
int start;
int stop;
gherkin_pkg::scenario_definition only_scenarios[$];

`uvm_info_context(get_name(), $sformatf("%s: %s", rule.keyword, rule.rule_name), UVM_MEDIUM, report_object)

// rule_tags.delete();
// foreach (rule.tags[i]) begin
// rule_tags.push_back(rule.tags[i].tag_name);
// end

// Separate background from scenario definitions
only_scenarios.delete();
foreach (rule.scenario_definitions[i]) begin
if ($cast(rule_background, rule.scenario_definitions[i])) begin
assert_only_one_background : assert (this.rule_background == null) else
`uvm_fatal_context_begin(get_name(), "Found more than one background definition", report_object)
`uvm_message_add_string(this.rule_background.scenario_definition_name, "Existing background")
`uvm_message_add_string(rule_background.scenario_definition_name, "Conflicting background")
`uvm_fatal_context_end
this.rule_background = rule_background;
end
else begin
only_scenarios.push_back(rule.scenario_definitions[i]);
end
end

foreach(only_scenarios[i]) begin
only_scenarios[i].accept(this);
end

// rule_tags.delete();
this.rule_background = null;
endtask : visit_rule

virtual function bit tag_check(string tags[$]);

Expand Down
43 changes: 42 additions & 1 deletion src/bathtub_pkg/gherkin_parser/gherkin_parser.svh
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ class gherkin_parser extends uvm_object implements gherkin_parser_interface;
while (status == OK) begin
if (line_obj.eof) break;
analyze_line(line_obj.text, line_analysis_result);
if (line_analysis_result.token_before_colon inside {"Background", "Scenario", "Example", "Scenario Outline", "Scenario Template"}) begin
if (line_analysis_result.token_before_colon inside {"Rule", "Background", "Scenario", "Example", "Scenario Outline", "Scenario Template"}) begin
break;
end
else begin
Expand All @@ -619,6 +619,45 @@ class gherkin_parser extends uvm_object implements gherkin_parser_interface;
endtask : parse_feature_description


virtual task parse_rule_description(ref string description, ref line_value line_obj);
line_analysis_result_t line_analysis_result;

line_mbox.peek(line_obj);

`uvm_info_context_begin(`BATHTUB__GET_SCOPE_NAME(), "gherkin_parser::parse_rule_description enter", UVM_HIGH, report_object)
`uvm_message_add_string(line_obj.file_name)
`uvm_message_add_int(line_obj.line_number, UVM_DEC)
`uvm_message_add_int(line_obj.eof, UVM_BIN)
if (!line_obj.eof) begin
`uvm_message_add_string(line_obj.text)
end
`uvm_info_context_end

if (!line_obj.eof) begin

description = "";

while (status == OK) begin
if (line_obj.eof) break;
analyze_line(line_obj.text, line_analysis_result);
if (line_analysis_result.token_before_colon inside {"Background", "Scenario", "Example", "Scenario Outline", "Scenario Template"}) begin
break;
end
else begin
description = {description, bathtub_utils::trim_white_space(line_obj.text), "\n"};
get_next_line(line_obj);
end
end

end

`uvm_info_context_begin(`BATHTUB__GET_SCOPE_NAME(), "gherkin_parser::parse_rule_description exit", UVM_HIGH, report_object)
`uvm_message_add_string(description)
`uvm_message_add_int(line_obj.eof, UVM_BIN)
`uvm_info_context_end
endtask : parse_rule_description


virtual task parse_examples_description(ref string description, ref line_value line_obj);
line_analysis_result_t line_analysis_result;

Expand Down Expand Up @@ -729,6 +768,7 @@ class gherkin_parser extends uvm_object implements gherkin_parser_interface;
extern virtual task parse_examples(ref gherkin_pkg::examples examples);
extern virtual task parse_feature(ref gherkin_pkg::feature feature);
extern virtual task parse_gherkin_document(ref gherkin_pkg::gherkin_document gherkin_document);
extern virtual task parse_rule(ref gherkin_pkg::rule rule);
extern virtual task parse_scenario(ref gherkin_pkg::scenario scenario);
extern virtual task parse_scenario_definition(ref gherkin_pkg::scenario_definition scenario_definition);
extern virtual task parse_scenario_outline(ref gherkin_pkg::scenario_outline scenario_outline);
Expand All @@ -747,6 +787,7 @@ endclass : gherkin_parser
`include "bathtub_pkg/gherkin_parser/parse_examples.svh"
`include "bathtub_pkg/gherkin_parser/parse_feature.svh"
`include "bathtub_pkg/gherkin_parser/parse_gherkin_document.svh"
`include "bathtub_pkg/gherkin_parser/parse_rule.svh"
`include "bathtub_pkg/gherkin_parser/parse_scenario.svh"
`include "bathtub_pkg/gherkin_parser/parse_scenario_definition.svh"
`include "bathtub_pkg/gherkin_parser/parse_scenario_outline.svh"
Expand Down
10 changes: 10 additions & 0 deletions src/bathtub_pkg/gherkin_parser/parse_feature.svh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ task gherkin_parser::parse_feature(ref gherkin_pkg::feature feature);
end
end

"Rule" : begin : construct_rule
gherkin_pkg::rule rule;

parse_rule(rule);
`pop_from_parser_stack(rule)
if (status == OK) begin
feature_value.rules.push_back(rule);
end
end

default : begin

case (line_analysis_result.secondary_keyword)
Expand Down
Loading