Skip to content

Commit

Permalink
Don't show AssemblyInformationalVersion metadata in BDN BrandVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Oct 10, 2023
1 parent c27152b commit 2e96d29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/BenchmarkDotNet/Properties/BenchmarkDotNetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BenchmarkDotNetInfo
var assembly = typeof(BenchmarkDotNetInfo).GetTypeInfo().Assembly;
var assemblyVersion = assembly.GetName().Version;
string informationVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion ?? "";
return new BenchmarkDotNetInfo(assemblyVersion, informationVersion);
return new BenchmarkDotNetInfo(assemblyVersion, RemoveVersionMetadata(informationVersion));
});

public static BenchmarkDotNetInfo Instance { get; } = LazyInstance.Value;
Expand Down Expand Up @@ -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" +
Expand Down
19 changes: 19 additions & 0 deletions tests/BenchmarkDotNet.Tests/Properties/BenchmarkDotNetInfoTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 2e96d29

Please sign in to comment.