about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/010vm4
-rw-r--r--cpp/011load15
-rw-r--r--cpp/013run21
-rw-r--r--cpp/024brace1
-rw-r--r--cpp/025name6
5 files changed, 25 insertions, 22 deletions
diff --git a/cpp/010vm b/cpp/010vm
index 8d1c71df..aa75c6ae 100644
--- a/cpp/010vm
+++ b/cpp/010vm
@@ -138,10 +138,10 @@ void setup_recipes() {
 //: startup, and carefully undo each test's additions after itself.
 :(before "End One-time Setup")
   setup_recipes();
-  load("core.mu");
+  // End Load Recipes
+  // give tests a consistent starting point
   assert(Next_recipe_number < 100);
   Next_recipe_number = 100;
-  recipes_added_by_test.clear();  // Freeze everything added so far.
   delete Trace_stream;  Trace_stream = new trace_stream;
 :(before "End Setup")
   Next_recipe_number = 100;  // consistent new numbers for each test
diff --git a/cpp/011load b/cpp/011load
index c111ba42..3ef1a409 100644
--- a/cpp/011load
+++ b/cpp/011load
@@ -24,7 +24,6 @@ vector<recipe_number> add_recipes(istream& in) {
     // Command Handlers
     if (command == "recipe") {
       result.push_back(add_recipe(in));
-      recipes_added_by_test.push_back(result.back());
     }
     // End Command Handlers
     else {
@@ -65,6 +64,8 @@ recipe_number add_recipe(istream& in) {
   }
   Recipe[r].name = recipe_name;
 //?   cout << "recipe " << recipe_name << " has " << Recipe[r].steps.size() << " steps.\n"; //? 1
+  // track added recipes because we may need to undo them in tests; see below
+  recently_added_recipes.push_back(r);
   return r;
 }
 
@@ -187,6 +188,18 @@ void skip_comma(istream& in) {
   skip_whitespace(in);
 }
 
+//: Recipes added for tests should be easy to remove as well.
+:(before "End Globals")
+vector<recipe_number> recently_added_recipes;
+:(before "End Setup")
+for (size_t i = 0; i < recently_added_recipes.size(); ++i) {
+//?   cout << "AAA clearing " << Recipe[recently_added_recipes[i]].name << '\n'; //? 2
+  Recipe_number.erase(Recipe[recently_added_recipes[i]].name);
+  Recipe.erase(recently_added_recipes[i]);
+}
+// Clear state for recently_added_recipes
+recently_added_recipes.clear();
+
 :(scenario parse_comment_outside_recipe)
 # comment
 recipe main [
diff --git a/cpp/013run b/cpp/013run
index 1ccbb3b3..134df75a 100644
--- a/cpp/013run
+++ b/cpp/013run
@@ -108,28 +108,19 @@ void load(string filename) {
   fin.close();
 }
 
-//: helper for tests
+//: On startup, load everything in core.mu
+:(before "End Load Recipes")
+load("core.mu");
+recently_added_recipes.clear();  // Freeze everything so it doesn't get cleared by tests.
 
-:(before "End Globals")
-// track recipes added so that we can cleanup after each test
-vector<recipe_number> recipes_added_by_test;
+//: helper for tests
 
 :(code)
 void run(string form) {
   vector<recipe_number> tmp = add_recipes(form);
-  recipes_added_by_test.insert(recipes_added_by_test.end(), tmp.begin(), tmp.end());
   transform_all();
-  run(recipes_added_by_test.front());
-}
-
-:(before "End Setup")
-for (size_t i = 0; i < recipes_added_by_test.size(); ++i) {
-//?   cout << "AAA clearing " << Recipe[recipes_added_by_test[i]].name << '\n'; //? 2
-  Recipe_number.erase(Recipe[recipes_added_by_test[i]].name);
-  Recipe.erase(recipes_added_by_test[i]);
+  run(tmp.front());
 }
-// Clear state for recipes_added_by_test
-recipes_added_by_test.clear();
 
 :(code)
 vector<int> read_memory(reagent x) {
diff --git a/cpp/024brace b/cpp/024brace
index 47dd5596..a0f4aa29 100644
--- a/cpp/024brace
+++ b/cpp/024brace
@@ -164,7 +164,6 @@ void transform_test(string form) {
 //?   cout << "AAA transform_test {\n"; //? 1
   vector<recipe_number> tmp = add_recipes(form);
 //?   cout << "AAA done adding recipes\n"; //? 1
-  recipes_added_by_test.insert(recipes_added_by_test.end(), tmp.begin(), tmp.end());
   transform_all();
 //?   cout << "AAA }\n"; //? 1
 }
diff --git a/cpp/025name b/cpp/025name
index 0c36d5ca..62c07c85 100644
--- a/cpp/025name
+++ b/cpp/025name
@@ -25,9 +25,9 @@ Transform.push_back(transform_names);
 unordered_map<recipe_number, unordered_map<string, int> > Name;
 :(before "End One-time Setup")
 Name.clear();
-:(before "Clear state for recipes_added_by_test")
-for (size_t i = 0; i < recipes_added_by_test.size(); ++i) {
-  Name.erase(recipes_added_by_test[i]);
+:(before "Clear state for recently_added_recipes")
+for (size_t i = 0; i < recently_added_recipes.size(); ++i) {
+  Name.erase(recently_added_recipes[i]);
 }
 
 :(code)