about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/.traces/literal3
-rw-r--r--cpp/.traces/parse3
-rw-r--r--cpp/.traces/parse24
-rw-r--r--cpp/.traces/parse_label1
-rw-r--r--cpp/000test.cc2
-rw-r--r--cpp/001trace.cc12
-rw-r--r--cpp/002main.test.cc8
-rw-r--r--cpp/makefile2
8 files changed, 30 insertions, 5 deletions
diff --git a/cpp/.traces/literal b/cpp/.traces/literal
new file mode 100644
index 00000000..d20319d2
--- /dev/null
+++ b/cpp/.traces/literal
@@ -0,0 +1,3 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "23", type: 0}
+parse/0:   product: {name: "1", type: 1}
diff --git a/cpp/.traces/parse b/cpp/.traces/parse
new file mode 100644
index 00000000..d20319d2
--- /dev/null
+++ b/cpp/.traces/parse
@@ -0,0 +1,3 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "23", type: 0}
+parse/0:   product: {name: "1", type: 1}
diff --git a/cpp/.traces/parse2 b/cpp/.traces/parse2
new file mode 100644
index 00000000..f8d5050e
--- /dev/null
+++ b/cpp/.traces/parse2
@@ -0,0 +1,4 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "23", type: 0}
+parse/0:   product: {name: "1", type: 1}
+parse/0:   product: {name: "2", type: 1}
diff --git a/cpp/.traces/parse_label b/cpp/.traces/parse_label
new file mode 100644
index 00000000..ba16e988
--- /dev/null
+++ b/cpp/.traces/parse_label
@@ -0,0 +1 @@
+parse/0: label: foo
diff --git a/cpp/000test.cc b/cpp/000test.cc
index 2754b254..1a731804 100644
--- a/cpp/000test.cc
+++ b/cpp/000test.cc
@@ -8,6 +8,8 @@ bool Passed = true;
 
 long Num_failures = 0;
 
+#define TEST(name) void test_##name() { Trace_file = #name;
+
 #define CHECK(X) \
   if (!(X)) { \
     ++Num_failures; \
diff --git a/cpp/001trace.cc b/cpp/001trace.cc
index 24416a91..0de7c687 100644
--- a/cpp/001trace.cc
+++ b/cpp/001trace.cc
@@ -86,9 +86,19 @@ ostream& operator<<(ostream& os, unused die) {
 #define DUMP(layer)  cerr << Trace_stream->readable_contents(layer)
 
 // Trace_stream is a resource, lease_tracer uses RAII to manage it.
+string Trace_file;
+static string Trace_dir = ".traces/";
 struct lease_tracer {
   lease_tracer() { Trace_stream = new trace_stream; }
-  ~lease_tracer() { delete Trace_stream, Trace_stream = NULL; }
+  ~lease_tracer() {
+//?     cerr << "write to file? " << Trace_file << "$\n"; //? 1
+    if (!Trace_file.empty()) {
+//?       cerr << "writing\n"; //? 1
+      ofstream fout((Trace_dir+Trace_file).c_str());
+      fout << Trace_stream->readable_contents("");
+      fout.close();
+    }
+    delete Trace_stream, Trace_stream = NULL; Trace_file = ""; }
 };
 
 #define START_TRACING_UNTIL_END_OF_SCOPE  lease_tracer leased_tracer;
diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc
index 2ac6843d..72dbe41f 100644
--- a/cpp/002main.test.cc
+++ b/cpp/002main.test.cc
@@ -1,11 +1,11 @@
-void test_parse() {
+TEST(parse)
   compile("recipe main [\n"
           "  1:integer <- copy 23:literal\n"
           "]\n");
   CHECK_TRACE_CONTENTS("parse", "instruction: 1  ingredient: {name: \"23\", type: 0}  product: {name: \"1\", type: 1}");
 }
 
-void test_parse_label() {
+TEST(parse_label)
   compile("recipe main [\n"
           "  foo:\n"
           "]\n");
@@ -13,14 +13,14 @@ void test_parse_label() {
   CHECK_TRACE_DOESNT_CONTAIN("parse", "instruction: 1");
 }
 
-void test_parse2() {
+TEST(parse2)
   compile("recipe main [\n"
           "  1:integer, 2:integer <- copy 23:literal\n"
           "]\n");
   CHECK_TRACE_CONTENTS("parse", "instruction: 1  ingredient: {name: \"23\", type: 0}  product: {name: \"1\", type: 1}  product: {name: \"2\", type: 1}");
 }
 
-void test_literal() {
+TEST(literal)
   compile("recipe main [\n"
           "  1:integer <- copy 23:literal\n"
           "]\n");
diff --git a/cpp/makefile b/cpp/makefile
index 1c7e1380..0dcdbce5 100644
--- a/cpp/makefile
+++ b/cpp/makefile
@@ -9,6 +9,7 @@ type_list: boot.cc [0-9]*.cc
 function_list: boot.cc [0-9]*.cc
 	@# assumes function decl has space before '{'
 	@grep -h "^[^ #].*) {" [0-9]*.cc |perl -pwe 's/ {.*/;/' > function_list
+	@grep -h "^[[:space:]]*TEST(" [0-9]*.cc |perl -pwe 's/^\s*TEST\((.*)\)$$/void test_$$1();/' >> function_list
 
 file_list: boot.cc [0-9]*.cc
 	@ls [0-9]*.cc |grep -v "\.test\.cc$$" |perl -pwe 's/.*/#include "$$&"/' > file_list
@@ -18,6 +19,7 @@ test_file_list: [0-9]*.test.cc
 
 test_list: [0-9]*.cc
 	@grep -h "^[[:space:]]*void test_" [0-9]*.cc |perl -pwe 's/^\s*void (.*)\(\) {$$/$$1,/' > test_list
+	@grep -h "^[[:space:]]*TEST(" [0-9]*.cc |perl -pwe 's/^\s*TEST\((.*)\)$$/test_$$1,/' >> test_list
 
 clean:
 	rm -rf mu* *_list