mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix regression -Tail 0 -Wait (#20734)
This commit is contained in:
+2
-2
@@ -87,7 +87,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (TotalCount == 0 || Tail == 0)
|
||||
if (TotalCount == 0)
|
||||
{
|
||||
// Don't read anything
|
||||
return;
|
||||
@@ -118,7 +118,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// as reading forwards. So we read forwards in this case.
|
||||
// If Tail is positive, we seek the right position. Or, if the seek failed
|
||||
// because of an unsupported encoding, we scan forward to get the tail content.
|
||||
if (Tail > 0)
|
||||
if (Tail >= 0)
|
||||
{
|
||||
bool seekSuccess = false;
|
||||
|
||||
|
||||
@@ -283,6 +283,16 @@ Describe "Get-Content" -Tags "CI" {
|
||||
Get-Content -Path $testPath -Tail 0 | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should wait for content when using -Tail 0 and -Wait" {
|
||||
$testValues = @(1,2,3)
|
||||
$Job = Start-Job -ScriptBlock {Get-Content -Path $using:testPath -Tail 0 -Wait}
|
||||
Start-Sleep -Seconds 3
|
||||
Add-Content -Value $testValues -Path $testPath
|
||||
Start-Sleep -Seconds 3
|
||||
Compare-Object -ReferenceObject $testValues -DifferenceObject ($Job | Receive-Job) | Should -BeNullOrEmpty
|
||||
$Job | Remove-Job -Force
|
||||
}
|
||||
|
||||
It "Should throw TailAndHeadCannotCoexist when both -Tail and -TotalCount are used" {
|
||||
{
|
||||
Get-Content -Path $testPath -Tail 1 -TotalCount 1 -ErrorAction Stop
|
||||
|
||||
Reference in New Issue
Block a user