Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Content -Head and -Tail disallow negative values and cleanup #19715

Merged
merged 15 commits into from
Jun 21, 2023
Prev Previous commit
Next Next commit
Add Tests
  • Loading branch information
CarloToso committed Jun 9, 2023
commit 434dfe8b676b44a225589926e80ccc6a52958e52
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
Loading