Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reenable a few OperatingSystem tests on MacCatalyst (#58428)
#56084 was fixed.
(cherry picked from commit 2d3ad72)
  • Loading branch information
akoeplinger committed Sep 9, 2021
commit 2bb7a34f9783ddaa13b4666afa634f36d5713b22
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ public static void IsOSPlatformVersionAtLeast_InvalidArgs_Throws()
public static void TestIsOSVersionAtLeast_Android_21() => Assert.True(OperatingSystem.IsAndroidVersionAtLeast(21)); // 21 is our min supported version

[Fact, PlatformSpecific(TestPlatforms.iOS)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56084", TestPlatforms.MacCatalyst)]
public static void TestIsOSPlatform_IOS() => TestIsOSPlatform("iOS", OperatingSystem.IsIOS);

[Fact, PlatformSpecific(TestPlatforms.iOS)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56084", TestPlatforms.MacCatalyst)]
public static void TestIsOSVersionAtLeast_IOS() => TestIsOSVersionAtLeast("iOS");

[Fact, PlatformSpecific(TestPlatforms.OSX)]
Expand All @@ -129,11 +127,9 @@ public static void OSX_Is_Treated_as_macOS()
}

[Fact, PlatformSpecific(TestPlatforms.MacCatalyst)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56084", TestPlatforms.MacCatalyst)]
public static void TestIsOSPlatform_MacCatalyst() => TestIsOSPlatform("MacCatalyst", OperatingSystem.IsMacCatalyst);

[Fact, PlatformSpecific(TestPlatforms.MacCatalyst)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56084", TestPlatforms.MacCatalyst)]
public static void TestIsOSVersionAtLeast_MacCatalyst() => TestIsOSVersionAtLeast("MacCatalyst");

[Fact, PlatformSpecific(TestPlatforms.MacCatalyst)]
Expand All @@ -147,7 +143,6 @@ public static void MacCatalyst_Is_Also_iOS()
}

[Fact, PlatformSpecific(TestPlatforms.iOS)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56084", TestPlatforms.MacCatalyst)]
public static void IOS_Is_Not_Also_MacCatalyst()
{
Assert.False(OperatingSystem.IsOSPlatform("MacCatalyst"));
Expand All @@ -172,6 +167,12 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
{
bool expected = currentOSName.Equals(platformName, StringComparison.OrdinalIgnoreCase);

// MacCatalyst is a special case since it also returns true for iOS
if (currentOSName == "MacCatalyst" && platformName == "iOS")
{
expected = true;
}

Assert.Equal(expected, OperatingSystem.IsOSPlatform(platformName));
Assert.Equal(expected, OperatingSystem.IsOSPlatform(platformName.ToUpper()));
Assert.Equal(expected, OperatingSystem.IsOSPlatform(platformName.ToLower()));
Expand All @@ -186,14 +187,32 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
OperatingSystem.IsFreeBSD(),
OperatingSystem.IsAndroid(),
OperatingSystem.IsIOS(),
OperatingSystem.IsMacOS(),
OperatingSystem.IsMacCatalyst(),
OperatingSystem.IsMacOS(),
OperatingSystem.IsTvOS(),
OperatingSystem.IsWatchOS(),
OperatingSystem.IsWindows()
};

Assert.Single(allResults, true);
// 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()
}
else
{
Assert.Single(allResults, true);
}
}

private static void TestIsOSVersionAtLeast(string currentOSName)
Expand All @@ -202,13 +221,19 @@ private static void TestIsOSVersionAtLeast(string currentOSName)
{
bool isCurrentOS = currentOSName.Equals(platformName, StringComparison.OrdinalIgnoreCase);

// MacCatalyst is a special case since it also returns true for iOS
if (currentOSName == "MacCatalyst" && platformName == "iOS")
{
isCurrentOS = true;
}

AssertVersionChecks(isCurrentOS, (major, minor, build, revision) => OperatingSystem.IsOSPlatformVersionAtLeast(platformName, major, minor, build, revision));
AssertVersionChecks(isCurrentOS, (major, minor, build, revision) => OperatingSystem.IsOSPlatformVersionAtLeast(platformName.ToLower(), major, minor, build, revision));
AssertVersionChecks(isCurrentOS, (major, minor, build, revision) => OperatingSystem.IsOSPlatformVersionAtLeast(platformName.ToUpper(), major, minor, build, revision));
}

AssertVersionChecks(currentOSName.Equals("Android", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsAndroidVersionAtLeast);
AssertVersionChecks(currentOSName.Equals("iOS", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsIOSVersionAtLeast);
AssertVersionChecks(currentOSName == "MacCatalyst" || currentOSName.Equals("iOS", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsIOSVersionAtLeast);
AssertVersionChecks(currentOSName.Equals("macOS", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsMacOSVersionAtLeast);
AssertVersionChecks(currentOSName.Equals("MacCatalyst", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsMacCatalystVersionAtLeast);
AssertVersionChecks(currentOSName.Equals("tvOS", StringComparison.OrdinalIgnoreCase), OperatingSystem.IsTvOSVersionAtLeast);
Expand Down