diff options
-rw-r--r-- | 050scenario.cc | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/050scenario.cc b/050scenario.cc index 5e4e9309..c1eeecf2 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -64,7 +64,14 @@ struct scenario { }; :(before "End Globals") -vector<scenario> Scenarios; +vector<scenario> Scenarios, Scenarios_snapshot; +set<string> Scenario_names, Scenario_names_snapshot; +:(before "End save_snapshots") +Scenarios_snapshot = Scenarios; +Scenario_names_snapshot = Scenario_names; +:(before "End restore_snapshots") +Scenarios = Scenarios_snapshot; +Scenario_names = Scenario_names_snapshot; //:: Parse the 'scenario' form. //: Simply store the text of the scenario. @@ -84,6 +91,9 @@ else if (command == "pending-scenario") { scenario parse_scenario(istream& in) { scenario result; result.name = next_word(in); + if (contains_key(Scenario_names, result.name)) + raise << "duplicate scenario name: '" << result.name << "'\n" << end(); + Scenario_names.insert(result.name); if (result.name.empty()) { assert(!has_data(in)); raise << "incomplete scenario at end of file\n" << end(); @@ -126,6 +136,17 @@ scenario foo [ ] +run: {1: ("address" "array" "character")} <- new {"# not a comment": "literal-string"} +:(scenarios run) +:(scenario duplicate_scenarios) +% Hide_errors = true; +scenario foo [ + 1:num <- copy 0 +] +scenario foo [ + 2:num <- copy 0 +] ++error: duplicate scenario name: 'foo' + //:: Run scenarios when we run './mu test'. //: Treat the text of the scenario as a regular series of instructions. @@ -269,7 +290,6 @@ void test_maybe_make_raw() { //: Watch out for redefinitions of scenario routines. We should never ever be //: doing that, regardless of anything else. -:(scenarios run) :(scenario forbid_redefining_scenario_even_if_forced) % Hide_errors = true; % Disable_redefine_checks = true; @@ -817,6 +837,7 @@ void mark_autogenerated(recipe_ordinal r) { :(code) // just for the scenarios running scenarios in C++ layers void run_mu_scenario(const string& form) { + Scenario_names.clear(); istringstream in(form); in >> std::noskipws; skip_whitespace_and_comments(in); |