/// <summary> /// Tries to find a failure in the section tree of a test case. /// </summary> /// <param name="element"></param> /// <param name="name"></param> void TryGetFailure(Tests.TestCase element, string name) { // Get current level's name. name += element.Name; // Try to find the failure from this element. foreach (var expression in element.Expressions) { // Map the failure to a flat result. if (expression.Success == "false") { string expanded = expression.Expanded.Trim(); string original = expression.Original.Trim(); string type = expression.Type; var res = new FlatResult() { // The path will be expanded by preceding stack frames. SectionPath = name, Expression = $"{type}({original}) with expansion: ({expanded})", LineNumber = Int32.Parse(expression.Line), FilePath = expression.Filename }; result.Add(res); } } // Try to find the failure from a subsection of this element. foreach (var section in element.Sections) { // Try to find a failure in this section. TryGetFailure(section, name + "\n"); } // Check if this element is a failure generated by FAIL(). if (element.Failure != null) { var res = new FlatResult() { SectionPath = name, Expression = $"FAIL({element.Failure.text.Trim()})", LineNumber = Int32.Parse(element.Failure.Line), FilePath = element.Failure.Filename }; result.Add(res); } }
/// <summary> /// Finds a failure in a test case and flattens the section path that leads to it. /// </summary> /// <param name="testCase"></param> /// <returns>A list of all failure found.</returns> List <FlatResult> GetFlatFailure(Tests.TestCase testCase) { result.Clear(); TryGetFailure(testCase, ""); return(result); }