Skip to content

Commit e01312a

Browse files
Support latest Windows and macOS versions in OsBrandStringHelper
1 parent 852bb8c commit e01312a

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/BenchmarkDotNet/Environments/OsBrandStringHelper.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,21 @@ public class OsBrandStringHelper
9696
{ "10.0.17763", "10 Redstone 5 [1809, October 2018 Update]" },
9797
{ "10.0.18362", "10 19H1 [1903, May 2019 Update]" },
9898
{ "10.0.18363", "10 19H2 [1909, November 2019 Update]" },
99-
{ "10.0.19041", "10 20H1 [2004, May 2020 Update]" }
99+
{ "10.0.19041", "10 20H1 [2004, May 2020 Update]" },
100+
{ "10.0.19042", "10 20H2 [20H2, October 2020 Update]" }
100101
};
101102

102103
private class Windows10Version
103104
{
104-
private int Version { get; }
105+
private string Version { get; }
105106
[NotNull] private string CodeName { get; }
106107
[NotNull] private string MarketingName { get; }
107108
private int BuildNumber { get; }
108109

109110
[NotNull] private string ShortifiedCodeName => CodeName.Replace(" ", "");
110111
[NotNull] private string ShortifiedMarketingName => MarketingName.Replace(" ", "");
111112

112-
private Windows10Version(int version, [NotNull] string codeName, [NotNull] string marketingName, int buildNumber)
113+
private Windows10Version(string version, [NotNull] string codeName, [NotNull] string marketingName, int buildNumber)
113114
{
114115
Version = version;
115116
CodeName = codeName;
@@ -124,21 +125,24 @@ private string ToFullVersion([CanBeNull] int? ubr = null)
124125
// When people past in on GitHub, it can be a reason of an ugly horizontal scrollbar.
125126
// To avoid this, we are trying to minimize this line and use the minimum possible number of characters.
126127
public string ToPrettifiedString([CanBeNull] int? ubr)
127-
=> $"{ToFullVersion(ubr)} ({Version}/{ShortifiedMarketingName}/{ShortifiedCodeName})";
128+
=> Version == ShortifiedCodeName
129+
? $"{ToFullVersion(ubr)} ({Version}/{ShortifiedMarketingName})"
130+
: $"{ToFullVersion(ubr)} ({Version}/{ShortifiedMarketingName}/{ShortifiedCodeName})";
128131

129132
// See https://en.wikipedia.org/wiki/Windows_10_version_history
130133
private static readonly List<Windows10Version> WellKnownVersions = new List<Windows10Version>
131134
{
132-
new Windows10Version(1507, "Threshold 1", "RTM", 10240),
133-
new Windows10Version(1511, "Threshold 2", "November Update", 10586),
134-
new Windows10Version(1607, "Redstone 1", "Anniversary Update", 14393),
135-
new Windows10Version(1703, "Redstone 2", "Creators Update", 15063),
136-
new Windows10Version(1709, "Redstone 3", "Fall Creators Update", 16299),
137-
new Windows10Version(1803, "Redstone 4", "April 2018 Update", 17134),
138-
new Windows10Version(1809, "Redstone 5", "October 2018 Update", 17763),
139-
new Windows10Version(1903, "19H1", "May 2019 Update", 18362),
140-
new Windows10Version(1909, "19H2", "November 2019 Update", 18363),
141-
new Windows10Version(2004, "20H1", "May 2020 Update", 19041)
135+
new Windows10Version("1507", "Threshold 1", "RTM", 10240),
136+
new Windows10Version("1511", "Threshold 2", "November Update", 10586),
137+
new Windows10Version("1607", "Redstone 1", "Anniversary Update", 14393),
138+
new Windows10Version("1703", "Redstone 2", "Creators Update", 15063),
139+
new Windows10Version("1709", "Redstone 3", "Fall Creators Update", 16299),
140+
new Windows10Version("1803", "Redstone 4", "April 2018 Update", 17134),
141+
new Windows10Version("1809", "Redstone 5", "October 2018 Update", 17763),
142+
new Windows10Version("1903", "19H1", "May 2019 Update", 18362),
143+
new Windows10Version("1909", "19H2", "November 2019 Update", 18363),
144+
new Windows10Version("2004", "20H1", "May 2020 Update", 19041),
145+
new Windows10Version("20H2", "20H2", "October 2020 Update", 19042),
142146
};
143147

144148
[CanBeNull]
@@ -202,7 +206,8 @@ private MacOSXVersion(int darwinVersion, [NotNull] string codeName)
202206
new MacOSXVersion(16, "Sierra"),
203207
new MacOSXVersion(17, "High Sierra"),
204208
new MacOSXVersion(18, "Mojave"),
205-
new MacOSXVersion(19, "Catalina")
209+
new MacOSXVersion(19, "Catalina"),
210+
new MacOSXVersion(20, "Big Sur")
206211
};
207212

208213
[CanBeNull]

tests/BenchmarkDotNet.Tests/Environments/OsBrandStringTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ public void WindowsIsPrettified(string originalVersion, string prettifiedName)
4242
[InlineData("10.0.18362", 693, "Windows 10.0.18362.693 (1903/May2019Update/19H1)")]
4343
[InlineData("10.0.18363", 657, "Windows 10.0.18363.657 (1909/November2019Update/19H2)")]
4444
[InlineData("10.0.19041", 1, "Windows 10.0.19041.1 (2004/May2020Update/20H1)")]
45+
[InlineData("10.0.19042", 746, "Windows 10.0.19042.746 (20H2/October2020Update)")]
4546
public void WindowsWithUbrIsPrettified(string originalVersion, int ubr, string prettifiedName)
4647
=> Check(OsBrandStringHelper.Prettify("Windows", originalVersion, ubr), prettifiedName);
4748

4849
[Theory]
4950
[InlineData("macOS 10.12.6 (16G29)", "Darwin 16.7.0", "macOS Sierra 10.12.6 (16G29) [Darwin 16.7.0]")]
5051
[InlineData("macOS 10.13.4 (17E199)", "Darwin 17.5.0", "macOS High Sierra 10.13.4 (17E199) [Darwin 17.5.0]")]
5152
[InlineData("macOS 10.15.4 (19E266)", "Darwin 19.4.0", "macOS Catalina 10.15.4 (19E266) [Darwin 19.4.0]")]
53+
[InlineData("macOS 11.1 (20C69)", "Darwin 20.2.0", "macOS Big Sur 11.1 (20C69) [Darwin 20.2.0]")]
5254
public void MacOSXIsPrettified(string systemVersion, string kernelVersion, string prettifiedName)
5355
=> Check(OsBrandStringHelper.PrettifyMacOSX(systemVersion, kernelVersion), prettifiedName);
5456
}

0 commit comments

Comments
 (0)