about summary refs log tree commit diff stats
path: root/tangle
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-17 15:35:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-17 15:35:43 -0700
commitcb159b8c8a888f089676a63273b76b641e860d88 (patch)
treeb0fc8ac0f6e9ffb7522eb5b39f9f9aee439174ac /tangle
parentb2f0954ef99f18ab2bec7b5a5b79cfb29cdc0c1f (diff)
downloadmu-cb159b8c8a888f089676a63273b76b641e860d88.tar.gz
3218
Fix CI. Scenario size_of_shape_shifting_exclusive_container was
triggering undefined behavior in tangle/ and causing things to break in
some compilers but not others.
Diffstat (limited to 'tangle')
-rw-r--r--tangle/003tangle.cc2
-rw-r--r--tangle/003tangle.test.cc12
2 files changed, 14 insertions, 0 deletions
diff --git a/tangle/003tangle.cc b/tangle/003tangle.cc
index ff9aa56e..5cb80b3e 100644
--- a/tangle/003tangle.cc
+++ b/tangle/003tangle.cc
@@ -305,6 +305,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
       result.push_back(Line("  "+front(lines).contents.substr(strlen("% ")), front(lines)));
       lines.pop_front();
     }
+    if (lines.empty()) break;
     result.push_back(input_lines(lines));
     if (!lines.empty() && !front(lines).contents.empty() && front(lines).contents[0] == '+')
       result.push_back(expected_in_trace(lines));
@@ -338,6 +339,7 @@ bool is_input(const string& line) {
 }
 
 Line input_lines(list<Line>& hunk) {
+  assert(!hunk.empty());
   Line result;
   result.line_number = hunk.front().line_number;
   result.filename = hunk.front().filename;
diff --git a/tangle/003tangle.test.cc b/tangle/003tangle.test.cc
index 9c8c4040..45e1f110 100644
--- a/tangle/003tangle.test.cc
+++ b/tangle/003tangle.test.cc
@@ -220,6 +220,18 @@ void test_tangle_can_hide_warnings_in_scenarios() {
   CHECK(lines.empty());
 }
 
+void test_tangle_can_include_c_code_at_end_of_scenario() {
+  istringstream in(":(scenario does_bar)\nabc def\n+layer1: pqr\n+layer2: xyz\n% int x = 1;");
+  list<Line> lines;
+  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, "  int x = 1;");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "}");  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<Line> lines;