forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RuntimeInformation.RuntimeIdentifier
This value returns the Runtime Identifier (RID) of the current machine. Contributes to dotnet#26780
- Loading branch information
Showing
8 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...braries/System.Runtime.InteropServices.RuntimeInformation/tests/RuntimeIdentifierTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.DotNet.RemoteExecutor; | ||
using Xunit; | ||
|
||
namespace System.Runtime.InteropServices.RuntimeInformationTests | ||
{ | ||
public class RuntimeIdentifierTests | ||
{ | ||
[Fact(Skip = "#26780 Need new testhost")] | ||
public void VerifyOSRid() | ||
{ | ||
Assert.NotNull(RuntimeInformation.RuntimeIdentifier); | ||
Assert.Same(RuntimeInformation.RuntimeIdentifier, RuntimeInformation.RuntimeIdentifier); | ||
Assert.EndsWith(RuntimeInformation.ProcessArchitecture.ToString(), RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Fact(Skip = "#26780 Need new testhost")] | ||
public void VerifyEnvironmentVariable() | ||
{ | ||
RemoteInvokeOptions options = new RemoteInvokeOptions(); | ||
options.StartInfo.EnvironmentVariables.Add("DOTNET_RUNTIME_ID", "overridenFromEnv-rid"); | ||
|
||
RemoteExecutor.Invoke(() => | ||
{ | ||
Assert.Equal("overridenFromEnv-rid", RuntimeInformation.RuntimeIdentifier); | ||
}, options).Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void VerifyAppContextVariable() | ||
{ | ||
RemoteExecutor.Invoke(() => | ||
{ | ||
AppDomain.CurrentDomain.SetData("RUNTIME_IDENTIFIER", "overriden-rid"); | ||
|
||
Assert.Equal("overriden-rid", RuntimeInformation.RuntimeIdentifier); | ||
}).Dispose(); | ||
} | ||
|
||
[Fact(Skip = "#26780 Need new testhost"), PlatformSpecific(TestPlatforms.Windows)] | ||
public void VerifyWindowsRid() | ||
{ | ||
Assert.StartsWith("win", RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Fact(Skip = "#26780 Need new testhost"), PlatformSpecific(TestPlatforms.Linux)] | ||
public void VerifyLinuxRid() | ||
{ | ||
string expectedOSName = File.ReadAllLines("/etc/os-release") | ||
.First(line => line.StartsWith("ID=", StringComparison.OrdinalIgnoreCase)) | ||
.Substring("ID=".Length) | ||
.Trim(); | ||
|
||
Assert.StartsWith(expectedOSName, RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Fact(Skip = "#26780 Need new testhost"), PlatformSpecific(TestPlatforms.FreeBSD)] | ||
public void VerifyFreeBSDRid() | ||
{ | ||
Assert.StartsWith("freebsd", RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
[Fact(Skip = "#26780 Need new testhost"), PlatformSpecific(TestPlatforms.OSX)] | ||
public void VerifyOSXRid() | ||
{ | ||
Assert.StartsWith("osx", RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...s.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters