/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/powershell/Modules/Microsoft.PowerShell.Utility/string.tests.ps1
79 строк
3 KB
xtqqczze
Use correct casing for cmdlet name and cmdlet parameter name in *.ps1 files (#12584)
07 май 2020, 15:00
Не верифицирован
07 май 2020, 15:00
f438220
Код
Авторство
О чём код?
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. 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("\", "\.\") $subDirName = Join-Path $TestDrive 'selectSubDir' New-Item -Path $subDirName -ItemType Directory -Force > $null $pathWithoutWildcard = $TestDrive $pathWithWildcard = Join-Path $TestDrive '*' # Here Get-ChildItem adds 'PSDrive' property $tempFile = New-TemporaryFile | Get-Item "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 "Select-String does not throw on subdirectory (path without wildcard)" { { Select-String -Path $pathWithoutWildcard "noExists" -ErrorAction Stop } | Should -Not -Throw } It "Select-String does not throw on subdirectory (path with wildcard)" { { Select-String -Path $pathWithWildcard "noExists" -ErrorAction Stop } | Should -Not -Throw } 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:(!$IsWindows) { (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 } } }