diff options
-rw-r--r-- | 003trace.cc | 10 | ||||
-rw-r--r-- | tangle/030tangle.cc | 3 | ||||
-rw-r--r-- | tangle/030tangle.test.cc | 39 |
3 files changed, 33 insertions, 19 deletions
diff --git a/003trace.cc b/003trace.cc index 76f3207f..8db6f54d 100644 --- a/003trace.cc +++ b/003trace.cc @@ -179,9 +179,12 @@ ostream& operator<<(ostream& os, unused die) { #define DUMP(layer) if (Trace_stream) cerr << Trace_stream->readable_contents(layer); -// Trace_stream is a resource, lease_tracer uses RAII to manage it. -string Trace_file; +// All scenarios save their traces in the repo, just like code. This gives +// future readers more meat when they try to make sense of a new project. static string Trace_dir = ".traces/"; +string Trace_file; + +// Trace_stream is a resource, lease_tracer uses RAII to manage it. struct lease_tracer { lease_tracer() { Trace_stream = new trace_stream; } ~lease_tracer() { @@ -196,9 +199,6 @@ struct lease_tracer { } }; -// To transparently save traces, start tests with the TEST() macro. -#define TEST(name) void test_##name() { Trace_file = #name; - #define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer; :(before "End Test Setup") START_TRACING_UNTIL_END_OF_SCOPE diff --git a/tangle/030tangle.cc b/tangle/030tangle.cc index 4949808a..57a10a9e 100644 --- a/tangle/030tangle.cc +++ b/tangle/030tangle.cc @@ -299,7 +299,8 @@ list<Line>::iterator balancing_curly(list<Line>::iterator curr) { // a directive to print the trace just for debugging ('?') // Remember to update is_input below if you add to this format. void emit_test(const string& name, list<Line>& lines, list<Line>& result) { - result.push_back(Line("TEST("+name+")", front(lines).filename, front(lines).line_number-1)); // use line number of directive + result.push_back(Line("void test_"+name+"() {", front(lines).filename, front(lines).line_number-1)); // use line number of directive + result.push_back(Line(" Trace_file = \""+name+"\";", front(lines).filename, front(lines).line_number-1)); while (!lines.empty()) { while (!lines.empty() && starts_with(front(lines).contents, "% ")) { result.push_back(Line(" "+front(lines).contents.substr(strlen("% ")), front(lines))); diff --git a/tangle/030tangle.test.cc b/tangle/030tangle.test.cc index cee0ac83..d44a408a 100644 --- a/tangle/030tangle.test.cc +++ b/tangle/030tangle.test.cc @@ -170,7 +170,8 @@ void test_tangle_supports_scenarios() { istringstream in(":(scenario does_bar)\nabc def\n+layer1: pqr\n+layer2: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -181,7 +182,8 @@ void test_tangle_ignores_empty_lines_in_scenarios() { istringstream in(":(scenario does_bar)\nabc def\n+layer1: pqr\n \n+layer2: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -199,7 +201,8 @@ void test_tangle_supports_configurable_toplevel() { istringstream in(":(scenarios foo)\n:(scenario does_bar)\nabc def\n+layer1: pqr"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -213,7 +216,8 @@ void test_tangle_can_hide_warnings_in_scenarios() { istringstream in(":(scenario does_bar)\n% Hide_warnings = true;\nabc def\n+layer1: pqr\n+layer2: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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(); @@ -225,7 +229,8 @@ void test_tangle_can_handle_in_scenarios() { istringstream in(":(scenario does_bar)\n% Hide_warnings = true;\nabc def\n+layer1: pqr\n+layer2: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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(); @@ -237,7 +242,8 @@ void test_tangle_supports_strings_in_scenarios() { istringstream in(":(scenario does_bar)\nabc \"def\"\n+layer1: pqr\n+layer2: \"xyz\""); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -248,7 +254,8 @@ void test_tangle_supports_strings_in_scenarios2() { istringstream in(":(scenario does_bar)\nabc \"\"\n+layer1: pqr\n+layer2: \"\""); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -259,7 +266,8 @@ void test_tangle_supports_multiline_input_in_scenarios() { istringstream in(":(scenario does_bar)\nabc def\n efg\n+layer1: pqr\n+layer2: \"\""); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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, "}"); lines.pop_front(); @@ -270,7 +278,8 @@ void test_tangle_supports_reset_in_scenarios() { istringstream in(":(scenario does_bar)\nabc def\n===\nefg\n+layer1: pqr\n+layer2: \"\""); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"does_bar\";"); lines.pop_front(); 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(); @@ -283,7 +292,8 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios() { istringstream in(":(scenario does_bar)\nabc def\n efg\n+layer1: pqr\n-layer1: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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_DOESNT_CONTAIN(\"layer1: xyz\");"); lines.pop_front(); @@ -295,7 +305,8 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios2() { istringstream in(":(scenario does_bar)\nabc def\n efg\n-layer1: pqr\n-layer1: xyz"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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_DOESNT_CONTAIN(\"layer1: pqr\");"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_DOESNT_CONTAIN(\"layer1: xyz\");"); lines.pop_front(); @@ -307,7 +318,8 @@ void test_tangle_can_check_for_count_in_scenario() { istringstream in(":(scenario does_bar)\nabc def\n efg\n$layer1: 2"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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_EQ(trace_count(\"layer1\"), 2);"); lines.pop_front(); CHECK_EQ(lines.front().contents, "}"); lines.pop_front(); @@ -318,7 +330,8 @@ void test_tangle_can_handle_mu_comments_in_scenario() { istringstream in(":(scenario does_bar)\nabc def\n# comment1\n efg\n # indented comment 2\n+layer1: pqr\n# comment inside expected_trace\n+layer1: xyz\n# comment after expected trace\n-layer1: z\n# comment before trace count\n$layer1: 2\n# comment at end\n\n"); list<Line> lines; tangle(in, lines); - CHECK_EQ(lines.front().contents, "TEST(does_bar)"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " Trace_file = \"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_DOESNT_CONTAIN(\"layer1: z\");"); lines.pop_front(); |