[xharness] Improve html report by formatting newlines and tabs in test failure messages using corresponding html tags. (#3627)

* [xharness] Improve html report by formatting newlines and tabs in test failure messages using corresponding html tags.

* [xharness] Improve nunit test reporting in html report by creating a list of failures.
This commit is contained in:
Rolf Bjarne Kvinge 2018-03-01 17:20:19 +01:00 коммит произвёл GitHub
Родитель ca4360116c
Коммит 6c1bdea375
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -2000,21 +2000,25 @@ function oninitialload ()
var failures = doc.SelectNodes ("//test-case[@result='Error' or @result='Failure']").Cast<System.Xml.XmlNode> ().ToArray (); var failures = doc.SelectNodes ("//test-case[@result='Error' or @result='Failure']").Cast<System.Xml.XmlNode> ().ToArray ();
if (failures.Length > 0) { if (failures.Length > 0) {
writer.WriteLine ("<div style='padding-left: 15px;'>"); writer.WriteLine ("<div style='padding-left: 15px;'>");
writer.WriteLine ("<ul>");
foreach (var failure in failures) { foreach (var failure in failures) {
writer.WriteLine ("<li>");
var test_name = failure.Attributes ["name"]?.Value; var test_name = failure.Attributes ["name"]?.Value;
var message = failure.SelectSingleNode ("failure/message")?.InnerText; var message = failure.SelectSingleNode ("failure/message")?.InnerText;
writer.Write (System.Web.HttpUtility.HtmlEncode (test_name)); writer.Write (System.Web.HttpUtility.HtmlEncode (test_name));
if (!string.IsNullOrEmpty (message)) { if (!string.IsNullOrEmpty (message)) {
writer.Write (": "); writer.Write (": ");
writer.Write (System.Web.HttpUtility.HtmlEncode (message)); writer.Write (HtmlFormat (message));
} }
writer.WriteLine ("<br />"); writer.WriteLine ("<br />");
writer.WriteLine ("</li>");
} }
writer.WriteLine ("</ul>");
writer.WriteLine ("</div>"); writer.WriteLine ("</div>");
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
writer.WriteLine ($"<span style='padding-left: 15px;'>Could not parse {log.Description}: {System.Web.HttpUtility.HtmlEncode (ex.Message)}</span><br />"); writer.WriteLine ($"<span style='padding-left: 15px;'>Could not parse {log.Description}: {HtmlFormat (ex.Message)}</span><br />");
} }
} }
} }
@ -2035,6 +2039,12 @@ function oninitialload ()
} }
Dictionary<Log, Tuple<long, object>> log_data = new Dictionary<Log, Tuple<long, object>> (); Dictionary<Log, Tuple<long, object>> log_data = new Dictionary<Log, Tuple<long, object>> ();
static string HtmlFormat (string value)
{
var rv = System.Web.HttpUtility.HtmlEncode (value);
return rv.Replace ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").Replace ("\n", "<br/>\n");
}
static string LinkEncode (string path) static string LinkEncode (string path)
{ {
return System.Web.HttpUtility.UrlEncode (path).Replace ("%2f", "/").Replace ("+", "%20"); return System.Web.HttpUtility.UrlEncode (path).Replace ("%2f", "/").Replace ("+", "%20");