-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-results.cake
143 lines (115 loc) · 4.29 KB
/
test-results.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ***********************************************************************
// Copyright (c) Charlie Poole and contributors.
// Licensed under the MIT License. See LICENSE.txt in root directory.
// ***********************************************************************
// This file contains classes used to interpret the result XML that is
// produced by test runs of the GUI.
public abstract class ResultSummary
{
public string OverallResult { get; set; }
public int Total { get; set; }
public int Passed { get; set; }
public int Failed { get; set; }
public int Warnings { get; set; }
public int Inconclusive { get; set; }
public int Skipped { get; set; }
}
public class ExpectedResult : ResultSummary
{
public ExpectedResult(string overallResult)
{
if (string.IsNullOrEmpty(overallResult))
throw new ArgumentNullException(nameof(overallResult));
OverallResult = overallResult;
// Initialize counters to -1, indicating no expected value.
// Set properties of those items to be checked.
Total = Passed = Failed = Warnings = Inconclusive = Skipped = -1;
}
public ExpectedAssemblyResult[] Assemblies { get; set; } = new ExpectedAssemblyResult[0];
}
public class ExpectedAssemblyResult
{
public ExpectedAssemblyResult(string name, string expectedRuntime)
{
Name = name;
Runtime = expectedRuntime;
}
public string Name { get; }
public string Runtime { get; }
}
public class ActualResult : ResultSummary
{
public ActualResult(string resultFile)
{
var doc = new XmlDocument();
doc.Load(resultFile);
Xml = doc.DocumentElement;
if (Xml.Name != "test-run")
throw new Exception("The test-run element was not found.");
OverallResult = GetAttribute(Xml, "result");
Total = IntAttribute(Xml, "total");
Passed = IntAttribute(Xml, "passed");
Failed = IntAttribute(Xml, "failed");
Warnings = IntAttribute(Xml, "warnings");
Inconclusive = IntAttribute(Xml, "inconclusive");
Skipped = IntAttribute(Xml, "skipped");
var assemblies = new List<ActualAssemblyResult>();
var engineVersion = new Version(GetAttribute(Xml, "engine-version"));
foreach (XmlNode node in Xml.SelectNodes("//test-suite[@type='Assembly']"))
assemblies.Add(new ActualAssemblyResult(node, engineVersion));
Assemblies = assemblies.ToArray();
}
public XmlNode Xml { get; }
public ActualAssemblyResult[] Assemblies { get; }
private string GetAttribute(XmlNode node, string name)
{
return node.Attributes[name]?.Value;
}
private int IntAttribute(XmlNode node, string name)
{
string s = GetAttribute(node, name);
// TODO: We should replace 0 with -1, representing a missing counter
// attribute, after issue #707 is fixed.
return s == null ? 0 : int.Parse(s);
}
}
public class ActualAssemblyResult
{
public ActualAssemblyResult(XmlNode xml, Version engineVersion)
{
Name = xml.Attributes["name"]?.Value;
var env = xml.SelectSingleNode("environment");
var settings = xml.SelectSingleNode("settings");
// If TargetRuntimeFramework setting is not present, the GUI will have crashed anyway
var runtimeSetting = settings.SelectSingleNode("setting[@name='ImageTargetFrameworkName']");
TargetRuntime = runtimeSetting?.Attributes["value"]?.Value;
// Engine 3.10 and earlier doesn't provide enough info
if (engineVersion >= new Version(3,11,0,0))
Runtime = DeduceActualRuntime(xml);
}
public string Name { get; }
public string Runtime { get; }
public string TargetRuntime { get; }
// Code to determine the runtime actually used is adhoc
// and doesn't work for all assemblies because the needed
// information may not be present in the result file.
// TODO: Modify result file schema so this can be cleaner
private static string DeduceActualRuntime(XmlNode assembly)
{
var env = assembly.SelectSingleNode("environment");
// The TargetRuntimeFramework setting is only present
// under the 3.12 and later versions of the engine.
var runtimeSetting = assembly.SelectSingleNode("settings/setting[@name='TargetRuntimeFramework']");
var targetRuntime = runtimeSetting?.Attributes["value"]?.Value;
if (targetRuntime != null)
return targetRuntime;
var clrVersion = env.Attributes["clr-version"]?.Value;
if (clrVersion == null)
return null;
if (clrVersion.StartsWith("2.0"))
return "net-2.0";
if (clrVersion.StartsWith("4.0"))
return "net-4";
return null;
}
}