Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Filter.ExcludeLine option #2016

Merged
merged 6 commits into from
Jun 27, 2021
Merged

Conversation

ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Jun 26, 2021

PR Summary

Fix #1992

I've included a Filter.ExcludeLine option.

Sample Test

Describe "block1" { #Line 1
    It "Test1" { #Line 2
        $true | Should -BeTrue
    }
    Context "block2" { #Line 5
        It "Test2" { # Line 6
            $true | Should -BeTrue
        }
        It "Test3" { #Line 9
            $true | Should -BeTrue
        }
    }
}

Setup Code

$pesterConfig = [PesterConfiguration] @{
    Run = @{
        Container = New-PesterContainer -Path C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1
    }
    Output = @{
        Verbosity = "Diagnostic"
    }
}

Test 1

Include Context block
Exclude Test2

$pesterConfig.Filter.Line = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:5"
$pesterConfig.Filter.ExcludeLine = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:6"
Invoke-Pester -Configuration $pesterConfig

Output 1

Only Test 3 is run

test1

Test 2

Include Describe, Context and Test2
Exclude Test2

$pesterConfig.Filter.Line = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:1", "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:5", "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:6"
$pesterConfig.Filter.ExcludeLine = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:6"
Invoke-Pester -Configuration $pesterConfig

Output 2

Only Test1 and Test3 are run

test2

Test 3

Include Describe
Exclude Context

$pesterConfig.Filter.Line = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:1"
$pesterConfig.Filter.ExcludeLine = "C:\Users\Armaan\Documents\powershell-dev\sample.Tests.ps1:5"
Invoke-Pester -Configuration $pesterConfig

Output 3

Only Test1 is run

test3

cc @JustinGrote

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review June 26, 2021 09:10
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Jun 26, 2021

I believe this is ready for review.

I may have gone a bit overboard on the tests, but was trying to include as many as I can to ensure this option works for different scenarios. I've also included screenshots in the description to highlight the tests cases in the linked issue, which match the behaviour that @JustinGrote is looking for.

Copy link
Contributor

@JustinGrote JustinGrote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nohwnd nohwnd merged commit a5bdc2f into pester:main Jun 27, 2021
@nohwnd
Copy link
Member

nohwnd commented Jun 27, 2021

Looks perfect.

@ArmaanMcleod ArmaanMcleod deleted the filter-exclude-line branch June 27, 2021 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Filter.ExcludeLine Option
3 participants