about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-01 23:43:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-01 23:43:45 -0700
commitc2089aaa653852c3a3f5e100658f74ec6dc62fb8 (patch)
tree209b46c15794e246aa2068746cc921f9b6885e83
parent36d163092fe951fd897dfb396c5e2cb301977800 (diff)
downloadmu-c2089aaa653852c3a3f5e100658f74ec6dc62fb8.tar.gz
1235
-rw-r--r--cpp/.traces/trace_negative_check_passes_silently16
-rw-r--r--cpp/.traces/trace_negative_check_warns_on_any_unexpected_line42
-rw-r--r--cpp/.traces/trace_negative_check_warns_on_failure38
-rw-r--r--cpp/049scenario_helpers.cc59
4 files changed, 155 insertions, 0 deletions
diff --git a/cpp/.traces/trace_negative_check_passes_silently b/cpp/.traces/trace_negative_check_passes_silently
new file mode 100644
index 00000000..b572cb34
--- /dev/null
+++ b/cpp/.traces/trace_negative_check_passes_silently
@@ -0,0 +1,16 @@
+parse/0: instruction: trace-should-not-contain
+parse/0:   ingredient: {name: "
+    a: b
+  ", value: 0, type: 0, properties: ["
+    a: b
+  ": "literal-string"]}
+after-brace/0: recipe main
+after-brace/0: trace-should-not-contain ...
+new/0: routine allocated memory from 1000 to 101000
+schedule/0: main
+run/0: instruction main/0
+run/0: trace-should-not-contain {name: "
+    a: b
+  ", value: 0, type: 0, properties: ["
+    a: b
+  ": "literal-string"]}
diff --git a/cpp/.traces/trace_negative_check_warns_on_any_unexpected_line b/cpp/.traces/trace_negative_check_warns_on_any_unexpected_line
new file mode 100644
index 00000000..913028a6
--- /dev/null
+++ b/cpp/.traces/trace_negative_check_warns_on_any_unexpected_line
@@ -0,0 +1,42 @@
+parse/0: instruction: run
+parse/0:   ingredient: {name: "
+    trace [a], [d]
+  ", value: 0, type: 0, properties: ["
+    trace [a], [d]
+  ": "literal-string"]}
+parse/0: instruction: trace-should-not-contain
+parse/0:   ingredient: {name: "
+    a: b
+    a: d
+  ", value: 0, type: 0, properties: ["
+    a: b
+    a: d
+  ": "literal-string"]}
+after-brace/0: recipe main
+after-brace/0: run ...
+after-brace/0: trace-should-not-contain ...
+new/0: routine allocated memory from 1000 to 101000
+schedule/0: main
+run/0: instruction main/0
+run/0: run {name: "
+    trace [a], [d]
+  ", value: 0, type: 0, properties: ["
+    trace [a], [d]
+  ": "literal-string"]}
+parse/0: instruction: trace
+parse/0:   ingredient: {name: "a", value: 0, type: 0, properties: ["a": "literal-string"]}
+parse/0:   ingredient: {name: "d", value: 0, type: 0, properties: ["d": "literal-string"]}
+after-brace/0: recipe tmp0
+after-brace/0: trace ...
+run/0: instruction tmp0/0
+run/0: trace {name: "a", value: 0, type: 0, properties: ["a": "literal-string"]}, {name: "d", value: 0, type: 0, properties: ["d": "literal-string"]}
+a/0: d
+run/0: instruction main/1
+run/0: trace-should-not-contain {name: "
+    a: b
+    a: d
+  ", value: 0, type: 0, properties: ["
+    a: b
+    a: d
+  ": "literal-string"]}
+warn/0: unexpected [d] in trace layer a
diff --git a/cpp/.traces/trace_negative_check_warns_on_failure b/cpp/.traces/trace_negative_check_warns_on_failure
new file mode 100644
index 00000000..42edb11a
--- /dev/null
+++ b/cpp/.traces/trace_negative_check_warns_on_failure
@@ -0,0 +1,38 @@
+parse/0: instruction: run
+parse/0:   ingredient: {name: "
+    trace [a], [b]
+  ", value: 0, type: 0, properties: ["
+    trace [a], [b]
+  ": "literal-string"]}
+parse/0: instruction: trace-should-not-contain
+parse/0:   ingredient: {name: "
+    a: b
+  ", value: 0, type: 0, properties: ["
+    a: b
+  ": "literal-string"]}
+after-brace/0: recipe main
+after-brace/0: run ...
+after-brace/0: trace-should-not-contain ...
+new/0: routine allocated memory from 1000 to 101000
+schedule/0: main
+run/0: instruction main/0
+run/0: run {name: "
+    trace [a], [b]
+  ", value: 0, type: 0, properties: ["
+    trace [a], [b]
+  ": "literal-string"]}
+parse/0: instruction: trace
+parse/0:   ingredient: {name: "a", value: 0, type: 0, properties: ["a": "literal-string"]}
+parse/0:   ingredient: {name: "b", value: 0, type: 0, properties: ["b": "literal-string"]}
+after-brace/0: recipe tmp0
+after-brace/0: trace ...
+run/0: instruction tmp0/0
+run/0: trace {name: "a", value: 0, type: 0, properties: ["a": "literal-string"]}, {name: "b", value: 0, type: 0, properties: ["b": "literal-string"]}
+a/0: b
+run/0: instruction main/1
+run/0: trace-should-not-contain {name: "
+    a: b
+  ", value: 0, type: 0, properties: ["
+    a: b
+  ": "literal-string"]}
+warn/0: unexpected [b] in trace layer a
diff --git a/cpp/049scenario_helpers.cc b/cpp/049scenario_helpers.cc
index a2f4db2c..d1d71c99 100644
--- a/cpp/049scenario_helpers.cc
+++ b/cpp/049scenario_helpers.cc
@@ -251,3 +251,62 @@ recipe main [
   ]
 ]
 -warn: missing [b] in trace layer a
+
+:(scenario trace_negative_check_warns_on_failure)
+% Hide_warnings = true;
+recipe main [
+  run [
+    trace [a], [b]
+  ]
+  trace-should-not-contain [
+    a: b
+  ]
+]
++warn: unexpected [b] in trace layer a
+
+:(before "End Primitive Recipe Declarations")
+TRACE_SHOULD_NOT_CONTAIN,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["trace-should-not-contain"] = TRACE_SHOULD_NOT_CONTAIN;
+:(before "End Primitive Recipe Implementations")
+case TRACE_SHOULD_NOT_CONTAIN: {
+  check_trace_missing(current_instruction().ingredients[0].name);
+  break;
+}
+
+:(code)
+// simplified version of check_trace_contents() that emits warnings rather
+// than just printing to stderr
+bool check_trace_missing(const string& in) {
+  Trace_stream->newline();
+  vector<pair<string, string> > lines = parse_trace(in);
+  for (size_t i = 0; i < lines.size(); ++i) {
+    if (trace_count(lines[i].first, lines[i].second) != 0) {
+      raise << "unexpected [" << lines[i].second << "] in trace layer " << lines[i].first << '\n';
+      return false;
+    }
+  }
+  return true;
+}
+
+:(scenario trace_negative_check_passes_silently)
+% Hide_warnings = true;
+recipe main [
+  trace-should-not-contain [
+    a: b
+  ]
+]
+-warn: unexpected [b] in trace layer a
+
+:(scenario trace_negative_check_warns_on_any_unexpected_line)
+% Hide_warnings = true;
+recipe main [
+  run [
+    trace [a], [d]
+  ]
+  trace-should-not-contain [
+    a: b
+    a: d
+  ]
+]
++warn: unexpected [d] in trace layer a