Skip to content

Commit

Permalink
Fix OperatingSystemTest.TestIsOSPlatform_MacCatalyst (#84842)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akoeplinger authored Apr 18, 2023
1 parent 5100b5b commit 634cc1e
Showing 1 changed file with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Xunit;

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

Assert.True(currentOSCheck());

bool[] allResults = new bool[]
Dictionary<string, bool> allResults = new()
{
OperatingSystem.IsBrowser(),
OperatingSystem.IsLinux(),
OperatingSystem.IsFreeBSD(),
OperatingSystem.IsAndroid(),
OperatingSystem.IsIOS(),
OperatingSystem.IsMacCatalyst(),
OperatingSystem.IsMacOS(),
OperatingSystem.IsTvOS(),
OperatingSystem.IsWatchOS(),
OperatingSystem.IsWindows(),
OperatingSystem.IsWasi(),
{ "IsBrowser", OperatingSystem.IsBrowser() },
{ "IsLinux", OperatingSystem.IsLinux() },
{ "IsFreeBSD", OperatingSystem.IsFreeBSD() },
{ "IsAndroid", OperatingSystem.IsAndroid() },
{ "IsIOS", OperatingSystem.IsIOS() },
{ "IsMacCatalyst", OperatingSystem.IsMacCatalyst() },
{ "IsMacOS", OperatingSystem.IsMacOS() },
{ "IsTvOS", OperatingSystem.IsTvOS() },
{ "IsWatchOS", OperatingSystem.IsWatchOS() },
{ "IsWindows", OperatingSystem.IsWindows() },
{ "IsWasi", OperatingSystem.IsWasi() },
};

// MacCatalyst is a special case since it also returns true for iOS
if (currentOSName == "MacCatalyst")
{
Assert.Equal(10, allResults.Length);
Assert.False(allResults[0]); // IsBrowser()
Assert.False(allResults[1]); // IsLinux()
Assert.False(allResults[2]); // IsFreeBSD()
Assert.False(allResults[3]); // IsAndroid()
Assert.True(allResults[4]); // IsIOS()
Assert.True(allResults[5]); // IsMacCatalyst()
Assert.False(allResults[6]); // IsMacOS()
Assert.False(allResults[7]); // IsTvOS()
Assert.False(allResults[8]); // IsWatchOS()
Assert.False(allResults[9]); // IsWindows()
Assert.False(allResults[10]); // IsWasi()
foreach (var result in allResults)
{
if (result.Key == "IsMacCatalyst" || result.Key == "IsIOS")
{
Assert.True(result.Value);
}
else
{
Assert.False(result.Value);
}
}
}
else
{
Assert.Single(allResults, true);
Assert.Single(allResults.Values, true);
}
}

Expand Down

0 comments on commit 634cc1e

Please # to comment.