Skip to content

Commit 452e78a

Browse files
committed
Added test of Get-Uptime -Since:$false to Get-Uptime.Tests.ps1, reproducing the bug described in issue PowerShell#25015.
Updated the implementation in GetUptime.cs to correct the handling of explicit $false values passed to -Since, making the test pass.
1 parent d5267d2 commit 452e78a

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetUptime.cs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ protected override void ProcessRecord()
3636
{
3737
TimeSpan uptime = TimeSpan.FromSeconds(Stopwatch.GetTimestamp() / Stopwatch.Frequency);
3838

39-
switch (ParameterSetName)
39+
if (Since.ToBool())
4040
{
41-
case TimespanParameterSet:
42-
// return TimeSpan of time since the system started up
43-
WriteObject(uptime);
44-
break;
45-
case SinceParameterSet:
46-
// return Datetime when the system started up
47-
WriteObject(DateTime.Now.Subtract(uptime));
48-
break;
41+
// return Datetime when the system started up
42+
WriteObject(DateTime.Now.Subtract(uptime));
43+
}
44+
else
45+
{
46+
// return TimeSpan of time since the system started up
47+
WriteObject(uptime);
4948
}
5049
}
5150
else

‎test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Uptime.Tests.ps1‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Describe "Get-Uptime" -Tags "CI" {
2525
$upt = Get-Uptime -Since
2626
$upt | Should -BeOfType DateTime
2727
}
28+
It "Get-Uptime -Since:`$false return TimeSpan" {
29+
$upt = Get-Uptime -Since:$false
30+
$upt | Should -BeOfType TimeSpan
31+
}
2832
It "Get-Uptime throw if IsHighResolution == false" {
2933
# Enable the test hook
3034
[system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true)

0 commit comments

Comments
 (0)