From 4bbd3ded0b767ae0919551776e4c17189140e735 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 30 May 2015 19:30:33 -0700 Subject: 1517 --- html/050scenario.cc.html | 95 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 22 deletions(-) (limited to 'html/050scenario.cc.html') diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index fa3c0d55..92d38825 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -10,19 +10,19 @@ @@ -107,15 +107,30 @@ else if (command == " :(code) scenario parse_scenario(istream& in) { +//? cerr << "parse scenario\n"; //? 1 scenario result; result.name = next_word(in); - skip_bracket(in, "'scenario' must begin with '['"); - ostringstream buffer; - slurp_until_matching_bracket(in, buffer); - result.to_run = buffer.str(); + skip_whitespace_and_comments(in); + assert(in.peek() == '['); + // scenarios are take special 'code' strings so we need to ignore brackets + // inside comments + result.to_run = slurp_quoted_ignoring_comments(in); return result; } +:(scenario read_scenario_with_bracket_in_comment) +scenario foo [ + # ']' in comment + 1:number <- copy 0:literal +] ++run: 1:number <- copy 0:literal + +:(scenario read_scenario_with_bracket_in_comment_in_nested_string) +scenario foo [ + 1:address:array:character <- new [# not a comment] +] ++run: 1:address:array:character <- new [# not a comment] + //:: Run scenarios when we run 'mu test'. //: Treat the text of the scenario as a regular series of instructions. @@ -124,7 +139,7 @@ time_t mu_time; time("\nMu tests: " << ctime(&mu_time); for (long long int i = 0; i < SIZE(Scenarios); ++i) { //? cerr << Passed << '\n'; //? 1 -//? cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 3 +//? cerr << i << ": " << Scenarios.at(i).name << '\n'; //? 5 run_mu_scenario(Scenarios.at(i)); if (Passed) cerr << "."; } @@ -151,6 +166,7 @@ void run_mu_scenario(const scenario& s; setup(); } +//? cerr << '^' << s.to_run << "$\n"; //? 1 run("recipe "+s.name+" [ " + s.to_run + " ]"); if (not_already_inside_test && Trace_stream) { teardown(); @@ -229,6 +245,7 @@ MEMORY_SHOULD_CONTAIN, Recipe_number["memory-should-contain"] = MEMORY_SHOULD_CONTAIN; :(before "End Primitive Recipe Implementations") case MEMORY_SHOULD_CONTAIN: { + if (!Passed) break; //? cout << current_instruction().ingredients.at(0).name << '\n'; //? 1 check_memory(current_instruction().ingredients.at(0).name); break; @@ -256,11 +273,18 @@ void check_memory(const string& s"duplicate expectation for location " << address << '\n'; trace(Primitive_recipe_depth, "run") << "checking location " << address; if (Memory[address] != value) { - if (Current_scenario) + if (Current_scenario && !Hide_warnings) { + // genuine test in a mu file raise << "\nF - " << Current_scenario->name << ": expected location " << address << " to contain " << value << " but saw " << Memory[address] << '\n'; - else + } + else { + // just testing scenario support raise << "expected location " << address << " to contain " << value << " but saw " << Memory[address] << '\n'; - Passed = false; + } + if (!Hide_warnings) { + Passed = false; + ++Num_failures; + } return; } locations_checked.insert(address); @@ -303,10 +327,14 @@ void check_string(long long int address(long long int i = 0; i < SIZE(literal); ++i) { trace(Primitive_recipe_depth, "run") << "checking location " << address+i; if (Memory[address+i] != literal.at(i)) { - if (Current_scenario && !Hide_warnings) + if (Current_scenario && !Hide_warnings) { + // genuine test in a mu file raise << "\nF - " << Current_scenario->name << ": expected location " << (address+i) << " to contain " << literal.at(i) << " but saw " << Memory[address+i] << '\n'; - else + } + else { + // just testing scenario support raise << "expected location " << (address+i) << " to contain " << literal.at(i) << " but saw " << Memory[address+i] << '\n'; + } if (!Hide_warnings) { Passed = false; ++Num_failures; @@ -380,6 +408,7 @@ TRACE_SHOULD_CONTAIN, Recipe_number["trace-should-contain"] = TRACE_SHOULD_CONTAIN; :(before "End Primitive Recipe Implementations") case TRACE_SHOULD_CONTAIN: { + if (!Passed) break; check_trace(current_instruction().ingredients.at(0).name); break; } @@ -470,6 +499,7 @@ TRACE_SHOULD_NOT_CONTAIN, Recipe_number["trace-should-not-contain"] = TRACE_SHOULD_NOT_CONTAIN; :(before "End Primitive Recipe Implementations") case TRACE_SHOULD_NOT_CONTAIN: { + if (!Passed) break; check_trace_missing(current_instruction().ingredients.at(0).name); break; } @@ -517,24 +547,45 @@ recipe main [ :(code) // just for the scenarios running scenarios in C++ layers void run_mu_scenario(const string& form) { +//? cerr << form << '\n'; //? 1 istringstream in(form); in >> std::noskipws; + skip_whitespace_and_comments(in); string _scenario = next_word(in); -//? cout << _scenario << '\n'; //? 1 +//? cout << _scenario << '\n'; //? 2 assert(_scenario == "scenario"); scenario s = parse_scenario(in); run_mu_scenario(s); } -void slurp_until_matching_bracket(istream& in, ostream& out) { - int brace_depth = 1; // just scanned '[' +string slurp_quoted_ignoring_comments(istream& in) { + assert(in.get() == '['); // drop initial '[' char c; + ostringstream out; while (in >> c) { - if (c == '[') ++brace_depth; - if (c == ']') --brace_depth; - if (brace_depth == 0) break; // drop final ']' +//? cerr << c << '\n'; //? 3 + if (c == '#') { + // skip comment + in.putback(c); + skip_comment(in); + continue; + } + if (c == '[') { + // nested strings won't detect comments + // can't yet handle scenarios inside strings inside scenarios.. + in.putback(c); + out << slurp_quoted(in); +//? cerr << "snapshot: ^" << out.str() << "$\n"; //? 1 + continue; + } + if (c == ']') { + // must be at the outermost level; drop final ']' + break; + } out << c; } +//? cerr << "done\n"; //? 2 + return out.str(); } -- cgit 1.4.1-2-gfad0