This repository was archived by the owner on Jul 18, 2024. It is now read-only.
forked from JetBrains/teamcity-csharp-interactive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuildStatistics.cs
78 lines (69 loc) · 2.01 KB
/
BuildStatistics.cs
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
namespace HostApi;
using System.Text;
[ExcludeFromCodeCoverage]
[Target]
public record BuildStatistics(
int Errors = default,
int Warnings = default,
int Tests = default,
int FailedTests = default,
int IgnoredTests = default,
int PassedTests = default)
{
public bool IsEmpty =>
Errors == 0
&& Warnings == 0
&& Tests == 0
&& FailedTests == 0
&& IgnoredTests == 0
&& PassedTests == 0;
public override string ToString()
{
if (IsEmpty)
{
return "Empty";
}
var sb = new StringBuilder();
var initialLength = sb.Length;
AddValue(sb, GetName("error", Errors), Errors, initialLength);
AddValue(sb, GetName("warning", Warnings), Warnings, initialLength);
// ReSharper disable once InvertIf
if (Tests > 0)
{
if (sb.Length > 0)
{
sb.Append(" and ");
}
sb.Append(Tests);
sb.Append(" finished ");
sb.Append(GetName("test", Tests));
// ReSharper disable once InvertIf
if (FailedTests > 0 || IgnoredTests > 0 || PassedTests > 0)
{
sb.Append(": ");
initialLength = sb.Length;
AddValue(sb, "failed", FailedTests, initialLength);
AddValue(sb, "ignored", IgnoredTests, initialLength);
AddValue(sb, "passed", PassedTests, initialLength);
}
}
return sb.ToString();
}
private static void AddValue(StringBuilder sb, string name, int value, int initialLength)
{
if (value <= 0) return;
if (sb.Length > initialLength)
{
sb.Append(", ");
}
sb.Append(value);
sb.Append(' ');
sb.Append(name);
}
private static string GetName(string baseName, int count) =>
count switch
{
1 => baseName,
_ => baseName + 's'
};
}