mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add new tests for Get-ChildItem (FileSystemProvider) (#11602)
This commit is contained in:
@@ -570,11 +570,26 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
|
||||
$ci[1].Name | Should -MatchExactly $filenamePattern
|
||||
$ci[2].Name | Should -MatchExactly $filenamePattern
|
||||
}
|
||||
It "Get-ChildItem -Name gets content of linked-to directory" {
|
||||
# The test depends on the files created in previous test:
|
||||
#$filenamePattern = "AlphaFile[12]\.txt"
|
||||
#New-Item -ItemType SymbolicLink -Path $alphaLink -Value $alphaDir
|
||||
$ci = Get-ChildItem $alphaLink -Name
|
||||
$ci.Count | Should -Be 3
|
||||
$ci[1] | Should -MatchExactly $filenamePattern
|
||||
$ci[2] | Should -MatchExactly $filenamePattern
|
||||
}
|
||||
It "Get-ChildItem does not recurse into symbolic links not explicitly given on the command line" {
|
||||
New-Item -ItemType SymbolicLink -Path $betaLink -Value $betaDir
|
||||
$ci = Get-ChildItem $alphaLink -Recurse
|
||||
$ci.Count | Should -BeExactly 7
|
||||
}
|
||||
It "Get-ChildItem -Name does not recurse into symbolic links not explicitly given on the command line" -Pending {
|
||||
# The test depends on the files created in previous test:
|
||||
#New-Item -ItemType SymbolicLink -Path $betaLink -Value $betaDir
|
||||
$ci = Get-ChildItem $alphaLink -Recurse -Name
|
||||
$ci.Count | Should -BeExactly 7 # returns 10 - unexpectly recurce in link-alpha\link-Beta. See https://github.com/PowerShell/PowerShell/issues/11614
|
||||
}
|
||||
It "Get-ChildItem will recurse into symlinks given -FollowSymlink, avoiding link loops" {
|
||||
New-Item -ItemType Directory -Path $gammaDir
|
||||
New-Item -ItemType SymbolicLink -Path $uponeLink -Value $betaDir
|
||||
@@ -584,6 +599,16 @@ Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows"
|
||||
$ci.Count | Should -BeExactly 13
|
||||
$w.Count | Should -BeExactly 3
|
||||
}
|
||||
It "Get-ChildItem -Name will recurse into symlinks given -FollowSymlink, avoiding link loops" -Pending {
|
||||
# The test depends on the files created in previous test:
|
||||
# New-Item -ItemType Directory -Path $gammaDir
|
||||
# New-Item -ItemType SymbolicLink -Path $uponeLink -Value $betaDir
|
||||
# New-Item -ItemType SymbolicLink -Path $uptwoLink -Value $alphaDir
|
||||
# New-Item -ItemType SymbolicLink -Path $omegaLink -Value $omegaDir
|
||||
$ci = Get-ChildItem -Path $alphaDir -FollowSymlink -Recurse -WarningVariable w -WarningAction SilentlyContinue -Name # unexpectly dead cycle. See https://github.com/PowerShell/PowerShell/issues/11614
|
||||
$ci.Count | Should -BeExactly 13
|
||||
$w.Count | Should -BeExactly 3
|
||||
}
|
||||
}
|
||||
|
||||
Context "Remove-Item and hard/symbolic links" {
|
||||
|
||||
+653
@@ -0,0 +1,653 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
Describe "Extended FileSystem Provider Tests for Get-ChildItem cmdlet" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$restoreLocation = Get-Location
|
||||
|
||||
$DirSep = [IO.Path]::DirectorySeparatorChar
|
||||
|
||||
$rootDir = Join-Path "TestDrive:" "TestDir"
|
||||
New-Item -Path $rootDir -ItemType Directory > $null
|
||||
|
||||
Set-Location $rootDir
|
||||
|
||||
New-Item -Path "file1.txt" -ItemType File > $null
|
||||
(New-Item -Path "filehidden1.doc" -ItemType File).Attributes = "Hidden"
|
||||
(New-Item -Path "filereadonly1.asd" -ItemType File).Attributes = "ReadOnly"
|
||||
|
||||
New-Item -Path "subDir2" -ItemType Directory > $null
|
||||
Set-Location "subDir2"
|
||||
New-Item -Path "file2.txt" -ItemType File > $null
|
||||
(New-Item -Path "filehidden2.asd" -ItemType File).Attributes = "Hidden"
|
||||
(New-Item -Path "filereadonly2.doc" -ItemType File).Attributes = "ReadOnly"
|
||||
(New-Item -Path "subDir21" -ItemType Directory).Attributes = "Hidden"
|
||||
Set-Location "subDir21"
|
||||
New-Item -Path "file21.txt" -ItemType File > $null
|
||||
|
||||
Set-Location $rootDir
|
||||
New-Item -Path "subDir3" -ItemType Directory > $null
|
||||
Set-Location "subDir3"
|
||||
New-Item -Path "file3.asd" -ItemType File > $null
|
||||
(New-Item -Path "filehidden3.txt" -ItemType File).Attributes = "Hidden"
|
||||
(New-Item -Path "filereadonly3.doc" -ItemType File).Attributes = "ReadOnly"
|
||||
|
||||
Set-Location $rootDir
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
#restore the previous location
|
||||
Set-Location -Path $restoreLocation
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path' {
|
||||
It "Get-ChildItem -Path" {
|
||||
$result = Get-ChildItem -Path $rootDir
|
||||
$result.Count | Should -Be 4
|
||||
$result[0] | Should -BeOfType System.IO.DirectoryInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Attribute Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Attributes Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Force
|
||||
$result.Count | Should -Be 5
|
||||
$result.Name | Should -Contain "filehidden1.doc"
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Directory/-File' {
|
||||
It "Get-ChildItem -Path -Directory" {
|
||||
$result = Get-ChildItem -Path $rootDir -Directory
|
||||
$result.Count | Should -Be 2
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -File" {
|
||||
$result = Get-ChildItem -Path $rootDir -File
|
||||
$result.Count | Should -Be 2
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -File -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -File -Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Name' {
|
||||
It "Get-ChildItem -Path -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Name
|
||||
$result.Count | Should -Be 4
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Name -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Name -Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.String
|
||||
$result | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Name -Attributes Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Name -Attributes Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.String
|
||||
$result | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Name -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Name -Force
|
||||
$result.Count | Should -Be 5
|
||||
$result | Should -BeOfType System.String
|
||||
$result | Should -Contain "filehidden1.doc"
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Directory -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Directory -Name
|
||||
$result.Count | Should -Be 2
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -File -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -File -Name
|
||||
$result.Count | Should -Be 2
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -File -Name -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -File -Name -Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.String
|
||||
$result | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Recurse' {
|
||||
It "Get-ChildItem -Path -Recurse" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse
|
||||
$result.Count | Should -Be 8
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Hidden
|
||||
$result.Count | Should -Be 4
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc"}) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "subDir21" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Attributes Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Attributes Hidden
|
||||
$result.Count | Should -Be 4
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" })| Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "subDir21" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Force
|
||||
$result.Count | Should -Be 13
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "subDir21" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Directory" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Directory
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir2" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir3" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -File" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -File
|
||||
$result.Count | Should -Be 6
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -File -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -File -Hidden
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Depth' {
|
||||
It "Get-ChildItem -Path -Depth 0" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 0
|
||||
$result.Count | Should -Be 4
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 0 -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 0 -Force
|
||||
$result.Count | Should -Be 5
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 1" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 1
|
||||
$result.Count | Should -Be 8
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 1 -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 1 -Force
|
||||
$result.Count | Should -Be 12
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 2" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 2
|
||||
$result.Count | Should -Be 8
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 2 -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 2 -Force
|
||||
$result.Count | Should -Be 13
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Recurse -Name' {
|
||||
It "Get-ChildItem -Path -Recurse -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name
|
||||
$result.Count | Should -Be 8
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -Hidden
|
||||
$result.Count | Should -Be 4
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "filehidden1.doc" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filehidden2.asd" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" }) | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -Force
|
||||
$result.Count | Should -Be 13
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "filehidden1.doc" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filehidden2.asd" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" }) | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -Directory" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -Directory
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir3" }) | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -Attributes Directory" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -Attributes Directory
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir3" }) | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -File" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -File
|
||||
$result.Count | Should -Be 6
|
||||
$result | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Recurse -Name -File -Hidden" {
|
||||
$result = Get-ChildItem -Path $rootDir -Recurse -Name -File -Hidden
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "filehidden1.doc" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filehidden2.asd" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" }) | Should -BeOfType System.String
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Depth -Name' {
|
||||
It "Get-ChildItem -Path -Depth 0 -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 0 -Name
|
||||
$result.Count | Should -Be 4
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 0 -Name -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 0 -Name -Force
|
||||
$result.Count | Should -Be 5
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 1 -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 1 -Name
|
||||
$result.Count | Should -Be 8
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 1 -Name -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 1 -Name -Force
|
||||
$result.Count | Should -Be 12
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 2 -Name" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 2 -Name
|
||||
$result.Count | Should -Be 8
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It "Get-ChildItem -Path -Depth 2 -Name -Force" {
|
||||
$result = Get-ChildItem -Path $rootDir -Depth 2 -Name -Force
|
||||
$result.Count | Should -Be 13
|
||||
$result[0] | Should -BeOfType System.String
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Filter' {
|
||||
It 'Get-ChildItem -Path -Filter "*.txt"' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "*.txt"
|
||||
$result.Count | Should -Be 1
|
||||
$result[0] | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "file1.txt"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*"' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*"
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filereadonly1.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file?.txt"' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file?.txt"
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "file1.txt"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Hidden' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Hidden
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "filehidden1.doc"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Force
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filereadonly1.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Filter -Recurse' {
|
||||
It 'Get-ChildItem -Path -Filter "*.txt" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "*.txt" -Recurse
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file2.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Recurse
|
||||
$result.Count | Should -Be 6
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filereadonly1.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file2.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filereadonly2.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file3.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filereadonly3.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file?.*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file?.*" -Recurse
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file2.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file3.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path $rootDir -Filter "file*" -Hidden -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Hidden -Recurse
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path $rootDir -Filter "file*" -Force -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Force -Recurse
|
||||
$result.Count | Should -Be 10
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Filter -Recurse -Name' {
|
||||
It 'Get-ChildItem -Path -Filter "*.txt" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "*.txt" -Recurse -Name
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Recurse -Name
|
||||
$result.Count | Should -Be 6
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "filereadonly1.asd" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filereadonly2.doc" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)file3.asd" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filereadonly3.doc" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file????only3.*" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file????only3.*" -Recurse -Name
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.String
|
||||
$result | Should -BeExactly "subDir3$($DirSep)filereadonly3.doc"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Hidden -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Hidden -Recurse -Name
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "filehidden1.doc" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filehidden2.asd" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Filter "file*" -Force -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Filter "file*" -Force -Recurse -Name
|
||||
$result.Count | Should -Be 10
|
||||
$result | Should -BeOfType System.String
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Include' {
|
||||
It 'Get-ChildItem -Path $-Include "*.txt"' -Pending:$true { # Pending due to a bug
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt"
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "file1.txt"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.txt" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt" -Recurse
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file2.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.txt" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt" -Recurse -Name
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -BeOfType System.String
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.t?t" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.t?t" -Recurse -Name
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -BeOfType System.String
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Include' {
|
||||
It 'Get-ChildItem -Path -Include "*.txt" -Force' -Pending:$true { # Pending due to a bug
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt" -Force
|
||||
$result.Count | Should -Be 1
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Name | Should -BeExactly "file1.txt"
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.txt" -Recurse -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt" -Recurse -Force
|
||||
$result.Count | Should -Be 4
|
||||
$result | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file1.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file2.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "file21.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden3.txt" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.txt" -Recurse -Name -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.txt" -Recurse -Name -Force
|
||||
$result.Count | Should -Be 4
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21$($DirSep)file21.txt" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Include "*.t?t" -Recurse -Name -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Include "*.t?t" -Recurse -Name -Force
|
||||
$result.Count | Should -Be 4
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "file1.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)file2.txt" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3$($DirSep)filehidden3.txt" } ) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21$($DirSep)file21.txt" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Exclude' {
|
||||
It 'Get-ChildItem -Path $rootDir -Exclude "*.txt"' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt"
|
||||
$result.Count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path $rootDir -Exclude "file*"' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "file*"
|
||||
$result.Count | Should -Be 2
|
||||
$result | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir2" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir3" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Recurse
|
||||
$result.Count | Should -Be 6
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.tx?" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.tx?" -Recurse
|
||||
$result.Count | Should -Be 6
|
||||
$result.Where({ $_.Name -like "*.tx?" }) | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Recurse -Name
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Count | Should -Be 6
|
||||
$result.Where({ $_ -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Recurse -Hidden' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Recurse -Hidden
|
||||
$result.Count | Should -Be 3
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -eq "filehidden1.doc" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "filehidden2.asd" }) | Should -BeOfType System.IO.FileInfo
|
||||
$result.Where({ $_.Name -eq "subDir21" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Recurse -Hidden -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Recurse -Hidden -Name
|
||||
$result.Count | Should -Be 3
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "filehidden1.doc" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)filehidden2.asd" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Include "file*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Include "file*" -Recurse
|
||||
$result.Count | Should -Be 4
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "file*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Exclude -Force' {
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Force
|
||||
$result.Count | Should -Be 4
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "file*" -Recurse -Force' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "file*" -Recurse -Force
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir2" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir3" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
$result.Where({ $_.Name -eq "subDir21" }) | Should -BeOfType System.IO.DirectoryInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "file*" -Force -Recurse -Name' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "file*" -Force -Recurse -Name
|
||||
$result.Count | Should -Be 3
|
||||
$result | Should -BeOfType System.String
|
||||
$result.Where({ $_ -eq "subDir2" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir3" }) | Should -Not -BeNullOrEmpty
|
||||
$result.Where({ $_ -eq "subDir2$($DirSep)subDir21" }) | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Recurse
|
||||
$result.Count | Should -Be 6
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Force -Include "file*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Force -Include "file*" -Recurse
|
||||
$result.Count | Should -Be 6
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "file*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Validate Get-ChildItem -Path -Exclude/-Include with some filters' {
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt","*.asd" -Force -Include "file*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt","*.asd" -Force -Include "file*" -Recurse
|
||||
$result.Count | Should -Be 3
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "*.asd" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "file*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt","*.asd" -Include "file*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt","*.asd" -Include "file*" -Recurse
|
||||
$result.Count | Should -Be 2
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "*.asd" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "file*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Force -Include "*2.*","*3.*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Force -Include "*2.*","*3.*" -Recurse
|
||||
$result.Count | Should -Be 4
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "*2.*" -or $_.Name -like "*3.*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
|
||||
It 'Get-ChildItem -Path -Exclude "*.txt" -Include "*2.*","*3.*" -Recurse' {
|
||||
$result = Get-ChildItem -Path $rootDir -Exclude "*.txt" -Include "*2.*","*3.*" -Recurse
|
||||
$result.Count | Should -Be 3
|
||||
$result.Where({ $_.Name -like "*.txt" }) | Should -BeNullOrEmpty
|
||||
$result.Where({ $_.Name -like "*2.*" -or $_.Name -like "*3.*" }) | Should -BeOfType System.IO.FileInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user