Skip to content

Commit

Permalink
Add RuntimeInformation.FrameworkDescription test to validate version (d…
Browse files Browse the repository at this point in the history
…otnet#93913)

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 authored and liveans committed Nov 9, 2023
1 parent 5a8d5ec commit 85936e9
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 85936e9

Please sign in to comment.