-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Filling test gaps (issue 2022) - this replaces PR 1834 #2023
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
Merged
daxian-dbw
merged 1 commit into
PowerShell:master
from
JamesWTruher:jameswtruher/TestGapFill-001
Aug 23, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| Describe "Job Cmdlet Tests" -Tag "CI" { | ||
| Context "Simple Jobs" { | ||
| AfterEach { | ||
| Get-Job | Remove-Job -force | ||
| } | ||
| BeforeEach { | ||
| $j = start-job -scriptblock { 1 + 1 } | ||
| } | ||
| It "Start-Job produces a job object" { | ||
| $j.gettype().fullname | should be "System.Management.Automation.PSRemotingJob" | ||
| } | ||
| It "Get-Job retrieves a job object" { | ||
| (Get-Job -id $j.id).gettype().fullname | should be "System.Management.Automation.PSRemotingJob" | ||
| } | ||
| It "Remove-Job can remove a job" { | ||
| remove-job $j -force | ||
| try { | ||
| get-job $j -ea Stop | ||
| throw "Execution OK" | ||
| } | ||
| catch { | ||
| $_.FullyQualifiedErrorId | should be "JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.GetJobCommand" | ||
| } | ||
| } | ||
| It "Receive-Job can retrieve job results" -pending { | ||
| $waitjob = Wait-Job -Timeout 10 -id $j.id | ||
| if ( $waitJob ) { | ||
| $result = receive-job -id $j.id | ||
| $result.id | Should be 2 | ||
| } | ||
| } | ||
| } | ||
| Context "jobs which take time" { | ||
| BeforeEach { | ||
| $j = start-job -scriptblock { Start-Sleep 15 } | ||
| } | ||
| AfterEach { | ||
| Get-Job | Remove-Job -force | ||
| } | ||
| It "Wait-Job will wait for a job" { | ||
| $result = wait-Job $j | ||
| $result | should be $j | ||
| } | ||
| It "Stop-Job will stop a job" -pending { | ||
| Stop-Job -id $j.id | ||
| $j.Status |Should be Stopped | ||
| } | ||
| } | ||
| } | ||
| Describe "Debug-job test" -tag "Feature" { | ||
| BeforeAll { | ||
| $rs = [runspacefactory]::CreateRunspace() | ||
| $rs.Open() | ||
| $rs.Debugger.SetDebugMode([System.Management.Automation.DebugModes]::RemoteScript) | ||
| $rs.Debugger.add_DebuggerStop({$true}) | ||
| $ps = [powershell]::Create() | ||
| $ps.Runspace = $rs | ||
| } | ||
| AfterAll { | ||
| $rs.Dispose() | ||
| $ps.Dispose() | ||
| } | ||
| # we check this via implication. | ||
| # if we're debugging a job, then the debugger will have a callstack | ||
| It "Debug-Job will break into debugger" -pending { | ||
| $ps.AddScript('$job = start-job { 1..300 | % { sleep 1 } }').Invoke() | ||
| $ps.Commands.Clear() | ||
| $ps.Runspace.Debugger.GetCallStack() | Should BeNullOrEmpty | ||
| start-sleep 3 | ||
| $asyncResult = $ps.AddScript('debug-job $job').BeginInvoke() | ||
| $ps.commands.clear() | ||
| start-sleep 2 | ||
| $result = $ps.runspace.Debugger.GetCallStack() | ||
| $result.Command | Should be "<ScriptBlock>" | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
test/powershell/Modules/Microsoft.PowerShell.Management/Clear-Item.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Describe "Clear-Item tests" -Tag "CI" { | ||
| BeforeAll { | ||
| ${myClearItemVariableTest} = "Value is here" | ||
| } | ||
| It "Clear-Item can clear an item" { | ||
| $myClearItemVariableTest | Should be "Value is here" | ||
| Clear-Item variable:myClearItemVariableTest | ||
| test-path variable:myClearItemVariableTest | should be $true | ||
| $myClearItemVariableTest | Should BeNullOrEmpty | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
test/powershell/Modules/Microsoft.PowerShell.Management/ItemProperty.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Describe "Simple ItemProperty Tests" -Tag "CI" { | ||
| It "Can retrieve the PropertyValue with Get-ItemPropertyValue" { | ||
| Get-ItemPropertyValue -path $TESTDRIVE -Name Attributes | should be "Directory" | ||
| } | ||
| It "Can clear the PropertyValue with Clear-ItemProperty" { | ||
| setup -f file1.txt | ||
| Set-ItemProperty $TESTDRIVE/file1.txt -Name Attributes -Value ReadOnly | ||
| Get-ItemPropertyValue -path $TESTDRIVE/file1.txt -Name Attributes | should match "ReadOnly" | ||
| Clear-ItemProperty $TESTDRIVE/file1.txt -Name Attributes | ||
| Get-ItemPropertyValue -path $TESTDRIVE/file1.txt -Name Attributes | should not match "ReadOnly" | ||
| } | ||
| # these cmdlets are targeted at the windows registry, and don't have an linux equivalent | ||
| Context "Registry targeted cmdlets" { | ||
| It "Copy ItemProperty" -pending { } | ||
| It "Move ItemProperty" -pending { } | ||
| It "New ItemProperty" -pending { } | ||
| It "Rename ItemProperty" -pending { } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
test/powershell/Modules/Microsoft.PowerShell.Management/Move-Item.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Describe "Move-Item tests" -Tag "CI" { | ||
| BeforeAll { | ||
| $content = "This is content" | ||
| Setup -f originalfile.txt -content "This is content" | ||
| $source = "$TESTDRIVE/originalfile.txt" | ||
| $target = "$TESTDRIVE/ItemWhichHasBeenRenamed.txt" | ||
| } | ||
| It "Rename-Item will rename a file" { | ||
| Rename-Item $source $target | ||
| test-path $source | Should be $false | ||
| test-path $target | Should be $true | ||
| "$target" | Should ContainExactly "This is content" | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
test/powershell/Modules/Microsoft.PowerShell.Management/Rename-Item.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Describe "Rename-Item tests" -Tag "CI" { | ||
| BeforeAll { | ||
| $content = "This is content" | ||
| Setup -f originalFile.txt -content "This is content" | ||
| $source = "$TESTDRIVE/originalFile.txt" | ||
| $target = "$TESTDRIVE/ItemWhichHasBeenRenamed.txt" | ||
| } | ||
| It "Rename-Item will rename a file" { | ||
| Rename-Item $source $target | ||
| test-path $source | Should be $false | ||
| test-path $target | Should be $true | ||
| "$target" | Should ContainExactly "This is content" | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
test/powershell/Modules/Microsoft.PowerShell.Management/Resolve-Path.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Describe "Resolve-Path returns proper path" -Tag "CI" { | ||
| It "Resolve-Path returns resolved paths" { | ||
| Resolve-Path $TESTDRIVE | Should be "$TESTDRIVE" | ||
| } | ||
| It "Resolve-Path handles provider qualified paths" { | ||
| $result = Resolve-Path Filesystem::$TESTDRIVE | ||
| $result.providerpath | should be "$TESTDRIVE" | ||
| } | ||
| It "Resolve-Path provides proper error on invalid location" { | ||
| try { | ||
| Resolve-Path $TESTDRIVE/this.directory.is.invalid -ea stop | ||
| throw "execution OK" | ||
| } | ||
| catch { | ||
| $_.fullyqualifiederrorid | should be "PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand" | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
test/powershell/Modules/Microsoft.PowerShell.Management/Set-Item.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| Describe "Set-Item" -Tag "CI" { | ||
| $testCases = @{ Path = "variable:SetItemTestCase"; Value = "TestData"; Validate = { $SetItemTestCase | Should be "TestData" }; Reset = {remove-item variable:SetItemTestCase} }, | ||
| @{ Path = "alias:SetItemTestCase"; Value = "Get-Alias"; Validate = { (Get-Alias SetItemTestCase).Definition | should be "Get-Alias"}; Reset = { remove-item alias:SetItemTestCase } }, | ||
| @{ Path = "function:SetItemTestCase"; Value = { 1 }; Validate = { SetItemTestCase | should be 1 }; Reset = { remove-item function:SetItemTestCase } }, | ||
| @{ Path = "env:SetItemTestCase"; Value = { 1 }; Validate = { $env:SetItemTestCase | should be 1 }; Reset = { remove-item env:SetItemTestCase } } | ||
|
|
||
| It "Set-Item should be able to handle <Path>" -TestCase $testCases { | ||
| param ( $Path, $Value, $Validate, $Reset ) | ||
| Set-item -path $path -Value $value | ||
| try { | ||
| & $Validate | ||
| } | ||
| finally { | ||
| & $reset | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
test/powershell/Modules/Microsoft.PowerShell.Security/AclCmdlets.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Describe "Acl cmdlets are available and operate properly" -Tag CI { | ||
| It "Get-Acl returns an ACL object" -pending:(!$IsWindows) { | ||
| $ACL = get-acl $TESTDRIVE | ||
| $ACL.gettype().FullName | Should be "System.Security.AccessControl.DirectorySecurity" | ||
| } | ||
| It "Set-Acl can set the ACL of a directory" -pending { | ||
| Setup -d testdir | ||
| $directory = "$TESTDRIVE/testdir" | ||
| $acl = get-acl $directory | ||
| $accessRule = [System.Security.AccessControl.FileSystemAccessRule]::New("Everyone","FullControl","ContainerInherit,ObjectInherit","None","Allow") | ||
| $acl.AddAccessRule($accessRule) | ||
| { $acl | Set-Acl $directory } | should not throw | ||
|
|
||
| $newacl = get-acl $directory | ||
| $newrule = $newacl.Access | ?{ $accessrule.FileSystemRights -eq $_.FileSystemRights -and $accessrule.AccessControlType -eq $_.AccessControlType -and $accessrule.IdentityReference -eq $_.IdentityReference } | ||
| $newrule |Should not benullorempty | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
job cmdlets don't work on *unix platforms, see #1972
maybe this test should be run only on windows for now.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as it turns out the cmdlets actually do run on both platforms - the jobs themselves don't work, but the cmdlets do work to a certain extent. As soon as the job cmdlets actually execute the tests, these should be able to just start working. Currently, job creation fails on both platforms which is why the tests which check for proper execution of the job are marked as pending.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks Jim, that sounds reasonable. BTW, what does
-pendingmean in Pester tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pendingis a way that we can track those tests which will be eventually enabled. We will start tracking Pending tests and drive that count to 0 over time. A skipped test is a test which isn't really ever applicable (for example, a test that is only applicable to Linux, Core. or windows).