Skip to content

Commit 3d160bc

Browse files
authored
[API] OperatingSystem.IsWasi() (#82817)
implement approved API #78389
1 parent 7bb7265 commit 3d160bc

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public static bool IsBrowser() =>
150150
false;
151151
#endif
152152

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

166164
/// <summary>
167165
/// Indicates whether the current application is running on Linux.

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public static class OperatingSystemTests
1818
"Windows",
1919
"Linux",
2020
"FreeBSD",
21-
"Browser"
21+
"Browser",
22+
"Wasi",
2223
};
2324

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

84+
[Fact, PlatformSpecific(TestPlatforms.Wasi)]
85+
public static void TestIsOSPlatform_Wasi() => TestIsOSPlatform("WASI", OperatingSystem.IsWasi);
86+
87+
[Fact, PlatformSpecific(TestPlatforms.Wasi)]
88+
public static void TestIsOSVersionAtLeast_Wasi() => TestIsOSVersionAtLeast("WASI");
89+
8390
[Fact, PlatformSpecific(TestPlatforms.Linux)]
8491
public static void TestIsOSPlatform_Linux() => TestIsOSPlatform("Linux", OperatingSystem.IsLinux);
8592

@@ -191,7 +198,8 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
191198
OperatingSystem.IsMacOS(),
192199
OperatingSystem.IsTvOS(),
193200
OperatingSystem.IsWatchOS(),
194-
OperatingSystem.IsWindows()
201+
OperatingSystem.IsWindows(),
202+
OperatingSystem.IsWasi(),
195203
};
196204

197205
// MacCatalyst is a special case since it also returns true for iOS
@@ -208,6 +216,7 @@ private static void TestIsOSPlatform(string currentOSName, Func<bool> currentOSC
208216
Assert.False(allResults[7]); // IsTvOS()
209217
Assert.False(allResults[8]); // IsWatchOS()
210218
Assert.False(allResults[9]); // IsWindows()
219+
Assert.False(allResults[10]); // IsWasi()
211220
}
212221
else
213222
{

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,6 +4334,7 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S
43344334
public static bool IsAndroid() { throw null; }
43354335
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) { throw null; }
43364336
public static bool IsBrowser() { throw null; }
4337+
public static bool IsWasi() { throw null; }
43374338
public static bool IsFreeBSD() { throw null; }
43384339
public static bool IsFreeBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) { throw null; }
43394340
[System.Runtime.Versioning.SupportedOSPlatformGuardAttribute("maccatalyst")]

0 commit comments

Comments
 (0)