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
@@ -1,4 +1,51 @@
Describe "History cmdlet test cases" -Tags "CI" {
Context "Simple History Tests" {
BeforeEach {
$setting = [system.management.automation.psinvocationsettings]::New()
$setting.AddToHistory = $true
$ps = [PowerShell]::Create("NewRunspace")
# we need to be sure that history is added, so use the proper
# Invoke variant
$null = $ps.addcommand("Get-Date").Invoke($null,$setting)
$ps.commands.clear()
$null = $ps.addscript("1+1").Invoke($null,$setting)
$ps.commands.clear()
$null = $ps.addcommand("Get-Location").Invoke($null,$setting)
$ps.commands.clear()
}
AfterEach {
$ps.Dispose()
}
It "Get-History returns proper history" {
# for this case, we'll *not* add to history
$result = $ps.AddCommand("Get-History").Invoke()
$result.Count | should be 3
$result[0].CommandLine | should be "Get-Date"
$result[1].CommandLine | should be "1+1"
$result[2].CommandLine | should be "Get-Location"
}
It "Invoke-History invokes proper command" {
$result = $ps.AddScript("Invoke-History 2").Invoke()
$result | Should be 2
}
It "Clear-History removes history" {
$ps.AddCommand("Clear-History").Invoke()
$ps.commands.clear()
$result = $ps.AddCommand("Get-History").Invoke()
$result | should BeNullOrEmpty
}
It "Add-History actually adds to history" {
# add this invocation to history
$ps.AddScript("Get-History|Add-History").Invoke($null,$setting)
# that's 4 history lines * 2
$ps.Commands.Clear()
$result = $ps.AddCommand("Get-History").Invoke()
$result.Count | Should be 8
for($i = 0; $i -lt 4; $i++) {
$result[$i+4].CommandLine | Should be $result[$i].CommandLine
}
}
}

It "Tests Invoke-History on a cmdlet that generates output on all streams" {
$streamSpammer = '
Expand Down
76 changes: 76 additions & 0 deletions test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Describe "Job Cmdlet Tests" -Tag "CI" {
Copy link
Member

@daxian-dbw daxian-dbw Aug 22, 2016

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.

Copy link
Collaborator Author

@JamesWTruher JamesWTruher Aug 22, 2016

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.

Copy link
Member

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 -pending mean in Pester tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pending is 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).

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>"
}
}
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
}
}
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 { }
}
}
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"
}
}
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"
}
}
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"
}
}
}
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
}
}
}
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ Describe "Stream writer tests" -Tags "CI" {
$Error[0] | Should Match "Test Error Message"
}
}

Context "Write-Information cmdlet" {
It "Write-Information outputs an information object" {
# redirect the streams is sufficient
$result = Write-Information "Test Message" *>&1
$result.GetType().Fullname | Should be "System.Management.Automation.InformationRecord"
"$result" | Should be "Test Message"
}
}
}