From 9eaa94f16f35d3f4b230f6beb7166ebcb736df37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 11:19:52 -0500 Subject: [PATCH 1/9] Update test project TFMs (#700) --- common/SharedHttpClient.cs | 2 +- eng/validate-testprojects-configuration.ps1 | 4 ++++ .../Meziantou.Framework.ByteSize.Tests.csproj | 4 ++-- .../Meziantou.Framework.CodeOwners.Tests.csproj | 4 ++-- .../Meziantou.Framework.RelativeDate.Tests.csproj | 2 +- .../Meziantou.Framework.SingleInstance.Tests.csproj | 2 +- .../Meziantou.Framework.ValueStopwatch.Tests.csproj | 4 ++-- .../Meziantou.Framework.Versioning.Tests.csproj | 2 +- .../Meziantou.Framework.WPF.Tests.csproj | 4 ++-- ...eziantou.Framework.Win32.CredentialManager.Tests.csproj | 2 +- .../Meziantou.Framework.Win32.RestartManager.Tests.csproj | 2 +- .../RestartManagerTests.cs | 2 +- tests/TestUtilities/NuGetHelpers.cs | 6 +++--- tests/TestUtilities/TestUtilities.csproj | 7 ++++++- 14 files changed, 28 insertions(+), 19 deletions(-) diff --git a/common/SharedHttpClient.cs b/common/SharedHttpClient.cs index cb5bc3bdc..2309d0835 100644 --- a/common/SharedHttpClient.cs +++ b/common/SharedHttpClient.cs @@ -1,4 +1,4 @@ -#if NET462 +#if NET462 || NET472 using System.Net.Http; #endif diff --git a/eng/validate-testprojects-configuration.ps1 b/eng/validate-testprojects-configuration.ps1 index 697dca25f..b13bc02a7 100644 --- a/eng/validate-testprojects-configuration.ps1 +++ b/eng/validate-testprojects-configuration.ps1 @@ -42,6 +42,10 @@ $Errors = $Projs | Foreach-Object -ThrottleLimit 5 -Parallel { if ($RefTfm -eq "netstandard2.1") { continue; } + + if ($RefTfm -eq "net462" -and $TestProjectTfms.Contains("net472")) { + continue; + } if (-not $TestProjectTfms.Contains($RefTfm)) { Write-Error "Project $($Proj.FullName) does not target $RefTfm, but it references $RefProj which does. ($TestProjectTfms) != ($RefTfms)" diff --git a/tests/Meziantou.Framework.ByteSize.Tests/Meziantou.Framework.ByteSize.Tests.csproj b/tests/Meziantou.Framework.ByteSize.Tests/Meziantou.Framework.ByteSize.Tests.csproj index 1671a9583..0b907c9c4 100644 --- a/tests/Meziantou.Framework.ByteSize.Tests/Meziantou.Framework.ByteSize.Tests.csproj +++ b/tests/Meziantou.Framework.ByteSize.Tests/Meziantou.Framework.ByteSize.Tests.csproj @@ -1,8 +1,8 @@ - + $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.CodeOwners.Tests/Meziantou.Framework.CodeOwners.Tests.csproj b/tests/Meziantou.Framework.CodeOwners.Tests/Meziantou.Framework.CodeOwners.Tests.csproj index e9a770a1c..6efaeca0d 100644 --- a/tests/Meziantou.Framework.CodeOwners.Tests/Meziantou.Framework.CodeOwners.Tests.csproj +++ b/tests/Meziantou.Framework.CodeOwners.Tests/Meziantou.Framework.CodeOwners.Tests.csproj @@ -1,8 +1,8 @@ - + $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.RelativeDate.Tests/Meziantou.Framework.RelativeDate.Tests.csproj b/tests/Meziantou.Framework.RelativeDate.Tests/Meziantou.Framework.RelativeDate.Tests.csproj index d874577e0..6c2d12a91 100644 --- a/tests/Meziantou.Framework.RelativeDate.Tests/Meziantou.Framework.RelativeDate.Tests.csproj +++ b/tests/Meziantou.Framework.RelativeDate.Tests/Meziantou.Framework.RelativeDate.Tests.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.SingleInstance.Tests/Meziantou.Framework.SingleInstance.Tests.csproj b/tests/Meziantou.Framework.SingleInstance.Tests/Meziantou.Framework.SingleInstance.Tests.csproj index 3abf00173..5c20d0677 100644 --- a/tests/Meziantou.Framework.SingleInstance.Tests/Meziantou.Framework.SingleInstance.Tests.csproj +++ b/tests/Meziantou.Framework.SingleInstance.Tests/Meziantou.Framework.SingleInstance.Tests.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.ValueStopwatch.Tests/Meziantou.Framework.ValueStopwatch.Tests.csproj b/tests/Meziantou.Framework.ValueStopwatch.Tests/Meziantou.Framework.ValueStopwatch.Tests.csproj index 2039615e8..49f4ebc3e 100644 --- a/tests/Meziantou.Framework.ValueStopwatch.Tests/Meziantou.Framework.ValueStopwatch.Tests.csproj +++ b/tests/Meziantou.Framework.ValueStopwatch.Tests/Meziantou.Framework.ValueStopwatch.Tests.csproj @@ -1,8 +1,8 @@ - + $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.Versioning.Tests/Meziantou.Framework.Versioning.Tests.csproj b/tests/Meziantou.Framework.Versioning.Tests/Meziantou.Framework.Versioning.Tests.csproj index e50ee91b6..1205ad7e1 100644 --- a/tests/Meziantou.Framework.Versioning.Tests/Meziantou.Framework.Versioning.Tests.csproj +++ b/tests/Meziantou.Framework.Versioning.Tests/Meziantou.Framework.Versioning.Tests.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.WPF.Tests/Meziantou.Framework.WPF.Tests.csproj b/tests/Meziantou.Framework.WPF.Tests/Meziantou.Framework.WPF.Tests.csproj index e3af819b1..c72a3227d 100644 --- a/tests/Meziantou.Framework.WPF.Tests/Meziantou.Framework.WPF.Tests.csproj +++ b/tests/Meziantou.Framework.WPF.Tests/Meziantou.Framework.WPF.Tests.csproj @@ -2,12 +2,12 @@ $(LatestTargetFrameworksWindows) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 true true - + diff --git a/tests/Meziantou.Framework.Win32.CredentialManager.Tests/Meziantou.Framework.Win32.CredentialManager.Tests.csproj b/tests/Meziantou.Framework.Win32.CredentialManager.Tests/Meziantou.Framework.Win32.CredentialManager.Tests.csproj index 8fd2693bd..e8ce8aa2a 100644 --- a/tests/Meziantou.Framework.Win32.CredentialManager.Tests/Meziantou.Framework.Win32.CredentialManager.Tests.csproj +++ b/tests/Meziantou.Framework.Win32.CredentialManager.Tests/Meziantou.Framework.Win32.CredentialManager.Tests.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworksWindows) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.Win32.RestartManager.Tests/Meziantou.Framework.Win32.RestartManager.Tests.csproj b/tests/Meziantou.Framework.Win32.RestartManager.Tests/Meziantou.Framework.Win32.RestartManager.Tests.csproj index 977f7d79c..0e6303aba 100644 --- a/tests/Meziantou.Framework.Win32.RestartManager.Tests/Meziantou.Framework.Win32.RestartManager.Tests.csproj +++ b/tests/Meziantou.Framework.Win32.RestartManager.Tests/Meziantou.Framework.Win32.RestartManager.Tests.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworksWindows) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 diff --git a/tests/Meziantou.Framework.Win32.RestartManager.Tests/RestartManagerTests.cs b/tests/Meziantou.Framework.Win32.RestartManager.Tests/RestartManagerTests.cs index c3626d1ee..56987fa15 100644 --- a/tests/Meziantou.Framework.Win32.RestartManager.Tests/RestartManagerTests.cs +++ b/tests/Meziantou.Framework.Win32.RestartManager.Tests/RestartManagerTests.cs @@ -9,7 +9,7 @@ public class RestartManagerTests public RestartManagerTests() { -#if NET462 +#if NET462 || NET472 _currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; #else _currentProcessId = System.Environment.ProcessId; diff --git a/tests/TestUtilities/NuGetHelpers.cs b/tests/TestUtilities/NuGetHelpers.cs index 0f19f9fd1..ca3ca0e88 100644 --- a/tests/TestUtilities/NuGetHelpers.cs +++ b/tests/TestUtilities/NuGetHelpers.cs @@ -1,4 +1,4 @@ -#if !NET462 +#if !NET462 && !NET472 #pragma warning disable MA0042 #endif using System.Collections.Concurrent; @@ -10,7 +10,7 @@ using Meziantou.Framework; using Xunit; -#if NET462 +#if NET462 || NET472 using System.Net.Http; #endif @@ -20,7 +20,7 @@ public static class NuGetHelpers { private static readonly ConcurrentDictionary>> NuGetPackagesCache = new(StringComparer.Ordinal); -#if !NET462 +#if !NET462 && !NET472 [SuppressMessage("Performance", "MA0106:Avoid closure by using an overload with the 'factoryArgument' parameter", Justification = "Not important in tests")] #endif public static async Task GetNuGetReferences(string packageName, string version, params string[] paths) diff --git a/tests/TestUtilities/TestUtilities.csproj b/tests/TestUtilities/TestUtilities.csproj index f2f5eb97f..339583564 100644 --- a/tests/TestUtilities/TestUtilities.csproj +++ b/tests/TestUtilities/TestUtilities.csproj @@ -2,7 +2,7 @@ $(LatestTargetFrameworks) - $(TargetFrameworks);net462 + $(TargetFrameworks);net472 @@ -15,4 +15,9 @@ + + + + + From 8eb5a6553cfb545a5bd77e1a9b8af6ac05585596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 11:53:54 -0500 Subject: [PATCH 2/9] Pin xunit version (#701) --- .../Meziantou.Extensions.Logging.Xunit.Tests.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Meziantou.Extensions.Logging.Xunit.Tests/Meziantou.Extensions.Logging.Xunit.Tests.csproj b/tests/Meziantou.Extensions.Logging.Xunit.Tests/Meziantou.Extensions.Logging.Xunit.Tests.csproj index ae6124e2d..cb55a20d3 100644 --- a/tests/Meziantou.Extensions.Logging.Xunit.Tests/Meziantou.Extensions.Logging.Xunit.Tests.csproj +++ b/tests/Meziantou.Extensions.Logging.Xunit.Tests/Meziantou.Extensions.Logging.Xunit.Tests.csproj @@ -2,9 +2,13 @@ $(LatestTargetFrameworks) + false + + + From 7af13e9e8e6bc388348cd61eeff3b816e799b799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 13:07:38 -0500 Subject: [PATCH 3/9] Add dependency conditionally (#704) --- .../Meziantou.Framework.Win32.CredentialManager.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Meziantou.Framework.Win32.CredentialManager/Meziantou.Framework.Win32.CredentialManager.csproj b/src/Meziantou.Framework.Win32.CredentialManager/Meziantou.Framework.Win32.CredentialManager.csproj index a565b2606..85b2d5f33 100644 --- a/src/Meziantou.Framework.Win32.CredentialManager/Meziantou.Framework.Win32.CredentialManager.csproj +++ b/src/Meziantou.Framework.Win32.CredentialManager/Meziantou.Framework.Win32.CredentialManager.csproj @@ -13,6 +13,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + + From af74acb5640fd963201a7f2830d509cbbaae8276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 13:33:03 -0500 Subject: [PATCH 4/9] Increase timeout in Debounce test (#703) --- ...ouceExtensionsTests.cs => DebounceExtensionsTests.cs} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename tests/Meziantou.Framework.Tests/{DebouceExtensionsTests.cs => DebounceExtensionsTests.cs} (70%) diff --git a/tests/Meziantou.Framework.Tests/DebouceExtensionsTests.cs b/tests/Meziantou.Framework.Tests/DebounceExtensionsTests.cs similarity index 70% rename from tests/Meziantou.Framework.Tests/DebouceExtensionsTests.cs rename to tests/Meziantou.Framework.Tests/DebounceExtensionsTests.cs index 04fa2dace..d1a8dd956 100644 --- a/tests/Meziantou.Framework.Tests/DebouceExtensionsTests.cs +++ b/tests/Meziantou.Framework.Tests/DebounceExtensionsTests.cs @@ -3,20 +3,21 @@ namespace Meziantou.Framework.Tests; -public class DebouceExtensionsTests +public sealed class DebounceExtensionsTests { [Fact] public void Debounce_CallActionsWithArgumentsOfTheLastCall() { using var resetEvent = new ManualResetEventSlim(initialState: false); - int lastArg = default; + var lastArg = 0; var count = 0; var debounced = DebounceExtensions.Debounce(i => { lastArg = i; - count++; + Interlocked.CompareExchange(ref lastArg, i, 0); + Interlocked.Increment(ref count); resetEvent.Set(); - }, TimeSpan.FromMilliseconds(10)); + }, TimeSpan.FromMilliseconds(200)); debounced(1); debounced(2); From 44f5cd76753facd1d1e1f51d12ab574cf06adb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 14:13:00 -0500 Subject: [PATCH 5/9] Update ArgumentsPrinter.csproj (#705) --- tests/ArgumentsPrinter/ArgumentsPrinter.csproj | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/ArgumentsPrinter/ArgumentsPrinter.csproj b/tests/ArgumentsPrinter/ArgumentsPrinter.csproj index 2b918e44c..126280d5b 100644 --- a/tests/ArgumentsPrinter/ArgumentsPrinter.csproj +++ b/tests/ArgumentsPrinter/ArgumentsPrinter.csproj @@ -1,13 +1,8 @@ - Exe $(LatestTargetFrameworks) LatestMajor + false - - - - - From 7ce31998a2b997b415f010ec9057c7d13690c357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 14:31:07 -0500 Subject: [PATCH 6/9] Hide xunit.runner.json (#706) --- tests/Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 07ac3caea..89e790325 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -6,7 +6,7 @@ - + @@ -23,4 +23,4 @@ - \ No newline at end of file + From b6f5e1535c5f0cbef9142e720809e4880f665f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 15:05:16 -0500 Subject: [PATCH 7/9] Remove fluentassertions from TaskDialog tests --- .../TaskDialogPromptTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs b/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs index 4a57a3bd2..233c9585f 100644 --- a/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs +++ b/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs @@ -89,9 +89,9 @@ internal void Ask(int buttonIndex, bool applyToAllFiles, PromptConfigurationMode { var result = Invoke(new PromptContext("path.cs", "dummy test", ParentProcessInfo: null), buttonIndex, applyToAllFiles); - result.Mode.Should().Be(expectedMode); - result.Scope.Should().Be(expectedScope); - result.RememberPeriod.Should().Be(TimeSpan.FromHours(1)); + Assert.Equal(expectedMode, result.Mode); + Assert.Equal(expectedScope, result.Scope); + Assert.Equal(TimeSpan.FromHours(1), result.RememberPeriod); } [RunIfFact(FactOperatingSystem.Windows)] @@ -99,8 +99,8 @@ internal void Ask_Cancel() { var result = Invoke(new PromptContext("path.cs", "dummy test", ParentProcessInfo: null), buttonIndex: 4, applyToAllFiles: false); - result.Mode.Should().Be(PromptConfigurationMode.Disallow); - result.Scope.Should().Be(PromptConfigurationScope.CurrentSnapshot); - result.RememberPeriod.Should().BeLessThanOrEqualTo(TimeSpan.Zero); + Assert.Equal(PromptConfigurationMode.Disallow, result.Mode); + Assert.Equal(PromptConfigurationScope.CurrentSnapshot, result.Scope); + Assert.True(result.RememberPeriod <= TimeSpan.Zero); } } From 69c7698f766b817e24e38907e0c9892c60c170de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 15:17:39 -0500 Subject: [PATCH 8/9] Upload binlog in test jobs --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89faa9b14..32f98070b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,7 +123,9 @@ jobs: name: ${{ steps.compute-artifact-name.outputs.artifact-name }} if-no-files-found: error retention-days: 3 - path: ${{ env.TestResultsDirectory }}/**/* + path: | + **/*.binlog + ${{ env.TestResultsDirectory }}/**/* build_and_test_windows_x86: runs-on: ${{ matrix.runs-on }} @@ -184,7 +186,9 @@ jobs: name: ${{ steps.compute-artifact-name.outputs.artifact-name }} if-no-files-found: error retention-days: 3 - path: ${{ env.TestResultsDirectory }}/**/* + path: | + **/*.binlog + ${{ env.TestResultsDirectory }}/**/* test_trimming: runs-on: ubuntu-24.04 From 66a5ec9926f1dd478f3f25a531d087796705dd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Sun, 22 Dec 2024 15:17:47 -0500 Subject: [PATCH 9/9] Cleaup usings --- .../TaskDialogPromptTests.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs b/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs index 233c9585f..be458f8e3 100644 --- a/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs +++ b/tests/Meziantou.Framework.InlineSnapshotTesting.TaskDialog.Tests/TaskDialogPromptTests.cs @@ -1,11 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using System.Windows.Automation; -using FluentAssertions; +using System.Windows.Automation; using Meziantou.Framework.InlineSnapshotTesting.SnapshotUpdateStrategies; -using Microsoft.CodeAnalysis.CSharp.Syntax; using TestUtilities; using Xunit;