about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/tangle/030tangle.cc9
-rw-r--r--cpp/tangle/030tangle.test.cc14
2 files changed, 23 insertions, 0 deletions
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index fc40880f..bbd0e178 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -233,6 +233,11 @@ void emit_test(const string& name, list<string>& lines, list<string>& result) {
       result.push_back("  Hide_warnings = true;");
       lines.pop_front();
     }
+    if (starts_with(lines.front(), "dump ")) {
+      string line = lines.front().substr(strlen("dump "));
+      result.push_back("  Trace_stream->dump_layer = \""+line+"\";");
+      lines.pop_front();
+    }
     result.push_back("  "+Toplevel+"(\""+input_lines(lines)+"\");");
     if (!lines.empty() && lines.front()[0] == '+')
       result.push_back("  CHECK_TRACE_CONTENTS(\""+expected_in_trace(lines)+"\");");
@@ -268,6 +273,10 @@ bool is_warn(const string& line) {
   return line == "hide warnings";
 }
 
+bool is_dump(const string& line) {
+  return starts_with(line, "dump ");
+}
+
 string input_lines(list<string>& hunk) {
   string result;
   while (!hunk.empty() && is_input(hunk.front())) {
diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc
index 3f86fdb8..bdf24a5c 100644
--- a/cpp/tangle/030tangle.test.cc
+++ b/cpp/tangle/030tangle.test.cc
@@ -196,6 +196,20 @@ void test_tangle_can_hide_warnings_in_scenarios() {
   CHECK(lines.empty());
 }
 
+void test_tangle_can_dump_traces_in_scenarios() {
+  istringstream in(":(scenario does_bar)\ndump foo\nabc def\n+layer1: pqr\n+layer2: xyz");
+  list<string> lines;
+  tangle(in, lines);
+  CHECK_EQ(lines.front(), "#line 1");  lines.pop_front();
+  CHECK_EQ(lines.front(), "#line 2");  lines.pop_front();
+  CHECK_EQ(lines.front(), "TEST(does_bar)");  lines.pop_front();
+  CHECK_EQ(lines.front(), "  Trace_stream->dump_layer = \"foo\";");  lines.pop_front();
+  CHECK_EQ(lines.front(), "  run(\"abc def\\n\");");  lines.pop_front();
+  CHECK_EQ(lines.front(), "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front(), "}");  lines.pop_front();
+  CHECK(lines.empty());
+}
+
 void test_tangle_supports_strings_in_scenarios() {
   istringstream in(":(scenario does_bar)\nabc \"def\"\n+layer1: pqr\n+layer2: \"xyz\"");
   list<string> lines;
/* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
discard """
  output: ""
  targets: "c"
"""

# bug #9594

type
  Foo = object
    i: int

proc `=`(self: var Foo; other: Foo) =
  self.i = other.i + 1

proc `=sink`(self: var Foo; other: Foo) =
  self.i = other.i

proc `=destroy`(self: var Foo) = discard

template preventCursorInference(x) =
  let p = addr(x)

proc test(): Foo =
  result = Foo()
  let temp = result
  preventCursorInference temp
  doAssert temp.i > 0
  return result

proc testB(): Foo =
  result = Foo()
  let temp = result
  preventCursorInference temp
  doAssert temp.i > 0

discard test()
discard testB()