about summary refs log tree commit diff stats
path: root/050scenario.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-15 23:14:30 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-11-15 23:14:30 -0800
commit195a846b8ca7b5360c7d19d5d29746f0cee27576 (patch)
tree75b62bad8cfef44a3a1b734b8e38e2704ccf8248 /050scenario.cc
parent00e9ddebbd5c6e23b77a7e43fc8cd6c99a1c0672 (diff)
downloadmu-195a846b8ca7b5360c7d19d5d29746f0cee27576.tar.gz
3677 - gracefully handle parse errors in scenarios
Thanks Jack Couch for running into this.
Diffstat (limited to '050scenario.cc')
-rw-r--r--050scenario.cc29
1 files changed, 26 insertions, 3 deletions
diff --git a/050scenario.cc b/050scenario.cc
index a7f59c68..d67b51e0 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -57,6 +57,10 @@ scenario foo [
 struct scenario {
   string name;
   string to_run;
+  void clear() {
+    name.clear();
+    to_run.clear();
+  }
 };
 
 :(before "End Globals")
@@ -67,7 +71,9 @@ vector<scenario> Scenarios;
 
 :(before "End Command Handlers")
 else if (command == "scenario") {
-  Scenarios.push_back(parse_scenario(in));
+  scenario result = parse_scenario(in);
+  if (!result.name.empty())
+    Scenarios.push_back(result);
 }
 else if (command == "pending-scenario") {
   // for temporary use only
@@ -92,9 +98,17 @@ scenario parse_scenario(istream& in) {
   // inside comments
   result.to_run = slurp_quoted(in);
   // delete [] delimiters
-  assert(starts_with(result.to_run, "["));
+  if (!starts_with(result.to_run, "[")) {
+    raise << "scenario " << result.name << " should start with '['\n" << end();
+    result.clear();
+    return result;
+  }
   result.to_run.erase(0, 1);
-  assert(result.to_run.at(SIZE(result.to_run)-1) == ']');
+  if (result.to_run.at(SIZE(result.to_run)-1) != ']') {
+    raise << "scenario " << result.name << " has an unbalanced '['\n" << end();
+    result.clear();
+    return result;
+  }
   result.to_run.erase(SIZE(result.to_run)-1);
   return result;
 }
@@ -260,6 +274,15 @@ def scenario-foo [
 ]
 +error: redefining recipe scenario-foo
 
+:(scenario scenario_containing_parse_error)
+% Hide_errors = true;
+scenario foo [
+  memory-should-contain [
+    1 <- 0
+  # missing ']'
+]
+# no crash
+
 :(scenario scenario_containing_transform_error)
 % Hide_errors = true;
 def main [