about summary refs log tree commit diff stats
path: root/tangle
diff options
context:
space:
mode:
Diffstat (limited to 'tangle')
-rw-r--r--tangle/003tangle.cc33
-rw-r--r--tangle/003tangle.test.cc55
2 files changed, 65 insertions, 23 deletions
diff --git a/tangle/003tangle.cc b/tangle/003tangle.cc
index 1699e8ce..bc67051a 100644
--- a/tangle/003tangle.cc
+++ b/tangle/003tangle.cc
@@ -311,8 +311,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
     }
     if (lines.empty()) break;
     result.push_back(input_lines(lines));
-    if (!lines.empty() && !front(lines).contents.empty() && front(lines).contents.at(0) == '+')
-      result.push_back(expected_in_trace(lines));
+    emit_expected_in_trace(lines, result);
     while (!lines.empty() && !front(lines).contents.empty() && front(lines).contents.at(0) == '-') {
       result.push_back(expected_not_in_trace(front(lines)));
       lines.pop_front();
@@ -355,17 +354,27 @@ Line input_lines(list<Line>& hunk) {
   return result;
 }
 
-Line expected_in_trace(list<Line>& hunk) {
-  Line result;
-  result.line_number = hunk.front().line_number;
-  result.filename = hunk.front().filename;
-  while (!hunk.empty() && !front(hunk).contents.empty() && front(hunk).contents.at(0) == '+') {
-    hunk.front().contents.erase(0, 1);
-    result.contents += hunk.front().contents+"";
-    hunk.pop_front();
+// pull lines starting with '+' out of 'hunk', and append translated lines to 'out'
+void emit_expected_in_trace(list<Line>& hunk, list<Line>& out) {
+  if (hunk.empty()) return;
+  if (front(hunk).contents.empty()) return;
+  if (front(hunk).contents.at(0) != '+') return;
+  Line curr_out;
+  curr_out.line_number = front(hunk).line_number;
+  curr_out.filename = front(hunk).filename;
+  curr_out.contents = "  CHECK_TRACE_CONTENTS(";
+  out.push_back(curr_out);
+  for (/*nada*/;  !hunk.empty() && front(hunk).contents.at(0) == '+';  hunk.pop_front()) {
+    Line curr_out;
+    curr_out.line_number = front(hunk).line_number;
+    curr_out.filename = front(hunk).filename;
+    curr_out.contents = "      \""+escape(front(hunk).contents.substr(1))+"\"";
+    out.push_back(curr_out);
   }
-  result.contents = "  CHECK_TRACE_CONTENTS(\""+escape(result.contents)+"\");";
-  return result;
+  curr_out.line_number = out.back().line_number;
+  curr_out.filename = out.back().filename;
+  curr_out.contents = "  );";
+  out.push_back(curr_out);
 }
 
 Line expected_not_in_trace(const Line& line) {
diff --git a/tangle/003tangle.test.cc b/tangle/003tangle.test.cc
index 43bc2b1d..606e6fc9 100644
--- a/tangle/003tangle.test.cc
+++ b/tangle/003tangle.test.cc
@@ -364,7 +364,10 @@ void test_tangle_supports_scenarios() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: xyz\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -379,7 +382,10 @@ void test_tangle_ignores_empty_lines_in_scenarios() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: xyz\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -404,7 +410,9 @@ void test_tangle_supports_configurable_toplevel() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  foo(\"abc def\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqr\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 
@@ -423,7 +431,10 @@ void test_tangle_can_hide_warnings_in_scenarios() {
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  Hide_warnings = true;");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: xyz\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -438,7 +449,10 @@ void test_tangle_can_include_c_code_at_end_of_scenario() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: xyz\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  int x = 1;");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
@@ -466,7 +480,10 @@ void test_tangle_supports_strings_in_scenarios() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc \\\"def\\\"\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: \\\"xyz\\\"\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: \\\"xyz\\\"\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -480,7 +497,10 @@ void test_tangle_supports_strings_in_scenarios2() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc \\\"\\\"\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: \\\"\\\"\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: \\\"\\\"\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -495,7 +515,10 @@ void test_tangle_supports_multiline_input_in_scenarios() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n  efg\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: \\\"\\\"\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: \\\"\\\"\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -513,7 +536,10 @@ void test_tangle_supports_reset_in_scenarios() {
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n\");");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  CLEAR_TRACE;");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"efg\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: \\\"\\\"\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer2: \\\"\\\"\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
 }
@@ -526,9 +552,13 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios() {
                    "-layer1: xyz");
   list<Line> lines;
   tangle(in, lines);
+//?   for (list<Line>::iterator p = lines.begin();  p != lines.end();  ++p)
+//?     cerr << p->contents << '\n';
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n  efg\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqr\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  CHECK_TRACE_DOESNT_CONTAIN(\"layer1: xyz\");");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
   CHECK(lines.empty());
@@ -583,7 +613,10 @@ void test_tangle_can_handle_mu_comments_in_scenario() {
   tangle(in, lines);
   CHECK_EQ(lines.front().contents, "void test_does_bar() {");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  run(\"abc def\\n# comment1\\n  efg\\n  # indented comment 2\\n\");");  lines.pop_front();
-  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer1: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_CONTENTS(");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: pqr\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "      \"layer1: xyz\"");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  );");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  CHECK_TRACE_DOESNT_CONTAIN(\"layer1: z\");");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "  CHECK_TRACE_COUNT(\"layer1\", 2);");  lines.pop_front();
   CHECK_EQ(lines.front().contents, "}");  lines.pop_front();