Skip to content

Commit

Permalink
Add sync script and sync
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd committed May 27, 2024
1 parent 1f68386 commit e995c3f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/csharp/Pester/Tracing/ExternalTracerAdapter.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/csharp/Pester/Tracing/ITracer.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/csharp/Pester/Tracing/Tracer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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}");
Expand Down
4 changes: 3 additions & 1 deletion src/csharp/Pester/Tracing/TracerHostUI.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/csharp/Sync-WithProfiler.ps1
Original file line number Diff line number Diff line change
@@ -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)) {

Check warning

Code scanning / PSScriptAnalyzer

Unsafe call to 'Test-Path' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1. Warning

Unsafe call to 'Test-Path' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1.
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

Check warning

Code scanning / PSScriptAnalyzer

Unsafe call to 'Get-Content' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1. Warning

Unsafe call to 'Get-Content' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1.
$n = [System.Environment]::NewLine
("// Copied from Profiler module, branch: $branch, commit: $commit$n$n" + $content) | Set-Content $destination -NoNewline

Check warning

Code scanning / PSScriptAnalyzer

Unsafe call to 'Set-Content' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1. Warning

Unsafe call to 'Set-Content' found. Pester module defines a $SafeCommands dictionary for external commands to avoid hijacking. To fix a violation of this rule, update the call to use SafeCommands-variant, ex. & $SafeCommands['CommandName'] -Param1 Value1.
}

0 comments on commit e995c3f

Please sign in to comment.