1- $ErrorActionPreference = ' Stop'
1+ using namespace System.IO
2+ using namespace System.Linq
23
3- $moduleName = (Get-Item ([IO.Path ]::Combine($PSScriptRoot , ' ..' , ' module' , ' *.psd1' ))).BaseName
4- $manifestPath = [IO.Path ]::Combine($PSScriptRoot , ' ..' , ' output' , $moduleName )
4+ $ErrorActionPreference = ' Stop'
5+
6+ $moduleName = (Get-Item ([Path ]::Combine($PSScriptRoot , ' ..' , ' module' , ' *.psd1' ))).BaseName
7+ $manifestPath = [Path ]::Combine($PSScriptRoot , ' ..' , ' output' , $moduleName )
58
69Import-Module $manifestPath
7- Import-Module ([System.IO. Path ]::Combine($PSScriptRoot , ' shared.psm1' ))
10+ Import-Module ([Path ]::Combine($PSScriptRoot , ' shared.psm1' ))
811
912Describe ' Get-PSTree' {
1013 BeforeAll {
@@ -33,7 +36,7 @@ Describe 'Get-PSTree' {
3336 $newFolder
3437 New-Item @fileSplat
3538 } | ForEach-Object {
36- $_.Attributes = $_.Attributes -bor [System.IO. FileAttributes ]::Hidden
39+ $_.Attributes = $_.Attributes -bor [FileAttributes ]::Hidden
3740 }
3841 }
3942
@@ -109,9 +112,9 @@ Describe 'Get-PSTree' {
109112 $exclude = ' *tools*' , ' *build*' , ' *.ps1'
110113 Get-PSTree $testPath - Exclude * | Should - HaveCount 1
111114 Get-PSTree $testPath - Exclude $exclude - Recurse | ForEach-Object {
112- [System.Linq. Enumerable ]::Any(
115+ [Enumerable ]::Any(
113116 [string []] $exclude ,
114- [System. Func [string , bool ]] { $_.Name -like $args [0 ] })
117+ [Func [string , bool ]] { $_.Name -like $args [0 ] })
115118 } | Should -Not - BeTrue
116119
117120 Get-ChildItem $testPath - Filter * .ps1 - Recurse |
@@ -122,9 +125,9 @@ Describe 'Get-PSTree' {
122125 It ' Includes child items with -Include parameter' {
123126 $include = ' *.ps1' , ' *.cs'
124127 Get-PSTree $testPath - Include $include - Recurse | ForEach-Object {
125- [System.Linq. Enumerable ]::Any(
128+ [Enumerable ]::Any(
126129 [string []] $include ,
127- [System. Func [string , bool ]] {
130+ [Func [string , bool ]] {
128131 $_.Name -like $args [0 ] -or $_ -is [PSTree.TreeDirectory ]
129132 }
130133 )
@@ -176,4 +179,23 @@ Describe 'Get-PSTree' {
176179 $testHiddenFolder | Get-PSTree - Recurse - Force |
177180 Should - HaveCount 21
178181 }
182+
183+ It ' Should be able to Cancel the cmdlet' {
184+ Measure-Command {
185+ $ps = [powershell ]::Create().AddScript({
186+ Import-Module $args [0 ]
187+
188+ $roots = Get-PSDrive |
189+ Where-Object { $_.Provider.Name -eq ' FileSystem' } |
190+ ForEach-Object Root
191+
192+ Get-PSTree $roots - Recurse - ErrorAction SilentlyContinue
193+ }).AddArgument($manifestPath )
194+
195+ $task = $ps.BeginInvoke ()
196+ Start-Sleep 0.5
197+ $ps.Stop ()
198+ try { $ps.EndInvoke ($task ) } catch { }
199+ } | Should - BeLessThan ([timespan ] ' 00:00:01' )
200+ }
179201}
0 commit comments