diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-02-17 13:43:48 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-02-17 13:43:48 -0800 |
commit | 6a2dabe3675cc5d9f03587e1bf4fb8c7a61bafea (patch) | |
tree | 2cecad02e09ef4a35d9d27f3c95840b7b12e4778 | |
parent | 0c0eee435482df5e58634cf7d26e3016bba4cf12 (diff) | |
download | mu-6a2dabe3675cc5d9f03587e1bf4fb8c7a61bafea.tar.gz |
773 - start testing traces
-rw-r--r-- | cpp/001trace.cc | 3 | ||||
-rw-r--r-- | cpp/002main.cc | 2 | ||||
-rw-r--r-- | cpp/002main.test.cc | 51 |
3 files changed, 8 insertions, 48 deletions
diff --git a/cpp/001trace.cc b/cpp/001trace.cc index 8b69cc84..24416a91 100644 --- a/cpp/001trace.cc +++ b/cpp/001trace.cc @@ -168,6 +168,7 @@ void parse_layer_and_frame(const string& orig, string* layer, string* frame) { bool check_trace_contents(string FUNCTION, string FILE, int LINE, string layer, string expected) { // empty layer == everything, multiple layers, hierarchical layers vector<string> expected_lines = split(expected, ""); +//? cout << "aa check2 " << layer << ": " << expected_lines.size() << '\n'; //? 1 size_t curr_expected_line = 0; while (curr_expected_line < expected_lines.size() && expected_lines[curr_expected_line].empty()) ++curr_expected_line; @@ -178,6 +179,8 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string layer, for (vector<pair<string, pair<int, string> > >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { if (!layer.empty() && !any_prefix_match(layers, p->first)) continue; +//? cout << "comparing " << p->second.second << '\n'; //? 1 +//? cout << " with " << expected_lines[curr_expected_line] << '\n'; //? 1 if (p->second.second != expected_lines[curr_expected_line]) continue; ++curr_expected_line; diff --git a/cpp/002main.cc b/cpp/002main.cc index ec03cf45..51359a82 100644 --- a/cpp/002main.cc +++ b/cpp/002main.cc @@ -120,7 +120,7 @@ struct reagent { } string to_string() { ostringstream out; - out << "{name: \"" << name << "\", type: " << types[0] << "}\n"; // todo: properties + out << "{name: \"" << name << "\", type: " << types[0] << "}"; // todo: properties return out.str(); } }; diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc index cc14762a..2ac6843d 100644 --- a/cpp/002main.test.cc +++ b/cpp/002main.test.cc @@ -2,65 +2,22 @@ void test_parse() { compile("recipe main [\n" " 1:integer <- copy 23:literal\n" "]\n"); - cout << '\n'; DUMP("parse"); - CHECK(Recipe_number.find("main") != Recipe_number.end()); - recipe r = Recipe[Recipe_number["main"]]; - vector<instruction>::iterator i = r.step.begin(); - CHECK_EQ(i->is_label, false); - CHECK_EQ(i->label, ""); - CHECK_EQ(i->operation, Recipe_number["copy"]); - CHECK_EQ(i->ingredients.size(), 1); - CHECK_EQ(i->ingredients[0].name, string("23")); - CHECK_EQ(i->ingredients[0].types.size(), 1); - CHECK_EQ(i->ingredients[0].types[0], Type_number["literal"]); - CHECK_EQ(i->ingredients[0].properties.size(), 0); - CHECK_EQ(i->products.size(), 1); - CHECK_EQ(i->products[0].name, string("1")); - CHECK_EQ(i->products[0].types.size(), 1); - CHECK_EQ(i->products[0].types[0], Type_number["integer"]); - CHECK_EQ(i->products[0].properties.size(), 0); + CHECK_TRACE_CONTENTS("parse", "instruction: 1 ingredient: {name: \"23\", type: 0} product: {name: \"1\", type: 1}"); } void test_parse_label() { compile("recipe main [\n" " foo:\n" "]\n"); - cout << '\n'; DUMP("parse"); - CHECK(Recipe_number.find("main") != Recipe_number.end()); - recipe r = Recipe[Recipe_number["main"]]; - vector<instruction>::iterator i = r.step.begin(); - CHECK_EQ(i->is_label, true); - CHECK_EQ(i->label, string("foo")); - CHECK_EQ(i->operation, 0); - CHECK_EQ(i->ingredients.size(), 0); - CHECK_EQ(i->products.size(), 0); + CHECK_TRACE_CONTENTS("parse", "label: foo"); + CHECK_TRACE_DOESNT_CONTAIN("parse", "instruction: 1"); } void test_parse2() { compile("recipe main [\n" " 1:integer, 2:integer <- copy 23:literal\n" "]\n"); - cout << '\n'; DUMP("parse"); - CHECK(Recipe_number.find("main") != Recipe_number.end()); - recipe r = Recipe[Recipe_number["main"]]; - vector<instruction>::iterator i = r.step.begin(); - CHECK_EQ(i->is_label, false); - CHECK_EQ(i->label, ""); - CHECK_EQ(i->operation, Recipe_number["copy"]); - CHECK_EQ(i->ingredients.size(), 1); - CHECK_EQ(i->ingredients[0].name, string("23")); - CHECK_EQ(i->ingredients[0].types.size(), 1); - CHECK_EQ(i->ingredients[0].types[0], Type_number["literal"]); - CHECK_EQ(i->ingredients[0].properties.size(), 0); - CHECK_EQ(i->products.size(), 2); - CHECK_EQ(i->products[0].name, string("1")); - CHECK_EQ(i->products[0].types.size(), 1); - CHECK_EQ(i->products[0].types[0], Type_number["integer"]); - CHECK_EQ(i->products[0].properties.size(), 0); - CHECK_EQ(i->products[1].name, string("2")); - CHECK_EQ(i->products[1].types.size(), 1); - CHECK_EQ(i->products[1].types[0], Type_number["integer"]); - CHECK_EQ(i->products[1].properties.size(), 0); + CHECK_TRACE_CONTENTS("parse", "instruction: 1 ingredient: {name: \"23\", type: 0} product: {name: \"1\", type: 1} product: {name: \"2\", type: 1}"); } void test_literal() { |