forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.tests.ps1
More file actions
63 lines (50 loc) · 2.63 KB
/
Copy pathstring.tests.ps1
File metadata and controls
63 lines (50 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Describe "String cmdlets" -Tags "CI" {
Context "Select-String" {
BeforeAll {
$sep = [io.path]::DirectorySeparatorChar
$fileName = New-Item 'TestDrive:\selectStr[ingLi]teralPath.txt'
"abc" | Out-File -LiteralPath $fileName.fullname
"bcd" | Out-File -LiteralPath $fileName.fullname -Append
"cde" | Out-File -LiteralPath $fileName.fullname -Append
$fileNameWithDots = $fileName.FullName.Replace("\", "\.\")
$tempFile = New-TemporaryFile
"abc" | Out-File -LiteralPath $tempFile.fullname
"bcd" | Out-File -LiteralPath $tempFile.fullname -Append
"cde" | Out-File -LiteralPath $tempFile.fullname -Append
$driveLetter = $tempFile.PSDrive.Name
$fileNameAsNetworkPath = "\\localhost\$driveLetter`$" + $tempFile.FullName.SubString(2)
Push-Location "$fileName\.."
}
AfterAll {
Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
Pop-Location
}
It "LiteralPath with relative path" {
(select-string -LiteralPath (Get-Item -LiteralPath $fileName).Name "b").count | Should Be 2
}
It "LiteralPath with absolute path" {
(select-string -LiteralPath $fileName "b").count | Should Be 2
}
It "LiteralPath with dots in path" {
(select-string -LiteralPath $fileNameWithDots "b").count | Should Be 2
}
It "Network path" -skip:($IsCoreCLR) {
(select-string -LiteralPath $fileNameAsNetworkPath "b").count | Should Be 2
}
It "throws error for non filesystem providers" {
$aaa = "aaaaaaaaaa"
select-string -literalPath variable:\aaa "a" -ErrorAction SilentlyContinue -ErrorVariable selectStringError
$selectStringError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand'
}
It "throws parameter binding exception for invalid context" {
{ select-string It $PSScriptRoot -Context -1,-1 } | Should Throw Context
}
It "match object supports RelativePath method" {
$file = "Modules${sep}Microsoft.PowerShell.Utility${sep}Microsoft.PowerShell.Utility.psd1"
$match = Select-String CmdletsToExport $pshome/$file
$match.RelativePath($pshome) | Should Be $file
$match.RelativePath($pshome.ToLower()) | Should Be $file
$match.RelativePath($pshome.ToUpper()) | Should Be $file
}
}
}