From ad5957e6c2015ad778244b38310cf725da073733 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Tue, 23 May 2023 18:59:41 +0200 Subject: [PATCH 01/15] TotalCount {get; set;} --- .../commands/management/GetContentCommand.cs | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index f2e4598c1bc..96d80401061 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -35,22 +35,9 @@ public class GetContentCommand : ContentCommandBase /// value is -1 which means read all the content. /// [Parameter(ValueFromPipelineByPropertyName = true)] + [ValidateRange(0, long.MaxValue)] [Alias("First", "Head")] - public long TotalCount - { - get - { - return _totalCount; - } - - set - { - _totalCount = value; - _totalCountSpecified = true; - } - } - - private bool _totalCountSpecified = false; + public long TotalCount { get; set; } = -1; /// /// The number of content items to retrieve from the back of the file. @@ -98,15 +85,6 @@ internal override object GetDynamicParameters(CmdletProviderContext context) #endregion Parameters - #region parameter data - - /// - /// The number of content items to retrieve. - /// - private long _totalCount = -1; - - #endregion parameter data - #region Command code /// @@ -116,7 +94,7 @@ protected override void ProcessRecord() { // TotalCount and Tail should not be specified at the same time. // Throw out terminating error if this is the case. - if (_totalCountSpecified && _tailSpecified) + if (TotalCount != -1 && _tailSpecified) { string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail"); ErrorRecord error = new(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null); @@ -209,7 +187,7 @@ protected override void ProcessRecord() // I am using TotalCount - countToRead so that I don't // have to worry about overflow - if ((TotalCount > 0) && (countToRead == 0 || (TotalCount - countToRead < countRead))) + if (TotalCount > 0 && (countToRead == 0 || TotalCount - countToRead < countRead)) { countToRead = TotalCount - countRead; } @@ -256,7 +234,7 @@ protected override void ProcessRecord() WriteContentObject(results, countRead, holder.PathInfo, currentContext); } } - } while (results != null && results.Count > 0 && ((TotalCount < 0) || countRead < TotalCount)); + } while (results != null && results.Count > 0 && (TotalCount < 0 || countRead < TotalCount)); } } } From fdf33353fb84013e3bc9fe8c0222d9a522c6f7e7 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Tue, 23 May 2023 19:03:58 +0200 Subject: [PATCH 02/15] Tail { get; set; } --- .../commands/management/GetContentCommand.cs | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 96d80401061..3bbf57ddef1 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -43,23 +43,9 @@ public class GetContentCommand : ContentCommandBase /// The number of content items to retrieve from the back of the file. /// [Parameter(ValueFromPipelineByPropertyName = true)] + [ValidateRange(0, int.MaxValue)] [Alias("Last")] - public int Tail - { - get - { - return _backCount; - } - - set - { - _backCount = value; - _tailSpecified = true; - } - } - - private int _backCount = -1; - private bool _tailSpecified = false; + public int Tail { get; set; } = -1; /// /// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets @@ -94,7 +80,7 @@ protected override void ProcessRecord() { // TotalCount and Tail should not be specified at the same time. // Throw out terminating error if this is the case. - if (TotalCount != -1 && _tailSpecified) + if (TotalCount != -1 && Tail != -1) { string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail"); ErrorRecord error = new(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null); @@ -123,7 +109,7 @@ protected override void ProcessRecord() holder.Reader != null, "All holders should have a reader assigned"); - if (_tailSpecified && holder.Reader is not FileSystemContentReaderWriter) + if (Tail != -1 && holder.Reader is not FileSystemContentReaderWriter) { string errMsg = SessionStateStrings.GetContent_TailNotSupported; ErrorRecord error = new(new InvalidOperationException(errMsg), "TailNotSupported", ErrorCategory.InvalidOperation, Tail); From 055da9fe05653f7071b3483bdc28b07cb1260e01 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Wed, 24 May 2023 10:08:26 +0200 Subject: [PATCH 03/15] Add comment Tail --- .../commands/management/GetContentCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 3bbf57ddef1..4bb6a8d01e9 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -41,6 +41,7 @@ public class GetContentCommand : ContentCommandBase /// /// The number of content items to retrieve from the back of the file. + /// By default this value is -1 which means read all the content. /// [Parameter(ValueFromPipelineByPropertyName = true)] [ValidateRange(0, int.MaxValue)] From fe599960d2e053b36a8db8d7ec3cf3cd4d594b29 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Wed, 24 May 2023 10:19:34 +0200 Subject: [PATCH 04/15] add {} while, for --- .../commands/management/GetContentCommand.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 4bb6a8d01e9..1de853f283c 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -314,7 +314,9 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext { // Write out the content as single object while (tailResultQueue.Count > 0) + { WriteContentObject(tailResultQueue.Dequeue(), count++, holder.PathInfo, currentContext); + } } else // ReadCount < Queue.Count { @@ -322,7 +324,10 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext { var outputList = new List((int)ReadCount); for (int idx = 0; idx < ReadCount; idx++, count++) + { outputList.Add(tailResultQueue.Dequeue()); + } + // Write out the content as an array of objects WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext); } From 19ba389ddd631e4be87ae6a38e4b3186077be903 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Wed, 24 May 2023 10:36:21 +0200 Subject: [PATCH 05/15] remove remainder --- .../commands/management/GetContentCommand.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 1de853f283c..7686b6af2bb 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -332,8 +332,7 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext); } - int remainder = tailResultQueue.Count; - if (remainder > 0) + if (tailResultQueue.Count > 0) { // Write out the content as an array of objects WriteContentObject(tailResultQueue.ToArray(), count, holder.PathInfo, currentContext); From 4ba3554f7ea8e36aace8243588145098fb3337f3 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Wed, 24 May 2023 10:37:24 +0200 Subject: [PATCH 06/15] Add {} if --- .../commands/management/GetContentCommand.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 7686b6af2bb..05afd6e2cd7 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -292,7 +292,10 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext foreach (object entry in results) { if (tailResultQueue.Count == Tail) + { tailResultQueue.Dequeue(); + } + tailResultQueue.Enqueue(entry); } } From f74f1e8ffccc4279c1c23d9f85ccb82ce61c8864 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Wed, 24 May 2023 11:09:22 +0200 Subject: [PATCH 07/15] remove space --- .../commands/management/GetContentCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 05afd6e2cd7..e68f5a9ab39 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -173,7 +173,6 @@ protected override void ProcessRecord() // Make sure we only ask for the amount the user wanted // I am using TotalCount - countToRead so that I don't // have to worry about overflow - if (TotalCount > 0 && (countToRead == 0 || TotalCount - countToRead < countRead)) { countToRead = TotalCount - countRead; From 4d2459bca793ecead152e54eccb0b56986ad8311 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:43:46 +0200 Subject: [PATCH 08/15] var, Logs --- .../commands/management/GetContentCommand.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index e68f5a9ab39..d9a2b969fbb 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -106,9 +106,7 @@ protected override void ProcessRecord() { long countRead = 0; - Dbg.Diagnostics.Assert( - holder.Reader != null, - "All holders should have a reader assigned"); + Dbg.Diagnostics.Assert(holder.Reader != null, "All holders should have a reader assigned"); if (Tail != -1 && holder.Reader is not FileSystemContentReaderWriter) { @@ -193,15 +191,8 @@ protected override void ProcessRecord() e); // Log a provider health event - MshLog.LogProviderHealthEvent( - this.Context, - holder.PathInfo.Provider.Name, - providerException, - Severity.Warning); - - WriteError(new ErrorRecord( - providerException.ErrorRecord, - providerException)); + MshLog.LogProviderHealthEvent(this.Context, holder.PathInfo.Provider.Name, providerException, Severity.Warning); + WriteError(new ErrorRecord(providerException.ErrorRecord, providerException)); break; } @@ -248,7 +239,7 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext { var fsReader = holder.Reader as FileSystemContentReaderWriter; Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter"); - var tailResultQueue = new Queue(); + Queue tailResultQueue = new(); IList results = null; ErrorRecord error = null; @@ -324,7 +315,7 @@ private bool ScanForwardsForTail(in ContentHolder holder, CmdletProviderContext { while (tailResultQueue.Count >= ReadCount) { - var outputList = new List((int)ReadCount); + List outputList = new((int)ReadCount); for (int idx = 0; idx < ReadCount; idx++, count++) { outputList.Add(tailResultQueue.Dequeue()); From 777d52609e9d79940715f7b82c84540ad57570e6 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:45:00 +0200 Subject: [PATCH 09/15] fast return --- .../commands/management/GetContentCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index d9a2b969fbb..58f567c043e 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -89,7 +89,7 @@ protected override void ProcessRecord() return; } - if (TotalCount == 0) + if (TotalCount == 0 || Tail == 0) { // Don't read anything return; From c60a8397658fd650e45d5c4829b5f9503840d1da Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:50:27 +0200 Subject: [PATCH 10/15] remove unnecessary if --- .../commands/management/GetContentCommand.cs | 87 +++++++++---------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 58f567c043e..e7dadca8f13 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -120,7 +120,7 @@ protected override void ProcessRecord() // 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; @@ -160,59 +160,56 @@ protected override void ProcessRecord() } } - if (TotalCount != 0) + IList results = null; + + do { - IList results = null; + long countToRead = ReadCount; - do + // Make sure we only ask for the amount the user wanted + // I am using TotalCount - countToRead so that I don't + // have to worry about overflow + if (TotalCount > 0 && (countToRead == 0 || TotalCount - countToRead < countRead)) { - long countToRead = ReadCount; + countToRead = TotalCount - countRead; + } - // Make sure we only ask for the amount the user wanted - // I am using TotalCount - countToRead so that I don't - // have to worry about overflow - if (TotalCount > 0 && (countToRead == 0 || TotalCount - countToRead < countRead)) - { - countToRead = TotalCount - countRead; - } + try + { + results = holder.Reader.Read(countToRead); + } + catch (Exception e) // Catch-all OK. 3rd party callout + { + ProviderInvocationException providerException = + new( + "ProviderContentReadError", + SessionStateStrings.ProviderContentReadError, + holder.PathInfo.Provider, + holder.PathInfo.Path, + e); - try - { - results = holder.Reader.Read(countToRead); - } - catch (Exception e) // Catch-all OK. 3rd party callout + // Log a provider health event + MshLog.LogProviderHealthEvent(this.Context, holder.PathInfo.Provider.Name, providerException, Severity.Warning); + WriteError(new ErrorRecord(providerException.ErrorRecord, providerException)); + + break; + } + + if (results != null && results.Count > 0) + { + countRead += results.Count; + if (ReadCount == 1) { - ProviderInvocationException providerException = - new( - "ProviderContentReadError", - SessionStateStrings.ProviderContentReadError, - holder.PathInfo.Provider, - holder.PathInfo.Path, - e); - - // Log a provider health event - MshLog.LogProviderHealthEvent(this.Context, holder.PathInfo.Provider.Name, providerException, Severity.Warning); - WriteError(new ErrorRecord(providerException.ErrorRecord, providerException)); - - break; + // Write out the content as a single object + WriteContentObject(results[0], countRead, holder.PathInfo, currentContext); } - - if (results != null && results.Count > 0) + else { - countRead += results.Count; - if (ReadCount == 1) - { - // Write out the content as a single object - WriteContentObject(results[0], countRead, holder.PathInfo, currentContext); - } - else - { - // Write out the content as an array of objects - WriteContentObject(results, countRead, holder.PathInfo, currentContext); - } + // Write out the content as an array of objects + WriteContentObject(results, countRead, holder.PathInfo, currentContext); } - } while (results != null && results.Count > 0 && (TotalCount < 0 || countRead < TotalCount)); - } + } + } while (results != null && results.Count > 0 && (TotalCount == -1 || countRead < TotalCount)); } } finally From c4d1b514e45fe91fef85f9d4df32ea8661f442b1 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:52:35 +0200 Subject: [PATCH 11/15] fix comment --- .../commands/management/GetContentCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index e7dadca8f13..3e6d94fa531 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -116,7 +116,7 @@ protected override void ProcessRecord() continue; } - // If Tail is negative, we are supposed to read all content out. This is same + // If Tail is -1, we are supposed to read all content out. This is same // 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. From c5729b172b912b1ca5303a7ef069afb4ec66a495 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:53:45 +0200 Subject: [PATCH 12/15] capitalize comment --- .../commands/management/GetContentCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index 3e6d94fa531..ae06eaef571 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -214,7 +214,7 @@ protected override void ProcessRecord() } finally { - // close all the content readers + // Close all the content readers CloseContent(contentStreams, false); From 174ad16be48977d05eb4ff8d78bb19b1eecb56cb Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Thu, 25 May 2023 18:55:52 +0200 Subject: [PATCH 13/15] edit comment --- .../commands/management/GetContentCommand.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs index ae06eaef571..4e83eda905f 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetContentCommand.cs @@ -31,8 +31,7 @@ public class GetContentCommand : ContentCommandBase public long ReadCount { get; set; } = 1; /// - /// The number of content items to retrieve. By default this - /// value is -1 which means read all the content. + /// The number of content items to retrieve. /// [Parameter(ValueFromPipelineByPropertyName = true)] [ValidateRange(0, long.MaxValue)] @@ -41,7 +40,6 @@ public class GetContentCommand : ContentCommandBase /// /// The number of content items to retrieve from the back of the file. - /// By default this value is -1 which means read all the content. /// [Parameter(ValueFromPipelineByPropertyName = true)] [ValidateRange(0, int.MaxValue)] From 434dfe8b676b44a225589926e80ccc6a52958e52 Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Sat, 10 Jun 2023 01:46:54 +0200 Subject: [PATCH 14/15] Add Tests --- .../Get-Content.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 index 9f42be74149..3ce3de05ada 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 @@ -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 From 727d53a3c1b00df2599280b8ab1a1d3180ef0c0a Mon Sep 17 00:00:00 2001 From: CarloToso <105941898+CarloToso@users.noreply.github.com> Date: Sat, 10 Jun 2023 02:10:53 +0200 Subject: [PATCH 15/15] Add {} --- .../Microsoft.PowerShell.Management/Get-Content.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 index 3ce3de05ada..5e8e258b85a 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1 @@ -73,11 +73,11 @@ Describe "Get-Content" -Tags "CI" { } It 'Verifies -TotalCount reports a ParameterArgumentValidationError error for negative values' { - Get-Content -Path $testPath2 -TotalCount -2 | Should -Throw -ErrorId 'ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetContentCommand' + {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' + {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" {