From 70e531f843688565d2529337e7c0edf2685f2610 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 13 Feb 2016 12:57:20 -0700 Subject: [PATCH 1/2] Added problem matchers to Pester task runner. Added comments on how to use task runner to the Pester tests. --- examples/.vscode/tasks.json | 126 +++++++++++++++++++++++++++--- examples/PathProcessing.Tests.ps1 | 60 ++++++++------ 2 files changed, 152 insertions(+), 34 deletions(-) diff --git a/examples/.vscode/tasks.json b/examples/.vscode/tasks.json index 6ab2591d6f..5e25865bbf 100644 --- a/examples/.vscode/tasks.json +++ b/examples/.vscode/tasks.json @@ -1,11 +1,19 @@ -// This uses the 'taskRunnertest' tag to specify which tests to include. +// A task runner that invokes Pester which runs all Pester tests under the +// current workspace folder. + +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process -// A task runner that calls Pester for testing the current project { "version": "0.1.0", // Start PowerShell - "command": "c:\\windows\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe", + "command": "${env.windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe", // The command is a shell script "isShellCommand": true, @@ -16,16 +24,116 @@ // Allow Pester to invoke scripts and run Pester "args": [ "-NoProfile", - "Set-ExecutionPolicy -ExecutionPolicy 'RemoteSigned' -Scope 'Process';", - "write-host 'invoking Pester...';invoke-pester;", - "invoke-command {write-host \"Completed all tasks in taskRunner: $args[0]\"} -args" + "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process;", + "Write-Host 'Invoking Pester...'; Invoke-Pester;", + "Invoke-Command { Write-Host \"Completed all tasks in task runner: $($args[0])\" } -args" ], - - // Associate with test taskrunner + + // Associate with test task runner "tasks": [ { "taskName": "Pester", - "isTestCommand": true + "isTestCommand": true, + "problemMatcher": [ + { + "owner": "powershell", + "fileLocation": ["absolute"], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*\\[-\\](.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^\\s+at line: (\\d+) in (.*)$", + "line": 1, + "file": 2, + "message": 2 + } + ] + }, + { + "owner": "powershell", + "fileLocation": ["absolute"], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*\\[-\\](.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^\\s+at line: (\\d+) in (.*)$", + "line": 1, + "file": 2, + "message": 2 + } + ] + }, + { + "owner": "powershell", + "fileLocation": ["absolute"], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*\\[-\\](.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^\\s+at line: (\\d+) in (.*)$", + "line": 1, + "file": 2, + "message": 2 + } + ] + }, + { + "owner": "powershell", + "fileLocation": ["absolute"], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*\\[-\\](.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^.*$" + }, + { + "regexp": "^\\s+at line: (\\d+) in (.*)$", + "line": 1, + "file": 2, + "message": 2 + } + ] + } + ] } ] } diff --git a/examples/PathProcessing.Tests.ps1 b/examples/PathProcessing.Tests.ps1 index fd7ae4efaf..fe3326e41b 100644 --- a/examples/PathProcessing.Tests.ps1 +++ b/examples/PathProcessing.Tests.ps1 @@ -1,58 +1,68 @@ -New-Item -Path 'foo[1].txt' -Force +# These tests for the for parameter-* and ex-path* snippets. +# These tests also demonstrate how you can create a tasks.json +# file in your workspace folder's .vscode directory to easily +# run your Pester tests. See the examples\.vscode\tasks.json file. -. $PSScriptRoot\PathProcessingNonExistingPaths.ps1 -Describe 'Verify Path Processing for Non-existing Paths Allowed Impl' { +# To run these Pester tests, press Ctrl+Shift+T which will run the +# "test" task defined in .vscode\tasks.json. Or press Ctrl+Shift+P, +# type "test" and select "Tasks: Run Test Task". + +# This (empty) file is required by some of the tests. +$null = New-Item -Path 'foo[1].txt' -Force + +. $PSScriptRoot\PathProcessingNonExistingPaths.ps1 +Describe 'Verify Path Processing for Non-existing Paths Allowed Impl' { It 'Processes non-wildcard absolute path to non-existing file via -Path param' { New-File -Path $PSScriptRoot\ReadmeNew.md | Should Be "$PSScriptRoot\READMENew.md" } It 'Processes multiple absolute paths via -Path param' { - New-File -Path $PSScriptRoot\Readme.md, $PSScriptRoot\XYZZY.ps1 | + New-File -Path $PSScriptRoot\Readme.md, $PSScriptRoot\XYZZY.ps1 | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\XYZZY.ps1") - } + } It 'Processes relative path via -Path param' { New-File -Path ..\examples\READMENew.md | Should Be "$PSScriptRoot\READMENew.md" } It 'Processes multiple relative path via -Path param' { - New-File -Path ..\examples\README.md, XYZZY.ps1 | + New-File -Path ..\examples\README.md, XYZZY.ps1 | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\XYZZY.ps1") } - + It 'Should accept pipeline input to Path' { Get-ChildItem -LiteralPath "$pwd\foo[1].txt" | New-File | Should Be "$PSScriptRoot\foo[1].txt" - } + } } -. $PSScriptRoot\PathProcessingNoWildcards.ps1 -Describe 'Verify Path Processing for NO Wildcards Allowed Impl' { +. $PSScriptRoot\PathProcessingNoWildcards.ps1 +Describe 'Verify Path Processing for NO Wildcards Allowed Impl' { It 'Processes non-wildcard absolute path via -Path param' { Import-FileNoWildcard -Path $PSScriptRoot\Readme.md | Should Be "$PSScriptRoot\README.md" } It 'Processes multiple absolute paths via -Path param' { - Import-FileNoWildcard -Path $PSScriptRoot\Readme.md, $PSScriptRoot\PathProcessingWildcards.ps1 | + Import-FileNoWildcard -Path $PSScriptRoot\Readme.md, $PSScriptRoot\PathProcessingWildcards.ps1 | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\PathProcessingWildcards.ps1") - } + } It 'Processes relative path via -Path param' { Import-FileNoWildcard -Path ..\examples\README.md | Should Be "$PSScriptRoot\README.md" } It 'Processes multiple relative path via -Path param' { - Import-FileNoWildcard -Path ..\examples\README.md, .vscode\launch.json | + Import-FileNoWildcard -Path ..\examples\README.md, .vscode\launch.json | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\.vscode\launch.json") } - + It 'Should accept pipeline input to Path' { Get-ChildItem -LiteralPath "$pwd\foo[1].txt" | Import-FileNoWildcard | Should Be "$PSScriptRoot\foo[1].txt" - } + } } -. $PSScriptRoot\PathProcessingWildcards.ps1 -Describe 'Verify Path Processing for Wildcards Allowed Impl' { +. $PSScriptRoot\PathProcessingWildcards.ps1 +Describe 'Verify Path Processing for Wildcards Allowed Impl' { It 'Processes non-wildcard absolute path via -Path param' { Import-FileWildcard -Path $PSScriptRoot\Readme.md | Should Be "$PSScriptRoot\README.md" } It 'Processes multiple absolute paths via -Path param' { - Import-FileWildcard -Path $PSScriptRoot\Readme.md, $PSScriptRoot\PathProcessingWildcards.ps1 | + Import-FileWildcard -Path $PSScriptRoot\Readme.md, $PSScriptRoot\PathProcessingWildcards.ps1 | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\PathProcessingWildcards.ps1") - } + } It 'Processes wildcard absolute path via -Path param' { Import-FileWildcard -Path $PSScriptRoot\*.md | Should Be "$PSScriptRoot\README.md" } @@ -63,14 +73,14 @@ Describe 'Verify Path Processing for Wildcards Allowed Impl' { Import-FileWildcard -Path ..\examples\README.md | Should Be "$PSScriptRoot\README.md" } It 'Processes multiple relative path via -Path param' { - Import-FileWildcard -Path ..\examples\README.md, .vscode\launch.json | + Import-FileWildcard -Path ..\examples\README.md, .vscode\launch.json | Should Be @("$PSScriptRoot\README.md", "$PSScriptRoot\.vscode\launch.json") } - + It 'DefaultParameterSet should be Path' { Import-FileWildcard *.md | Should Be "$PSScriptRoot\README.md" } - + It 'Should process absolute literal paths via -LiteralPath param'{ Import-FileWildcard -LiteralPath "$PSScriptRoot\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt" } @@ -78,11 +88,11 @@ Describe 'Verify Path Processing for Wildcards Allowed Impl' { Import-FileWildcard -LiteralPath "..\examples\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt" } It 'Should process multiple literal paths via -LiteralPath param'{ - Import-FileWildcard -LiteralPath "..\examples\foo[1].txt", "$PSScriptRoot\README.md" | + Import-FileWildcard -LiteralPath "..\examples\foo[1].txt", "$PSScriptRoot\README.md" | Should Be @("$PSScriptRoot\foo[1].txt", "$PSScriptRoot\README.md") } - + It 'Should accept pipeline input to LiteralPath' { Get-ChildItem -LiteralPath "$pwd\foo[1].txt" | Import-FileWildcard | Should Be "$PSScriptRoot\foo[1].txt" - } + } } From fdfb04a23a3468736cf72f371c514e0548321735 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 13 Feb 2016 13:01:31 -0700 Subject: [PATCH 2/2] Updated test comments - more readable. --- examples/PathProcessing.Tests.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/PathProcessing.Tests.ps1 b/examples/PathProcessing.Tests.ps1 index fe3326e41b..9d5cd35b58 100644 --- a/examples/PathProcessing.Tests.ps1 +++ b/examples/PathProcessing.Tests.ps1 @@ -1,11 +1,11 @@ -# These tests for the for parameter-* and ex-path* snippets. -# These tests also demonstrate how you can create a tasks.json -# file in your workspace folder's .vscode directory to easily -# run your Pester tests. See the examples\.vscode\tasks.json file. +# These Pester tests are for the for parameter-* and ex-path* snippets. +# Take a look at the .vscode\tasks.json file to see how you can create +# and configure a test task runner that will run all the Pester tests +# in your workspace folder. -# To run these Pester tests, press Ctrl+Shift+T which will run the -# "test" task defined in .vscode\tasks.json. Or press Ctrl+Shift+P, -# type "test" and select "Tasks: Run Test Task". +# To run these Pester tests, press Ctrl+Shift+T or press Ctrl+Shift+P, +# type "test" and select "Tasks: Run Test Task". This will invoke the +# test task runner defined in .vscode\tasks.json. # This (empty) file is required by some of the tests. $null = New-Item -Path 'foo[1].txt' -Force