diff --git a/src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs b/src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs index 0b9d0e6f44..fcb01a0055 100644 --- a/src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs +++ b/src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs @@ -11,7 +11,7 @@ public class BenchmarkDotNetInfo var assembly = typeof(BenchmarkDotNetInfo).GetTypeInfo().Assembly; var assemblyVersion = assembly.GetName().Version; string informationVersion = assembly.GetCustomAttribute().InformationalVersion ?? ""; - return new BenchmarkDotNetInfo(assemblyVersion, informationVersion); + return new BenchmarkDotNetInfo(assemblyVersion, RemoveVersionMetadata(informationVersion)); }); public static BenchmarkDotNetInfo Instance { get; } = LazyInstance.Value; @@ -49,6 +49,12 @@ public BenchmarkDotNetInfo(Version assemblyVersion, string fullVersion) BrandTitle = "BenchmarkDotNet v" + BrandVersion; } + internal static string RemoveVersionMetadata(string version) + { + int index = version.IndexOf('+'); + return index >= 0 ? version.Substring(0, index) : version; + } + internal const string PublicKey = "00240000048000009400000006020000002400005253413100040000010001002970bbdfca4d12" + "9fc74b4845b239973f1b183684f0d7db5e1de7e085917e3656cf94884803cb800d85d5aae5838f" + diff --git a/tests/BenchmarkDotNet.Tests/Properties/BenchmarkDotNetInfoTests.cs b/tests/BenchmarkDotNet.Tests/Properties/BenchmarkDotNetInfoTests.cs new file mode 100644 index 0000000000..66581494e7 --- /dev/null +++ b/tests/BenchmarkDotNet.Tests/Properties/BenchmarkDotNetInfoTests.cs @@ -0,0 +1,19 @@ +using BenchmarkDotNet.Properties; +using Xunit; + +namespace BenchmarkDotNet.Tests.Properties; + +public class BenchmarkDotNetInfoTests +{ + [Theory] + [InlineData("", "")] + [InlineData("1.2.3.4", "1.2.3.4")] + [InlineData("1729-foo", "1729-foo")] + [InlineData("0.13.9+228a464e8be6c580ad9408e98f18813f6407fb5a", "0.13.9")] + [InlineData("1-2+3", "1-2")] + public void RemoveVersionMetadata(string input, string expectedOutput) + { + string? actualOutput = BenchmarkDotNetInfo.RemoveVersionMetadata(input); + Assert.Equal(expectedOutput, actualOutput); + } +} \ No newline at end of file