diff options
Diffstat (limited to '050scenario.cc')
-rw-r--r-- | 050scenario.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/050scenario.cc b/050scenario.cc index 29ffc2cb..163d03db 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -552,6 +552,66 @@ recipe main [ ] +warn: unexpected [d] in trace with label a +:(scenario trace_count_check) +recipe main [ + run [ + trace 1, [a], [foo] + ] + check-trace-count-for-label 1, [a] +] + +:(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") +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(); + 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(); + 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(); + break; + } + 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: "; + DUMP(label); + raise; + } + else { + // just testing scenario support + raise << current_recipe_name() << ": expected " << expected_count << " lines in trace with label " << label << " in trace\n" << end(); + } + if (!Scenario_testing_scenario) { + Passed = false; + ++Num_failures; + } + } + break; +} + +:(scenario trace_count_check_2) +% Scenario_testing_scenario = true; +% Hide_warnings = 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 + //: Minor detail: ignore 'system' calls in scenarios, since anything we do //: with them is by definition impossible to test through mu. :(after "case _SYSTEM:") |