From 76755b2836b0dadd88f82635f661f9d9df77604d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 10 Nov 2015 21:35:42 -0800 Subject: 2423 - describe shape-shifting in html docs --- html/050scenario.cc.html | 167 +++++++++++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 71 deletions(-) (limited to 'html/050scenario.cc.html') diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index e6184407..c586b575 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -13,10 +13,10 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .traceContains { color: #008000; } .CommentedCode { color: #6c6c6c; } +.SalientComment { color: #00ffff; } +.cSpecial { color: #008000; } .traceAbsent { color: #c00000; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } @@ -110,8 +110,8 @@ else if (command == " scenario parse_scenario(istream& in) { scenario result; result.name = next_word(in); - if (Scenario_names.find(result.name) != Scenario_names.end()) - raise << "duplicate scenario name: " << result.name << '\n' << end(); + if (contains_key(Scenario_names, result.name)) + raise_error << "duplicate scenario name: " << result.name << '\n' << end(); Scenario_names.insert(result.name); skip_whitespace_and_comments(in); assert(in.peek() == '['); @@ -224,7 +224,11 @@ recipe main [ :(before "End Primitive Recipe Declarations") RUN, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["run"] = RUN; +put(Recipe_ordinal, "run", RUN); +:(before "End Primitive Recipe Checks") +case RUN: { + break; +} :(before "End Primitive Recipe Implementations") case RUN: { ostringstream tmp; @@ -232,6 +236,11 @@ case RUN: { vector<recipe_ordinal> tmp_recipe = load(tmp.str()); bind_special_scenario_names(tmp_recipe.at(0)); transform_all(); + if (Trace_stream) { + ++Trace_stream->callstack_depth; + trace(9998, "trace") << "run: incrementing callstack depth to " << Trace_stream->callstack_depth << end(); + assert(Trace_stream->callstack_depth < 9000); // 9998-101 plus cushion + } Current_routine->calls.push_front(call(tmp_recipe.at(0))); continue; // not done with caller; don't increment current_step_index() } @@ -256,7 +265,7 @@ recipe main [ +mem: storing 13 in location 1 +mem: storing 13 in location 2 -//: 'memory-should-contain' raises warnings if specific locations aren't as expected +//: 'memory-should-contain' raises errors if specific locations aren't as expected //: Also includes some special support for checking strings. :(before "End Globals") @@ -266,19 +275,23 @@ Scenario_testing_scenario = false:(scenario memory_check) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ memory-should-contain [ 1 <- 13 ] ] +run: checking location 1 -+warn: expected location 1 to contain 13 but saw 0 ++error: expected location 1 to contain 13 but saw 0 :(before "End Primitive Recipe Declarations") MEMORY_SHOULD_CONTAIN, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["memory-should-contain"] = MEMORY_SHOULD_CONTAIN; +put(Recipe_ordinal, "memory-should-contain", MEMORY_SHOULD_CONTAIN); +:(before "End Primitive Recipe Checks") +case MEMORY_SHOULD_CONTAIN: { + break; +} :(before "End Primitive Recipe Implementations") case MEMORY_SHOULD_CONTAIN: { if (!Passed) break; @@ -299,22 +312,22 @@ void check_memory(const string& s(lhs, in); continue; } - int address = to_integer(lhs); + long long int address = to_integer(lhs); skip_whitespace_and_comments(in); string _assign; in >> _assign; assert(_assign == "<-"); skip_whitespace_and_comments(in); - int value = 0; in >> value; - if (locations_checked.find(address) != locations_checked.end()) - raise << "duplicate expectation for location " << address << '\n' << end(); - trace(Primitive_recipe_depth, "run") << "checking location " << address << end(); - if (Memory[address] != value) { + double value = 0; in >> value; + if (contains_key(locations_checked, address)) + raise_error << "duplicate expectation for location " << address << '\n' << end(); + trace(9999, "run") << "checking location " << address << end(); + if (get_or_insert(Memory, address) != value) { if (Current_scenario && !Scenario_testing_scenario) { // genuine test in a mu file - raise << "\nF - " << Current_scenario->name << ": expected location " << address << " to contain " << value << " but saw " << Memory[address] << '\n' << end(); + raise_error << "\nF - " << Current_scenario->name << ": expected location " << address << " to contain " << no_scientific(value) << " but saw " << no_scientific(get_or_insert(Memory, address)) << '\n' << end(); } else { // just testing scenario support - raise << "expected location " << address << " to contain " << value << " but saw " << Memory[address] << '\n' << end(); + raise_error << "expected location " << address << " to contain " << no_scientific(value) << " but saw " << no_scientific(get_or_insert(Memory, address)) << '\n' << end(); } if (!Scenario_testing_scenario) { Passed = false; @@ -328,7 +341,7 @@ void check_memory(const string& s(const string& lhs, istream& in) { reagent x(lhs); - if (x.properties.at(0).second.at(0) == "string") { + if (x.properties.at(0).second->value == "string") { x.set_value(to_integer(x.name)); skip_whitespace_and_comments(in); string _assign = next_word(in); @@ -342,16 +355,16 @@ void check_type(const string& lhs(address, literal); return; } - raise << "don't know how to check memory for " << lhs << '\n' << end(); + raise_error << "don't know how to check memory for " << lhs << '\n' << end(); } void check_string(long long int address, const string& literal) { - trace(Primitive_recipe_depth, "run") << "checking string length at " << address << end(); - if (Memory[address] != SIZE(literal)) { + trace(9999, "run") << "checking string length at " << address << end(); + if (get_or_insert(Memory, address) != SIZE(literal)) { if (Current_scenario && !Scenario_testing_scenario) - raise << "\nF - " << Current_scenario->name << ": expected location " << address << " to contain length " << SIZE(literal) << " of string [" << literal << "] but saw " << Memory[address] << '\n' << end(); + raise_error << "\nF - " << Current_scenario->name << ": expected location " << address << " to contain length " << SIZE(literal) << " of string [" << literal << "] but saw " << no_scientific(get_or_insert(Memory, address)) << '\n' << end(); else - raise << "expected location " << address << " to contain length " << SIZE(literal) << " of string [" << literal << "] but saw " << Memory[address] << '\n' << end(); + raise_error << "expected location " << address << " to contain length " << SIZE(literal) << " of string [" << literal << "] but saw " << no_scientific(get_or_insert(Memory, address)) << '\n' << end(); if (!Scenario_testing_scenario) { Passed = false; ++Num_failures; @@ -360,15 +373,15 @@ void check_string(long long int address} ++address; // now skip length for (long long int i = 0; i < SIZE(literal); ++i) { - trace(Primitive_recipe_depth, "run") << "checking location " << address+i << end(); - if (Memory[address+i] != literal.at(i)) { + trace(9999, "run") << "checking location " << address+i << end(); + if (get_or_insert(Memory, address+i) != literal.at(i)) { if (Current_scenario && !Scenario_testing_scenario) { // 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' << end(); + raise_error << "\nF - " << Current_scenario->name << ": expected location " << (address+i) << " to contain " << literal.at(i) << " but saw " << no_scientific(get_or_insert(Memory, address+i)) << '\n' << end(); } else { // just testing scenario support - raise << "expected location " << (address+i) << " to contain " << literal.at(i) << " but saw " << Memory[address+i] << '\n' << end(); + raise_error << "expected location " << (address+i) << " to contain " << literal.at(i) << " but saw " << no_scientific(get_or_insert(Memory, address+i)) << '\n' << end(); } if (!Scenario_testing_scenario) { Passed = false; @@ -381,18 +394,18 @@ void check_string(long long int address:(scenario memory_check_multiple) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ memory-should-contain [ 1 <- 0 1 <- 0 ] ] -+warn: duplicate expectation for location 1 ++error: duplicate expectation for location 1 :(scenario memory_check_string_length) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ 1:number <- copy 3 2:number <- copy 97 # 'a' @@ -402,7 +415,7 @@ recipe main [ 1:string <- [ab] ] ] -+warn: expected location 1 to contain length 2 of string [ab] but saw 3 ++error: expected location 1 to contain length 2 of string [ab] but saw 3 :(scenario memory_check_string) recipe main [ @@ -425,21 +438,25 @@ recipe main [ // that the lines are present *and* in the specified sequence. (There can be // other lines in between.) -:(scenario trace_check_warns_on_failure) +:(scenario trace_check_fails) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ trace-should-contain [ a: b a: d ] ] -+warn: missing [b] in trace with label a ++error: missing [b] in trace with label a :(before "End Primitive Recipe Declarations") TRACE_SHOULD_CONTAIN, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["trace-should-contain"] = TRACE_SHOULD_CONTAIN; +put(Recipe_ordinal, "trace-should-contain", TRACE_SHOULD_CONTAIN); +:(before "End Primitive Recipe Checks") +case TRACE_SHOULD_CONTAIN: { + break; +} :(before "End Primitive Recipe Implementations") case TRACE_SHOULD_CONTAIN: { if (!Passed) break; @@ -448,7 +465,7 @@ case TRACE_SHOULD_CONTAIN: { } :(code) -// simplified version of check_trace_contents() that emits warnings rather +// simplified version of check_trace_contents() that emits errors rather // than just printing to stderr bool check_trace(const string& expected) { Trace_stream->newline(); @@ -465,8 +482,8 @@ bool check_trace(const string& expected} } - raise << "missing [" << expected_lines.at(curr_expected_line).contents << "] " - << "in trace with label " << expected_lines.at(curr_expected_line).label << '\n' << end(); + raise_error << "missing [" << expected_lines.at(curr_expected_line).contents << "] " + << "in trace with label " << expected_lines.at(curr_expected_line).label << '\n' << end(); Passed = false; return false; } @@ -483,9 +500,9 @@ vector<trace_line> parse_trace(const string return result; } -:(scenario trace_check_warns_on_failure_in_later_line) +:(scenario trace_check_fails_in_nonfirst_line) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ run [ trace 1, [a], [b] @@ -495,11 +512,11 @@ recipe main [ a: d ] ] -+warn: missing [d] in trace with label a ++error: missing [d] in trace with label a :(scenario trace_check_passes_silently) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ run [ trace 1, [a], [b] @@ -508,16 +525,16 @@ recipe main [ a: b ] ] --warn: missing [b] in trace with label a -$warn: 0 +-error: missing [b] in trace with label a +$error: 0 //: 'trace-should-not-contain' is like the '-' lines in our scenarios so far //: Each trace line is separately checked for absense. Order is *not* //: important, so you can't say things like "B should not exist after A." -:(scenario trace_negative_check_warns_on_failure) +:(scenario trace_negative_check_fails) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ run [ trace 1, [a], [b] @@ -526,12 +543,16 @@ recipe main [ a: b ] ] -+warn: unexpected [b] in trace with label a ++error: unexpected [b] in trace with label a :(before "End Primitive Recipe Declarations") TRACE_SHOULD_NOT_CONTAIN, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["trace-should-not-contain"] = TRACE_SHOULD_NOT_CONTAIN; +put(Recipe_ordinal, "trace-should-not-contain", TRACE_SHOULD_NOT_CONTAIN); +:(before "End Primitive Recipe Checks") +case TRACE_SHOULD_NOT_CONTAIN: { + break; +} :(before "End Primitive Recipe Implementations") case TRACE_SHOULD_NOT_CONTAIN: { if (!Passed) break; @@ -540,14 +561,14 @@ case TRACE_SHOULD_NOT_CONTAIN: { } :(code) -// simplified version of check_trace_contents() that emits warnings rather +// simplified version of check_trace_contents() that emits errors rather // than just printing to stderr bool check_trace_missing(const string& in) { Trace_stream->newline(); vector<trace_line> lines = parse_trace(in); for (long long int i = 0; i < SIZE(lines); ++i) { if (trace_count(lines.at(i).label, lines.at(i).contents) != 0) { - raise << "unexpected [" << lines.at(i).contents << "] in trace with label " << lines.at(i).label << '\n' << end(); + raise_error << "unexpected [" << lines.at(i).contents << "] in trace with label " << lines.at(i).label << '\n' << end(); Passed = false; return false; } @@ -557,18 +578,18 @@ bool check_trace_missing(const string& in:(scenario trace_negative_check_passes_silently) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ trace-should-not-contain [ a: b ] ] --warn: unexpected [b] in trace with label a -$warn: 0 +-error: unexpected [b] in trace with label a +$error: 0 -:(scenario trace_negative_check_warns_on_any_unexpected_line) +:(scenario trace_negative_check_fails_on_any_unexpected_line) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ run [ trace 1, [a], [d] @@ -578,7 +599,7 @@ recipe main [ a: d ] ] -+warn: unexpected [d] in trace with label a ++error: unexpected [d] in trace with label a :(scenario trace_count_check) recipe main [ @@ -591,35 +612,39 @@ recipe main [ :(before "End Primitive Recipe Declarations") CHECK_TRACE_COUNT_FOR_LABEL, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["check-trace-count-for-label"] = CHECK_TRACE_COUNT_FOR_LABEL; -:(before "End Primitive Recipe Implementations") +put(Recipe_ordinal, "check-trace-count-for-label", CHECK_TRACE_COUNT_FOR_LABEL); +:(before "End Primitive Recipe Checks") case CHECK_TRACE_COUNT_FOR_LABEL: { - if (!Passed) break; - if (SIZE(current_instruction().ingredients) != 2) { - raise << current_recipe_name() << ": 'check-trace-for-label' requires exactly two ingredients, but got '" << current_instruction().to_string() << "'\n" << end(); + if (SIZE(inst.ingredients) != 2) { + raise_error << maybe(get(Recipe, r).name) << "'check-trace-for-label' requires exactly two ingredients, but got '" << inst.to_string() << "'\n" << end(); break; } - if (!scalar(ingredients.at(0))) { - raise << current_recipe_name() << ": first ingredient of 'check-trace-for-label' should be a number (count), but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); + if (!is_mu_number(inst.ingredients.at(0))) { + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'check-trace-for-label' should be a number (count), but got " << inst.ingredients.at(0).original_string << '\n' << end(); break; } - long long int expected_count = ingredients.at(0).at(0); - if (!is_literal_string(current_instruction().ingredients.at(1))) { - raise << current_recipe_name() << ": second ingredient of 'check-trace-for-label' should be a literal string (label), but got " << current_instruction().ingredients.at(1).original_string << '\n' << end(); + if (!is_literal_string(inst.ingredients.at(1))) { + raise_error << maybe(get(Recipe, r).name) << "second ingredient of 'check-trace-for-label' should be a literal string (label), but got " << inst.ingredients.at(1).original_string << '\n' << end(); break; } + break; +} +:(before "End Primitive Recipe Implementations") +case CHECK_TRACE_COUNT_FOR_LABEL: { + if (!Passed) break; + long long int expected_count = ingredients.at(0).at(0); string label = current_instruction().ingredients.at(1).name; long long int count = trace_count(label); if (count != expected_count) { if (Current_scenario && !Scenario_testing_scenario) { // genuine test in a mu file - raise << "\nF - " << Current_scenario->name << ": " << current_recipe_name() << ": expected " << expected_count << " lines in trace with label " << label << " in trace: "; + raise_error << "\nF - " << Current_scenario->name << ": " << maybe(current_recipe_name()) << "expected " << expected_count << " lines in trace with label " << label << " in trace: "; DUMP(label); - raise; + raise_error; } else { // just testing scenario support - raise << current_recipe_name() << ": expected " << expected_count << " lines in trace with label " << label << " in trace\n" << end(); + raise_error << maybe(current_recipe_name()) << "expected " << expected_count << " lines in trace with label " << label << " in trace\n" << end(); } if (!Scenario_testing_scenario) { Passed = false; @@ -631,14 +656,14 @@ case CHECK_TRACE_COUNT_FOR_LABEL: { :(scenario trace_count_check_2) % Scenario_testing_scenario = true; -% Hide_warnings = true; +% Hide_errors = true; recipe main [ run [ trace 1, [a], [foo] ] check-trace-count-for-label 2, [a] ] -+warn: main: expected 2 lines in trace with label a in trace ++error: main: expected 2 lines in trace with label a in trace //: Minor detail: ignore 'system' calls in scenarios, since anything we do //: with them is by definition impossible to test through mu. -- cgit 1.4.1-2-gfad0