From c39a8503154c01abd69ffcacf352daa760f7d959 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Jun 2023 21:42:52 +1000 Subject: [PATCH 1/2] remove parameter hashing from unsupported TFM --- src/Verify.Tests/Naming/NamerTests.cs | 2 ++ src/Verify/Naming/FileNameBuilder.cs | 4 ++++ src/Verify/Naming/ParameterSettings.cs | 2 ++ src/Verify/SettingsTask.cs | 3 +++ src/Verify/Verify.csproj | 2 +- src/Verify/VerifySettings.cs | 4 ++++ 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Verify.Tests/Naming/NamerTests.cs b/src/Verify.Tests/Naming/NamerTests.cs index e858bb0112..05501d7755 100644 --- a/src/Verify.Tests/Naming/NamerTests.cs +++ b/src/Verify.Tests/Naming/NamerTests.cs @@ -586,6 +586,7 @@ public Task FrameworkName() }) .UniqueForRuntimeAndVersion(); } +#if NET6_0_OR_GREATER || NETFRAMEWORK [Theory] [InlineData(true, false)] @@ -622,4 +623,5 @@ public Task HashParametersFluent(bool a, bool b) => Verify("ContentHashParametersFluent") .UseHashedParameters(a, b) .HashParameters(); +#endif } \ No newline at end of file diff --git a/src/Verify/Naming/FileNameBuilder.cs b/src/Verify/Naming/FileNameBuilder.cs index 15e2d3441e..a5936a4ddd 100644 --- a/src/Verify/Naming/FileNameBuilder.cs +++ b/src/Verify/Naming/FileNameBuilder.cs @@ -38,14 +38,17 @@ public static string GetParameterText(IReadOnlyList? methodParameters, V builder.Length -= 1; var parameterText = builder.ToString(); +#if NET6_0_OR_GREATER || NETFRAMEWORK if (settings.hashParameters) { var hashed = HashString(parameterText); return $"_{hashed}"; } +#endif return parameterText; } +#if NET6_0_OR_GREATER || NETFRAMEWORK static string HashString(string value) { var data = XxHash64.Hash(Encoding.UTF8.GetBytes(value)); @@ -59,4 +62,5 @@ static string HashString(string value) return builder.ToString(); } +#endif } \ No newline at end of file diff --git a/src/Verify/Naming/ParameterSettings.cs b/src/Verify/Naming/ParameterSettings.cs index e6974ddc40..0aed1a556b 100644 --- a/src/Verify/Naming/ParameterSettings.cs +++ b/src/Verify/Naming/ParameterSettings.cs @@ -52,6 +52,7 @@ public void IgnoreParametersForVerified(params object?[] parameters) ignoreParametersForVerified = true; } +#if NET6_0_OR_GREATER || NETFRAMEWORK internal bool hashParameters; /// @@ -75,4 +76,5 @@ public void UseHashedParameters(params object?[] parameters) UseParameters(parameters); HashParameters(); } +#endif } \ No newline at end of file diff --git a/src/Verify/SettingsTask.cs b/src/Verify/SettingsTask.cs index 9f4346dcdd..a102926f57 100644 --- a/src/Verify/SettingsTask.cs +++ b/src/Verify/SettingsTask.cs @@ -246,6 +246,7 @@ public SettingsTask UniqueForRuntimeAndVersion() return this; } +#if NET6_0_OR_GREATER || NETFRAMEWORK /// /// Provide parameters to hash together and pass to . /// Used to get a deterministic file name while avoiding long paths. @@ -267,6 +268,8 @@ public SettingsTask HashParameters() return this; } +#endif + /// /// Use the current processor architecture (x86/x64/arm/arm64) to make the test results unique. /// Used when a test produces different results based on processor architecture. diff --git a/src/Verify/Verify.csproj b/src/Verify/Verify.csproj index fb7ff939e3..3509e76e1a 100644 --- a/src/Verify/Verify.csproj +++ b/src/Verify/Verify.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Verify/VerifySettings.cs b/src/Verify/VerifySettings.cs index c96e3a4c8d..7c04a915e6 100644 --- a/src/Verify/VerifySettings.cs +++ b/src/Verify/VerifySettings.cs @@ -25,7 +25,11 @@ public VerifySettings(VerifySettings? settings) streamComparer = settings.streamComparer; parameters = settings.parameters; ignoreParametersForVerified = settings.ignoreParametersForVerified; + +#if NET6_0_OR_GREATER || NETFRAMEWORK hashParameters = settings.hashParameters; +#endif + parametersText = settings.parametersText; fileName = settings.fileName; UniquePrefixDisabled = settings.UniquePrefixDisabled; From d1d8d6866782b54335bb6327079da93c76790d08 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 19 Jun 2023 21:43:18 +1000 Subject: [PATCH 2/2] . --- src/Directory.Build.props | 2 +- src/Verify/Naming/FileNameBuilder.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 18da5019dd..c54def43de 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436;CS1573 - 20.3.2 + 20.3.3 enable 11 true diff --git a/src/Verify/Naming/FileNameBuilder.cs b/src/Verify/Naming/FileNameBuilder.cs index a5936a4ddd..d1d0123dfe 100644 --- a/src/Verify/Naming/FileNameBuilder.cs +++ b/src/Verify/Naming/FileNameBuilder.cs @@ -1,4 +1,6 @@ -using System.IO.Hashing; +#if NET6_0_OR_GREATER || NETFRAMEWORK +using System.IO.Hashing; +#endif static class FileNameBuilder {