Skip to content

Commit

Permalink
Add RuntimeInformation.FrameworkDescription test to validate version
Browse files Browse the repository at this point in the history
We need to make sure the string contains only the stabilized version in servicing, or a non-stabilized one otherwise.
This prevents issues like dotnet#45812 and what we hit in dotnet#93807.

Closes dotnet#45812
  • Loading branch information
akoeplinger committed Oct 24, 2023
1 parent 64b93dd commit 8a099df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ public void VerifyRuntimeNameOnNetCoreApp()
Assert.Same(RuntimeInformation.FrameworkDescription, RuntimeInformation.FrameworkDescription);
}

[Fact]
public void VerifyFrameworkDescriptionContainsCorrectVersion()
{
var frameworkDescription = RuntimeInformation.FrameworkDescription;
var version = frameworkDescription.Substring(".NET".Length).Trim(); // remove ".NET" prefix

if (String.IsNullOrEmpty(version))
return;

Assert.DoesNotContain("+", version); // no git hash

#if STABILIZE_PACKAGE_VERSION
// a stabilized version looks like 8.0.0
Assert.DoesNotContain("-", version);
Assert.True(Version.TryParse(version, out Version _));
#else
// a non-stabilized version looks like 8.0.0-preview.5.23280.8 or 8.0.0-dev
Assert.Contains("-", version);
var versionNumber = version.Substring(0, version.IndexOf("-"));
Assert.True(Version.TryParse(versionNumber, out Version _));
#endif
}

[Fact]
public void VerifyOSDescription()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(StabilizePackageVersion)' == 'true'">$(DefineConstants);STABILIZE_PACKAGE_VERSION</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CheckArchitectureTests.cs" />
Expand Down

0 comments on commit 8a099df

Please sign in to comment.