Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Dispose()
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "Milliseconds", ValueFromPipelineByPropertyName = true)]
[ValidateRangeAttribute(0, int.MaxValue)]
[Alias("ms")]
public int Milliseconds { get; set; }

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ Describe "Start-Sleep DRT Unit Tests" -Tags "CI" {
Start-Sleep -Seconds 1
$watch.Stop()
$watch.ElapsedMilliseconds | Should BeGreaterThan 950
$watch.ElapsedMilliseconds | Should BeLessThan 1050
}

It "Should work properly when sleeping with Milliseconds" {
$watch = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Milliseconds 1000
$watch.Stop()
$watch.ElapsedMilliseconds | Should BeGreaterThan 950
$watch.ElapsedMilliseconds | Should BeLessThan 1050
}

It "Should work properly when sleeping with ms alias" {
$watch = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -ms 1000
$watch.Stop()
$watch.ElapsedMilliseconds | Should BeGreaterThan 950
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you should also make sure it's less than 1050

Copy link
Collaborator

@iSazonov iSazonov Jun 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test parameter aliases? It seems it is a general feature and we should test the feature in special tests but not every cmdlet and every alias.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should validate the alias is correct, but shouldn't repeat every test for the parameter and its alias. -ms is a pretty simple case, so it's hard to not repeat the test (using -TestCases is probably better here). For parameters with more complex behavior, I think it would be sufficient if some cases used the parameter while others used the alias.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iSazonov - As a matter of principle - we avoid testing the parameter binder in cmdlet specific tests.

Personally I don't ask for any tests for an alias - the test isn't covering any new code, but I understand the concerns of those asking for the test, so I don't complain about it either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're worried about parameter's aliases, we could make a common test for all of them, just like we did for the cmdlets and their aliases as < cmdlet, parameter, alias, platform(?) >.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big problem, people mostly never remove code anyway and if they did, it should be caught during the PR, but it's a nice idea.

$watch.ElapsedMilliseconds | Should BeLessThan 1050
}
}

Expand Down