diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-12-27 18:35:27 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-12-27 18:35:27 -0800 |
commit | df0c0babff599b0ab85f56cd50ee0b4143f12886 (patch) | |
tree | e7a77e30de8669b7d87be1b5061d80d02ca53d89 | |
parent | c792fe8ea24e1ba040474b672e7e219385b26569 (diff) | |
download | mu-df0c0babff599b0ab85f56cd50ee0b4143f12886.tar.gz |
3724 - flag duplicate scenarios
I took this feature out in 3161 (back in Aug) to support scenarios in lesson/recipes.mu. Setting up snapshots for scenario data structures gives us the best of both worlds.
-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); |