Code cleanup for Get-Content to make -Head and -Tail disallow negative values (#19715)

This commit is contained in:
CarloToso
2023-06-21 09:35:18 -07:00
committed by GitHub
parent bdf21cc448
commit cb2848c19b
2 changed files with 76 additions and 107 deletions
@@ -72,6 +72,14 @@ Describe "Get-Content" -Tags "CI" {
Get-Content -Path $testPath2 -Last 1 | Should -BeExactly $fifthline
}
It 'Verifies -TotalCount reports a ParameterArgumentValidationError error for negative values' {
{Get-Content -Path $testPath2 -TotalCount -2} | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetContentCommand'
}
It 'Verifies -Tail reports a ParameterArgumentValidationError error for negative values' {
{Get-Content -Path $testPath2 -Tail -2} | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetContentCommand'
}
It "Should be able to get content within a different drive" {
Push-Location env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
@@ -271,6 +279,10 @@ Describe "Get-Content" -Tags "CI" {
Get-Content -Path $testPath -TotalCount 0 | Should -BeNullOrEmpty
}
It "Should return no content when -Tail value is 0" {
Get-Content -Path $testPath -Tail 0 | Should -BeNullOrEmpty
}
It "Should throw TailAndHeadCannotCoexist when both -Tail and -TotalCount are used" {
{
Get-Content -Path $testPath -Tail 1 -TotalCount 1 -ErrorAction Stop