Skip to content

Commit

Permalink
Make Invoke-Formatter cleanup its state in the same way as Invoke-Scr…
Browse files Browse the repository at this point in the history
…iptAnalyzer does to avoid knock on effect on Invoke-ScriptAnalyzer when Invoke-Formatter is being called (#1121)
  • Loading branch information
bergmeister authored Jan 12, 2019
1 parent d0aa363 commit c62b8b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Engine/Commands/InvokeFormatterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ protected override void ProcessRecord()
this.WriteObject(formattedScriptDefinition);
}

protected override void EndProcessing()
{
ScriptAnalyzer.Instance.CleanUp();
base.EndProcessing();
}

protected override void StopProcessing()
{
ScriptAnalyzer.Instance.CleanUp();
base.StopProcessing();
}

private void ValidateInputSettings()
{
// todo implement this
Expand Down
11 changes: 9 additions & 2 deletions Tests/Engine/InvokeFormatter.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ $testRootDirectory = Split-Path -Parent $directory
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")

Describe "Invoke-Formatter Cmdlet" {
Context "Cmdlet cleans up and has no knock on effect" {
It "Invoke-Formatter has knock on effect on Invoke-ScriptAnalyzer" {
Invoke-Formatter 'foo'
Invoke-ScriptAnalyzer -ScriptDefinition 'gci' | Should -Not -BeNullOrEmpty
}
}

Context "When positional parameters are given" {
It "Should use the positional parameters" {
$def = @"
Expand Down Expand Up @@ -30,12 +37,12 @@ function foo {
}

It "Should not expand unary operators when being used as a single negative argument" {
$script = '$foo.bar(-$a)'
$script = '$foo.bar(-$a)'
Invoke-Formatter '$foo.bar(-$a)' -Settings CodeFormatting | Should -Be $script
}

It "Should expand unary operators when not being used as a single negative argument" {
Invoke-Formatter '$foo.bar(-$a+$b+$c)' -Settings CodeFormatting | Should -Be '$foo.bar(-$a + $b + $c)'
Invoke-Formatter '$foo.bar(-$a+$b+$c)' -Settings CodeFormatting | Should -Be '$foo.bar(-$a + $b + $c)'
}
}

Expand Down

0 comments on commit c62b8b2

Please sign in to comment.