From e995c3fa38c317a10a3dfa8971201697134ed9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 27 May 2024 09:42:36 +0200 Subject: [PATCH] Add sync script and sync --- .../Pester/Tracing/ExternalTracerAdapter.cs | 4 ++- src/csharp/Pester/Tracing/ITracer.cs | 4 ++- src/csharp/Pester/Tracing/Tracer.cs | 7 +++-- src/csharp/Pester/Tracing/TracerHostUI.cs | 4 ++- src/csharp/Sync-WithProfiler.ps1 | 28 +++++++++++++++++++ 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/csharp/Sync-WithProfiler.ps1 diff --git a/src/csharp/Pester/Tracing/ExternalTracerAdapter.cs b/src/csharp/Pester/Tracing/ExternalTracerAdapter.cs index 87240a76d..fa776fa7b 100644 --- a/src/csharp/Pester/Tracing/ExternalTracerAdapter.cs +++ b/src/csharp/Pester/Tracing/ExternalTracerAdapter.cs @@ -1,4 +1,6 @@ -using System; +// Copied from Profiler module, branch: Fix-error-autodetection, commit: 150bbcf Fix error autodetection + +using System; using System.Management.Automation; using System.Management.Automation.Language; using System.Reflection; diff --git a/src/csharp/Pester/Tracing/ITracer.cs b/src/csharp/Pester/Tracing/ITracer.cs index 4e820ab9b..e6aa5ef65 100644 --- a/src/csharp/Pester/Tracing/ITracer.cs +++ b/src/csharp/Pester/Tracing/ITracer.cs @@ -1,4 +1,6 @@ -using System.Management.Automation; +// Copied from Profiler module, branch: Fix-error-autodetection, commit: 150bbcf Fix error autodetection + +using System.Management.Automation; using System.Management.Automation.Language; # if PESTER diff --git a/src/csharp/Pester/Tracing/Tracer.cs b/src/csharp/Pester/Tracing/Tracer.cs index 526b3f696..27db03edd 100644 --- a/src/csharp/Pester/Tracing/Tracer.cs +++ b/src/csharp/Pester/Tracing/Tracer.cs @@ -1,4 +1,6 @@ -using System; +// Copied from Profiler module, branch: Fix-error-autodetection, commit: 150bbcf Fix error autodetection + +using System; using System.Management.Automation; using System.Management.Automation.Host; using System.Management.Automation.Language; @@ -77,7 +79,8 @@ private static void EnsureTracingWasNotCorrupted() // the only line that is allowed to do that is $corruptionAutodetectionVariable = Set-PSDebug -Trace 0 // This line should be the second to last line that was executed. We re-enable the trace in Profiler, so the last line (::Unregister or ::Unpatch) is // captured even when tracing is broken by user. - var corrupted = LastTraceItem.Extent?.Text != null && LastTraceItem.Extent.Text != "$corruptionAutodetectionVariable = Set-PSDebug -Trace 0"; + const string autodetectionText = "$corruptionAutodetectionVariable = Set-PSDebug -Trace 0"; + var corrupted = LastTraceItem.Extent?.Text != null && !LastTraceItem.Extent.Text.Equals(autodetectionText, StringComparison.OrdinalIgnoreCase); if (corrupted) { throw new InvalidOperationException($"Trace was broken by: {LastTraceItem.Extent.Text} from {LastTraceItem.Extent.File}:{LastTraceItem.Extent.StartLineNumber}"); diff --git a/src/csharp/Pester/Tracing/TracerHostUI.cs b/src/csharp/Pester/Tracing/TracerHostUI.cs index 9433c367a..2c2cc3e69 100644 --- a/src/csharp/Pester/Tracing/TracerHostUI.cs +++ b/src/csharp/Pester/Tracing/TracerHostUI.cs @@ -1,4 +1,6 @@ -using System; +// Copied from Profiler module, branch: Fix-error-autodetection, commit: 150bbcf Fix error autodetection + +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Management.Automation; diff --git a/src/csharp/Sync-WithProfiler.ps1 b/src/csharp/Sync-WithProfiler.ps1 new file mode 100644 index 000000000..d17e69efc --- /dev/null +++ b/src/csharp/Sync-WithProfiler.ps1 @@ -0,0 +1,28 @@ +# Copies shared csharp files from Profiler module, which is expected to be +# in a folder named Profiler next to Pester repo folder. + +$ErrorActionPreference = 'Stop' +$profilerPath = "$PSScriptRoot\..\..\..\Profiler" + +if (-not (Test-Path $profilerPath)) { + throw "Profiler module not found at '$profilerPath'." +} + + +$commit = git -C $profilerPath log --format="%h %B" -n 1 +$branch = git -C $profilerPath branch --show-current +$profilerSources = "$profilerPath\csharp\Profiler" +$pesterSources = "$PSScriptRoot\Pester\Tracing\" +$names = @( + "ExternalTracerAdapter.cs" + "ITracer.cs" + "Tracer.cs" + "TracerHostUI.cs" +) +foreach ($name in $names ) { + $destination = "$pesterSources\$name" + Copy-Item -Path "$profilerSources\$name" -Destination $destination -Force + $content = Get-Content $destination -Raw + $n = [System.Environment]::NewLine + ("// Copied from Profiler module, branch: $branch, commit: $commit$n$n" + $content) | Set-Content $destination -NoNewline +}