Skip to content

Commit 634cc1e

Browse files
authored
Fix OperatingSystemTest.TestIsOSPlatform_MacCatalyst (#84842)
It got broken by 3d160bc because the assert wasn't updated. Changed the code to verify the iOS/Catalyst conditions explicitly so this doesn't happen again.
1 parent 5100b5b commit 634cc1e

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/libraries/System.Runtime.Extensions/tests/System/OperatingSystemTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Collections.Generic;
45
using Xunit;
56

67
namespace System.Tests
@@ -187,40 +188,39 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
187188

188189
Assert.True(currentOSCheck());
189190

190-
bool[] allResults = new bool[]
191+
Dictionary<string, bool> allResults = new()
191192
{
192-
OperatingSystem.IsBrowser(),
193-
OperatingSystem.IsLinux(),
194-
OperatingSystem.IsFreeBSD(),
195-
OperatingSystem.IsAndroid(),
196-
OperatingSystem.IsIOS(),
197-
OperatingSystem.IsMacCatalyst(),
198-
OperatingSystem.IsMacOS(),
199-
OperatingSystem.IsTvOS(),
200-
OperatingSystem.IsWatchOS(),
201-
OperatingSystem.IsWindows(),
202-
OperatingSystem.IsWasi(),
193+
{ "IsBrowser", OperatingSystem.IsBrowser() },
194+
{ "IsLinux", OperatingSystem.IsLinux() },
195+
{ "IsFreeBSD", OperatingSystem.IsFreeBSD() },
196+
{ "IsAndroid", OperatingSystem.IsAndroid() },
197+
{ "IsIOS", OperatingSystem.IsIOS() },
198+
{ "IsMacCatalyst", OperatingSystem.IsMacCatalyst() },
199+
{ "IsMacOS", OperatingSystem.IsMacOS() },
200+
{ "IsTvOS", OperatingSystem.IsTvOS() },
201+
{ "IsWatchOS", OperatingSystem.IsWatchOS() },
202+
{ "IsWindows", OperatingSystem.IsWindows() },
203+
{ "IsWasi", OperatingSystem.IsWasi() },
203204
};
204205

205206
// MacCatalyst is a special case since it also returns true for iOS
206207
if (currentOSName == "MacCatalyst")
207208
{
208-
Assert.Equal(10, allResults.Length);
209-
Assert.False(allResults[0]); // IsBrowser()
210-
Assert.False(allResults[1]); // IsLinux()
211-
Assert.False(allResults[2]); // IsFreeBSD()
212-
Assert.False(allResults[3]); // IsAndroid()
213-
Assert.True(allResults[4]); // IsIOS()
214-
Assert.True(allResults[5]); // IsMacCatalyst()
215-
Assert.False(allResults[6]); // IsMacOS()
216-
Assert.False(allResults[7]); // IsTvOS()
217-
Assert.False(allResults[8]); // IsWatchOS()
218-
Assert.False(allResults[9]); // IsWindows()
219-
Assert.False(allResults[10]); // IsWasi()
209+
foreach (var result in allResults)
210+
{
211+
if (result.Key == "IsMacCatalyst" || result.Key == "IsIOS")
212+
{
213+
Assert.True(result.Value);
214+
}
215+
else
216+
{
217+
Assert.False(result.Value);
218+
}
219+
}
220220
}
221221
else
222222
{
223-
Assert.Single(allResults, true);
223+
Assert.Single(allResults.Values, true);
224224
}
225225
}
226226

0 commit comments

Comments
 (0)