Skip to content

Commit

Permalink
[API] OperatingSystem.IsWasi() (#82817)
Browse files Browse the repository at this point in the history
implement approved API #78389
  • Loading branch information
pavelsavara authored Mar 1, 2023
1 parent 7bb7265 commit 3d160bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public static bool IsBrowser() =>
false;
#endif

/* TODO https://github.com/dotnet/runtime/issues/78389
/// <summary>
/// Indicates whether the current application is running as WASI.
/// </summary>
Expand All @@ -161,7 +160,6 @@ public static bool IsWasi() =>
#else
false;
#endif
*/

/// <summary>
/// Indicates whether the current application is running on Linux.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public static class OperatingSystemTests
"Windows",
"Linux",
"FreeBSD",
"Browser"
"Browser",
"Wasi",
};

[Theory]
Expand Down Expand Up @@ -80,6 +81,12 @@ public static void IsOSPlatformVersionAtLeast_InvalidArgs_Throws()
[Fact, PlatformSpecific(TestPlatforms.Browser)]
public static void TestIsOSVersionAtLeast_Browser() => TestIsOSVersionAtLeast("BROWSER");

[Fact, PlatformSpecific(TestPlatforms.Wasi)]
public static void TestIsOSPlatform_Wasi() => TestIsOSPlatform("WASI", OperatingSystem.IsWasi);

[Fact, PlatformSpecific(TestPlatforms.Wasi)]
public static void TestIsOSVersionAtLeast_Wasi() => TestIsOSVersionAtLeast("WASI");

[Fact, PlatformSpecific(TestPlatforms.Linux)]
public static void TestIsOSPlatform_Linux() => TestIsOSPlatform("Linux", OperatingSystem.IsLinux);

Expand Down Expand Up @@ -191,7 +198,8 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
OperatingSystem.IsMacOS(),
OperatingSystem.IsTvOS(),
OperatingSystem.IsWatchOS(),
OperatingSystem.IsWindows()
OperatingSystem.IsWindows(),
OperatingSystem.IsWasi(),
};

// MacCatalyst is a special case since it also returns true for iOS
Expand All @@ -208,6 +216,7 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
Assert.False(allResults[7]); // IsTvOS()
Assert.False(allResults[8]); // IsWatchOS()
Assert.False(allResults[9]); // IsWindows()
Assert.False(allResults[10]); // IsWasi()
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4334,6 +4334,7 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S
public static bool IsAndroid() { throw null; }
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) { throw null; }
public static bool IsBrowser() { throw null; }
public static bool IsWasi() { throw null; }
public static bool IsFreeBSD() { throw null; }
public static bool IsFreeBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformGuardAttribute("maccatalyst")]
Expand Down

0 comments on commit 3d160bc

Please sign in to comment.