Incorporating feedback from code-review

This commit is contained in:
Bryce Milton
2016-05-04 17:09:01 -07:00
parent 0eacf59dae
commit e9606484da
9 changed files with 427 additions and 461 deletions
+47 -44
View File
@@ -1,47 +1,50 @@
Describe "Add-Content cmdlet tests" {
$file1 = "file1.txt"
Setup -File "$file1"
Describe "Add-Content cmdlet tests" -Tags:DRT {
$file1 = "file1.txt"
Setup -File "$file1"
Context "Add-Content should actually add content" {
It "should Add-Content to testdrive:\$file1" {
$result=add-content -path testdrive:\$file1 -value "ExpectedContent" -passthru
$result| Should be "ExpectedContent"
}
It "should return expected string from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly "ExpectedContent"
}
It "should Add-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result=add-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru
$result| Should BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result = get-content -path testdrive:\dynamicfile.txt
$result | Should BeExactly "ExpectedContent"
}
It "should Add-Content to testdrive:\$file1 even when -Value is `$null" {
$AsItWas=get-content testdrive:\$file1
{add-content -path testdrive:\$file1 -value $null -ea stop} | Should Not Throw
get-content testdrive:\$file1 | Should BeExactly $AsItWas
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
{add-content -path $null -value "ShouldNotWorkBecausePathIsNull" -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
{add-content -path $() -value "ShouldNotWorkBecausePathIsInvalid" -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw 'PSNotSupportedException' when you add-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
{add-content -path HKLM:\\software\\microsoft -value "ShouldNotWorkBecausePathIsUnsupported" -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
It "should be able to pass multiple [string]`$objects to Add-Content through the pipeline to output a dynamic Path file" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 9058182)]
"hello","world"|add-content testdrive:\dynamicfile2.txt
$result=get-content testdrive:\dynamicfile2.txt
$result.length |Should be 2
$result[0] |Should be "hello"
$result[1] |Should be "world"
}
Context "Add-Content should actually add content" {
It "should Add-Content to testdrive:\$file1" {
$result=add-content -path testdrive:\$file1 -value "ExpectedContent" -passthru
$result| Should be "ExpectedContent"
}
It "should return expected string from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly "ExpectedContent"
}
It "should Add-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result=add-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru
$result| Should BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result = get-content -path testdrive:\dynamicfile.txt
$result | Should BeExactly "ExpectedContent"
}
It "should Add-Content to testdrive:\$file1 even when -Value is `$null" {
$AsItWas=get-content testdrive:\$file1
{add-content -path testdrive:\$file1 -value $null -ea stop} | Should Not Throw
get-content testdrive:\$file1 | Should BeExactly $AsItWas
}
It "should throw 'ParameterArgumentValidationErrorNullNotAllowed' when -Path is `$null" {
Try {add-content -path $null -value "ShouldNotWorkBecausePathIsNull" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
Try {add-content -path $() -value "ShouldNotWorkBecausePathIsInvalid" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'NotSupportedException' when you add-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
Try {add-content -path HKLM:\\software\\microsoft -value "ShouldNotWorkBecausePathIsUnsupported" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "NotSupported,Microsoft.PowerShell.Commands.AddContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 9058182)]
It "should be able to pass multiple [string]`$objects to Add-Content through the pipeline to output a dynamic Path file" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
"hello","world"|add-content testdrive:\dynamicfile2.txt
$result=get-content testdrive:\dynamicfile2.txt
$result.length |Should be 2
$result[0] |Should be "hello"
$result[1] |Should be "world"
}
}
}
+23 -24
View File
@@ -1,27 +1,26 @@
Describe "Clear-Content cmdlet tests" {
$file1 = "file1.txt"
Setup -File "$file1"
Describe "Clear-Content cmdlet tests" -Tags:DRT {
$file1 = "file1.txt"
Setup -File "$file1"
Context "Clear-Content should actually clear content" {
It "should clear-Content of testdrive:\$file1" {
set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should be "ExpectedContent"
clear-content -Path testdrive:\$file1
}
It "shouldn't get any content from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly $null
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
{clear-content -path $null -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
{clear-content -path $() -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
{clear-content -path HKLM:\\software\\microsoft -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
Context "Clear-Content should actually clear content" {
It "should clear-Content of testdrive:\$file1" {
set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should be "ExpectedContent"
clear-content -Path testdrive:\$file1
}
It "shouldn't get any content from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly $null
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
{clear-content -path $null -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
{clear-content -path $() -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
{clear-content -path HKLM:\\software\\microsoft -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
}
}
+26 -34
View File
@@ -1,37 +1,29 @@
if (!$IsLinux -And !$IsOSX) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
}
Describe "Clear-EventLog cmdlet tests" {
BeforeAll {
Remove-EventLog -LogName TestLog -ea Ignore
Remove-EventLog -LogName MissingTestLog -ea Ignore
New-EventLog -LogName TestLog -Source TestSource -ea Ignore
if ($IsWindows) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
Describe "Clear-EventLog cmdlet tests" -Tags:DRT {
#DRT - CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
It "should be able to Clear-EventLog" -Pending:($True -Or $NonWinAdmin) {
Remove-EventLog -LogName TestLog -ea Ignore
{New-EventLog -LogName TestLog -Source TestSource -ea Stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop } | Should Not Throw
{$result=Get-EventLog -LogName TestLog} | Should Not Throw
($result.Count) | Should be 1
{Clear-EventLog -LogName TestLog} | Should Not Throw
$result=Get-EventLog -LogName TestLog -ea Ignore
($result.Count) | Should be 0
{Remove-EventLog -LogName TestLog -ea Stop} | Should Not Throw
}
BeforeEach {
Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Ignore
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Pending:($True -Or $NonWinAdmin) {
Remove-EventLog -LogName MissingTestLog -ea Ignore
try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
}
AfterEach {
Clear-EventLog -LogName TestLog -ea Ignore
It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True -Or $NonWinAdmin) {
try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
}
AfterAll {
Remove-EventLog -LogName TestLog -ea Ignore
}
It "should be able to Clear-EventLog" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.Message | Should BeExactly "Test"
Clear-EventLog -LogName TestLog
$result=Get-EventLog -LogName TestLog -ea Ignore
$result.Count | Should be 0
}
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{Clear-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'The Log name "MissingTestLog" does not exist'
}
}
}
}
+133 -148
View File
@@ -1,149 +1,134 @@
Describe "Get-Content" {
$testString = "This is a test content for a file"
$nl = [Environment]::NewLine
$firstline = "Here's a first line "
$secondline = " here's a second line"
$thirdline = "more text"
$fourthline = "just to make sure"
$fifthline = "there's plenty to work with"
$testString2 = $firstline + $nl + $secondline + $nl + $thirdline + $nl + $fourthline + $nl + $fifthline
$testPath = Join-Path -Path $TestDrive -ChildPath testfile1
$testPath2 = Join-Path -Path $TestDrive -ChildPath testfile2
BeforeEach {
New-Item -Path $testPath -ItemType file -Force -Value $testString
New-Item -Path $testPath2 -ItemType file -Force -Value $testString2
Describe "Get-Content" -Tags:DRT {
$testString = "This is a test content for a file"
$nl = [Environment]::NewLine
$firstline = "Here's a first line "
$secondline = " here's a second line"
$thirdline = "more text"
$fourthline = "just to make sure"
$fifthline = "there's plenty to work with"
$testString2 = $firstline + $nl + $secondline + $nl + $thirdline + $nl + $fourthline + $nl + $fifthline
$testPath = Join-Path -Path $TestDrive -ChildPath testfile1
$testPath2 = Join-Path -Path $TestDrive -ChildPath testfile2
BeforeEach {
New-Item -Path $testPath -ItemType file -Force -Value $testString
New-Item -Path $testPath2 -ItemType file -Force -Value $testString2
}
AfterEach {
Remove-Item -Path $testPath -Force
Remove-Item -Path $testPath2 -Force
}
It "Should throw an error on a directory " {# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
}
It "Should return an Object when listing only a single line" {
(Get-Content -Path $testPath).GetType().BaseType.Name | Should Be "Object"
}
It "Should deliver an array object when listing a file with multiple lines" {
(Get-Content -Path $testPath2).GetType().BaseType.Name | Should Be "Array"
}
It "Should return the correct information from a file" {
(Get-Content -Path $testPath) | Should Be $testString
}
It "Should be able to call using the gc alias" {
{ gc -Path $testPath } | Should Not Throw
}
It "Should be able to call using the type alias" {
{ type -Path $testPath } | Should Not Throw
}
It "Should return the same values for aliases" {
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$typeAlias = type -Path $testPath
$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $typeAlias
}
It "Should be able to return a specific line from a file" {
(Get-Content -Path $testPath2)[1] | Should be $secondline
}
It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
$returnArray = (Get-Content -Path $testPath2 -TotalCount 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the Head switch" {
$returnArray = (Get-Content -Path $testPath2 -Head 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the First switch" {
$returnArray = (Get-Content -Path $testPath2 -First 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should return the last line of a file using the Tail switch" {
Get-Content -Path $testPath -Tail 1 | Should Be $testString
}
It "Should return the last lines of a file using the Last alias" {
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
}
It "Should be able to get content within a different drive" {
pushd env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
{ Get-Content PATH } | Should Not Throw
Get-Content PATH | Should Be $expectedoutput
popd
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
{get-content -path HKLM:\\software\\microsoft -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
It "should Get-Content with a variety of -Tail and -ReadCount values" {#[DRT]
set-content -path $testPath "Hello,World","Hello2,World2","Hello3,World3","Hello4,World4"
$result=get-content -path $testPath -readcount:-1 -tail 5
$result.Length | Should Be 4
$expected = "Hello,World","Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 0 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 1 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 99999 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 2 -tail 3
$result.Length | Should Be 2
$expected = "Hello2,World2","Hello3,World3"
$expected = $expected,"Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 2 -tail 2
$result.Length | Should Be 2
$expected = "Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -delimiter "," -tail 2
$result.Length | Should Be 2
if ($IsWindows) {$expected = "World3`r`nHello4,","World4`r`n"
} else {$expected = "World3`nHello4,","World4`n"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -delimiter "o" -tail 3
$result.Length | Should Be 3
if ($IsWindows) {$expected = "rld3`r`nHello","4,Wo","rld4"
} else {$expected = "rld3`nHello","4,Wo","rld4"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i].Trim() | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -encoding:Byte -tail 10
$result.Length | Should Be 10
if ($IsWindows) {
$expected = "52","44","87","111","114","108","100","52","13","10"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
}
AfterEach {
Remove-Item -Path $testPath -Force
Remove-Item -Path $testPath2 -Force
}
It "Should throw an error on a directory " {
# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
}
It "Should return an Object when listing only a single line" {
(Get-Content -Path $testPath).GetType().BaseType.Name | Should Be "Object"
}
It "Should deliver an array object when listing a file with multiple lines" {
(Get-Content -Path $testPath2).GetType().BaseType.Name | Should Be "Array"
}
It "Should return the correct information from a file" {
(Get-Content -Path $testPath) | Should Be $testString
}
It "Should be able to call using the gc alias" {
{ gc -Path $testPath } | Should Not Throw
}
It "Should be able to call using the type alias" {
{ type -Path $testPath } | Should Not Throw
}
It "Should return the same values for aliases" {
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$typeAlias = type -Path $testPath
$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $typeAlias
}
It "Should be able to return a specific line from a file" {
(Get-Content -Path $testPath2)[1] | Should be $secondline
}
It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
$returnArray = (Get-Content -Path $testPath2 -TotalCount 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the Head switch" {
$returnArray = (Get-Content -Path $testPath2 -Head 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the First switch" {
$returnArray = (Get-Content -Path $testPath2 -First 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should return the last line of a file using the Tail switch" {
Get-Content -Path $testPath -Tail 1 | Should Be $testString
}
It "Should return the last lines of a file using the Last alias" {
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
}
It "Should be able to get content within a different drive" {
pushd env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
{ Get-Content PATH } | Should Not Throw
Get-Content PATH | Should Be $expectedoutput
popd
}
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
{get-content -path HKLM:\\software\\microsoft -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
It "should Get-Content with a variety of -Tail and -ReadCount values" {
#[DRT]
set-content -path $testPath "Hello,World","Hello2,World2","Hello3,World3","Hello4,World4"
$result=get-content -path $testPath -readcount:-1 -tail 5
$result.Length | Should Be 4
$expected = "Hello,World","Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 0 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 1 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 99999 -tail 3
$result.Length | Should Be 3
$expected = "Hello2,World2","Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 2 -tail 3
$result.Length | Should Be 2
$expected = "Hello2,World2","Hello3,World3"
$expected = $expected,"Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -readcount 2 -tail 2
$result.Length | Should Be 2
$expected = "Hello3,World3","Hello4,World4"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -delimiter "," -tail 2
$result.Length | Should Be 2
if ($IsWindows) {$expected = "World3`r`nHello4,","World4`r`n"
} else {$expected = "World3`nHello4,","World4`n"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -delimiter "o" -tail 3
$result.Length | Should Be 3
if ($IsWindows) {$expected = "rld3`r`nHello","4,Wo","rld4"
} else {$expected = "rld3`nHello","4,Wo","rld4"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i].Trim() | Should BeExactly $expected[$i]}
$result=get-content -path $testPath -encoding:Byte -tail 10
$result.Length | Should Be 10
if ($IsWindows) {
$expected = "52","44","87","111","114","108","100","52","13","10"
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
}
}
It "should get-content that matches the input string"{
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 905829)]
set-content $testPath "Hello,llllWorlld","Hello2,llllWorlld2"
$result=get-content $testPath -delimiter "ll"
$result.Length | Should Be 9
if ($IsWindows) {$expected = "Hell","o,ll","ll","Worll","d`r`nHell","o2,ll","ll","Worll","d2`r`n"
} else {$expected = "Hell","o,ll","ll","Worll","d`nHell","o2,ll","ll","Worll","d2`n"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
}
}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 905829)]
It "should get-content that matches the input string"{
set-content $testPath "Hello,llllWorlld","Hello2,llllWorlld2"
$result=get-content $testPath -delimiter "ll"
$result.Length | Should Be 9
if ($IsWindows) {$expected = "Hell","o,ll","ll","Worll","d`r`nHell","o2,ll","ll","Worll","d2`r`n"
} else {$expected = "Hell","o,ll","ll","Worll","d`nHell","o2,ll","ll","Worll","d2`n"}
for ($i = 0; $i -lt $result.Length ; $i++) { $result[$i] | Should BeExactly $expected[$i]}
}
}
+42 -58
View File
@@ -1,60 +1,44 @@
if ($IsWindows) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {exit}
Describe "Get-EventLog cmdlet tests" -Tags:DRT {
#CmdLets are not yet implemented, so these cases are -Pending:($True) for now...
It "should return an array of eventlogs objects when called with -AsString parameter" -Pending:($True) {
{$result=Get-EventLog -AsString -ea stop} | Should Not Throw
$result.GetType().BaseType.Name | Should Be "Array"
$result -eq "Application" | Should Be "Application"
$result.Count -ge 3 | Should Be $true
}
It "should return a list of eventlog objects when called with -List parameter" -Pending:($True) {
{$result=Get-EventLog -List -ea stop} | Should Not Throw
$result.GetType().BaseType.Name | Should Be "array"
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
$logs -eq "System" | Should Be "System"
$logs.Count -ge 3 | Should Be $true
}
It "should be able to Get-EventLog -LogName Application -Newest 100" -Pending:($True) {
{$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw
$result | Should Not BeNullOrEmpty
$result.Length -le 100 | Should Be $true
$result[0].GetType().Name | Should Be "EventLogEntry"
}
It "should throw 'AmbiguousParameterSetException' when called with both -LogName and -List parameters" -Pending:($True) {
try {Get-EventLog -LogName System -List -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {echo $_.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
It "should be able to Get-EventLog -LogName * with multiple matches" -Pending:($True) {
{$result=get-eventlog -LogName * -ea stop} | Should Not Throw
$result | Should Not BeNullOrEmpty
$result -eq "Security" | Should Be "Security"
$result.Count -ge 3 | Should Be $true
}
It "should throw 'InvalidOperationException' when asked to get a log that does not exist" -Pending:($True) {
try {Get-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {echo $_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
}
}
Describe "Get-EventLog cmdlet tests" {
BeforeAll {
Remove-EventLog -LogName TestLog -ea Ignore
Remove-EventLog -LogName MissingTestLog -ea Ignore
New-EventLog -LogName TestLog -Source TestSource -ea Ignore
}
BeforeEach {
Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Ignore
}
AfterEach {
Clear-EventLog -LogName TestLog -ea Ignore
}
AfterAll {
Remove-EventLog -LogName TestLog -ea Ignore
}
It "should return an array of strings when called with -AsString parameter" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{$result=Get-EventLog -AsString -ea stop} | Should Not Throw
{$result.GetType()|% { $_.IsArray }} | Should Be $true
{$result.Contains("System")} | Should Be $true
{$result.Contains("TestLog")} | Should Be $true
($result.Count -ge 4) | Should Be $true
}
It "should return a list of strings when called with -List parameter" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{$result=Get-EventLog -List -ea stop} | Should Not Throw
{$result.GetType()|% { $_.IsArray }} | Should Be $true
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
{$logs.Contains("System")} | Should Be $true
{$logs.Contains("TestLog")} | Should Be $true
($logs.Count -ge 4) | Should Be $true
}
It "should be able to Get-EventLog -LogName Application -Newest 100" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw
($result) | Should Not BeNullOrEmpty
($result.Length -le 100) | Should Be $true
($result[0].GetType().Name) | Should Be EventLog
}
It "should throw 'ParameterBindingException' when called with both -List and -AsString" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{Get-EventLog -LogName MissingTestLog -ea stop} | Should Throw
}
It "should be able to Get-EventLog -LogName * with multiple matches" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{$result=get-eventlog -LogName * -ea stop}| Should Not Throw
($result) | Should Not BeNullOrEmpty
{$result.Contains("System")} | Should Be $true
{$result.Contains("TestLog")} | Should Be $true
($result.count -ge 4) | Should Be $true
}
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to get a log that does not exist" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
{Get-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'does not exist'
}
}
+46 -43
View File
@@ -1,43 +1,46 @@
Describe "Join-Path cmdlet tests" {
BeforeAll {
$StartingLocation = Get-Location
}
AfterEach {
Set-Location $StartingLocation
}
It "should output multiple paths when called with multiple -Path targets" -Tag DRT {
Setup -Dir SubDir1
(Join-Path -Path TestDrive:,$TestDrive -ChildPath "SubDir1" -resolve).Length | Should be 2
}
It "should throw 'Cannot find drive' when drive cannot be found" -Tag DRT {
{Join-Path bogusdrive:\\somedir otherdir -resolve -ea stop} | Should Throw "Cannot find drive"
}
It "should throw 'Cannot find path' when item cannot be found" -Tag DRT {
{Join-Path "Bogus" "Path" -resolve -ea stop} | Should Throw "Cannot find path"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 905237)] Note: Windows-specified bug, but the result should be the same on other platforms
It "should return one object when called with a FileSystem::Redirector" -Tag DRT {
set-location env:\
$result=join-path FileSystem::windir system32
$result.Count | Should be 1
$result | Should BeExactly "FileSystem::windir\system32"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Variable:' with 'foo'" -Tag DRT {
$result=Join-Path "Variable:" "foo"
$result.Count | Should be 1
$result | Should BeExactly "Variable:\foo"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Alias:' with 'foo'" -Tag DRT {
$result=Join-Path "Alias:" "foo"
$result.Count | Should be 1
$result | Should BeExactly "Alias:\foo"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Env:' with 'foo'" -Tag DRT {
$result=Join-Path "Env:" "foo"
$result.Count | Should be 1
$result | Should BeExactly "Env:\foo"
}
}
Describe "Join-Path cmdlet tests" -Tags DRT {
$SepChar=[io.path]::DirectorySeparatorChar
BeforeAll {
$StartingLocation = Get-Location
}
AfterEach {
Set-Location $StartingLocation
}
It "should output multiple paths when called with multiple -Path targets" {
Setup -Dir SubDir1
(Join-Path -Path TestDrive:,$TestDrive -ChildPath "SubDir1" -resolve).Length | Should be 2
}
It "should throw 'DriveNotFound' when called with -Resolve and drive does not exist" {
try {Join-Path bogusdrive:\\somedir otherdir -resolve -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "DriveNotFound,Microsoft.PowerShell.Commands.JoinPathCommand"}
}
It "should throw 'PathNotFound' when called with -Resolve and item does not exist" {
try {Join-Path "Bogus" "Path" -resolve -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.JoinPathCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 905237)] Note: Result should be the same on non-Windows platforms too
It "should return one object when called with a Windows FileSystem::Redirector" {
set-location ("env:"+$SepChar)
$result=join-path FileSystem::windir system32
$result.Count | Should be 1
$result | Should BeExactly ("FileSystem::windir"+$SepChar+"system32")
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Variable:' with 'foo'" {
$result=Join-Path "Variable:" "foo"
$result.Count | Should be 1
$result | Should BeExactly ("Variable:"+$SepChar+"foo")
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Alias:' with 'foo'" {
$result=Join-Path "Alias:" "foo"
$result.Count | Should be 1
$result | Should BeExactly ("Alias:"+$SepChar+"foo")
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
It "should be able to join-path special string 'Env:' with 'foo'" {
$result=Join-Path "Env:" "foo"
$result.Count | Should be 1
$result | Should BeExactly ("Env:"+$SepChar+"foo")
}
}
+33 -38
View File
@@ -5,48 +5,43 @@
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
}
Describe "New-EventLog cmdlet tests" {
Describe "New-EventLog cmdlet tests" -Tags DRT {
BeforeEach {
Remove-EventLog -LogName TestLog -ea Ignore
Remove-EventLog -LogName TestLog -ea Ignore
}
It "should be able to create a New-EventLog with a -Source paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{New-EventLog -LogName TestLog -Source TestSource -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
It "should be able to create a New-EventLog with a -Source paramter" -Skip:($True -Or $NonWinAdmin) {
{New-EventLog -LogName TestLog -Source TestSource -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
}
It "should be able to create a New-EventLog with a -ComputerName paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{New-EventLog -LogName TestLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 1
It "should be able to create a New-EventLog with a -ComputerName paramter" -Skip:($True -Or $NonWinAdmin) {
{New-EventLog -LogName TestLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 1
}
It "should be able to create a New-EventLog with a -CategoryResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{New-EventLog -LogName TestLog -Source TestSource -CategoryResourceFile "CategoryMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 2 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 2
It "should be able to create a New-EventLog with a -CategoryResourceFile paramter" -Skip:($True -Or $NonWinAdmin) {
{New-EventLog -LogName TestLog -Source TestSource -CategoryResourceFile "CategoryMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 2 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 2
}
It "should be able to create a New-EventLog with a -MessageResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{New-EventLog -LogName TestLog -Source TestSource -MessageResourceFile "ResourceMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 3 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 3
It "should be able to create a New-EventLog with a -MessageResourceFile paramter" -Skip:($True -Or $NonWinAdmin) {
{New-EventLog -LogName TestLog -Source TestSource -MessageResourceFile "ResourceMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 3 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 3
}
It "should be able to create a New-EventLog with a -ParameterResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{New-EventLog -LogName TestLog -Source TestSource -ParameterResourceFile "ParameterMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 4 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 4
It "should be able to create a New-EventLog with a -ParameterResourceFile paramter" -Skip:($True -Or $NonWinAdmin) {
{New-EventLog -LogName TestLog -Source TestSource -ParameterResourceFile "ParameterMessageFile" -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 4 -ea stop} | Should Not Throw
$result=Get-EventLog -LogName TestLog
$result.Count | Should be 1
$result.EventID | Should be 4
}
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Tag DRT {
{Clear-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'The Log name "MissingTestLog" does not exist'
}
}
}
}
+27 -23
View File
@@ -1,27 +1,31 @@
if ($IsWindows) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
}
Describe "New-EventLog cmdlet tests" {
BeforeEach {
Remove-EventLog -LogName TestLog -ea Ignore
New-EventLog -LogName TestLog -Source TestSource -ea Ignore
Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea ignore
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
$NonWinAdmin=$false
} else {$NonWinAdmin=$true}
Describe "New-EventLog cmdlet tests" -Tags DRT {
BeforeEach{
Remove-EventLog -LogName TestLog -ea Ignore
{New-EventLog -LogName TestLog -Source TestSource -ea Stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop} | Should Not Throw
}
It "should be able to Remove-EventLog -LogName <string> -ComputerName <string>" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
{Remove-EventLog -LogName TestLog -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Throw
{Get-EventLog -LogName TestLog -ea stop} | Should Throw
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
It "should be able to Remove-EventLog -LogName <string> -ComputerName <string>" -Pending:($True -Or $NonWinAdmin) {
{Remove-EventLog -LogName TestLog -ComputerName $env:COMPUTERNAME -ea Stop} | Should Not Throw
try {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.WriteEventLogCommand"}
try {Get-EventLog -LogName TestLog -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
It "should be able to Remove-EventLog -Source <string> -ComputerName <string>" -Skip:($true -Or $NonWinAdmin -Or $IsLinux -Or $IsOSX) -Tag DRT {
{Remove-EventLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Throw
{Get-EventLog -LogName TestLog -ea stop} | Should Throw
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
It "should be able to Remove-EventLog -Source <string> -ComputerName <string>" -Pending:($True -Or $NonWinAdmin) {
{Remove-EventLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea Stop} | Should Not Throw
try {Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.WriteEventLogCommand"}
try {Get-EventLog -LogName TestLog -ea Stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
}
}
}
+50 -49
View File
@@ -1,50 +1,51 @@
Describe "Set-Content cmdlet tests" {
$file1 = "file1.txt"
Setup -File "$file1" -Content $file1
Context "Set-Content should actually set content" {
It "should set-Content of testdrive:\$file1" {
$result=set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru
$result| Should be "ExpectedContent"
}
It "should return expected string from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly "ExpectedContent"
}
It "should Set-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result=set-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru
$result| Should BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result = get-content -path testdrive:\dynamicfile.txt
$result | Should BeExactly "ExpectedContent"
}
It "should remove existing content from testdrive:\$file1 when the -Value is `$null" {
$AsItWas=get-content testdrive:\$file1
$AsItWas |Should BeExactly "ExpectedContent"
{set-content -path testdrive:\$file1 -value $null -ea stop} | Should Not Throw
$AsItIs=get-content testdrive:\$file1
$AsItIs| Should Not Be $AsItWas
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
{set-content -path $null -value "ShouldNotWorkBecausePathIsNull" -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
{set-content -path $() -value "ShouldNotWorkBecausePathIsInvalid" -ea stop} | Should Throw "Cannot bind argument to parameter 'Path'"
}
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
{set-content -path HKLM:\\software\\microsoft -value "ShouldNotWorkBecausePathIsUnsupported" -ea stop} | Should Throw "IContentCmdletProvider interface is not implemented"
}
It "should be able to pass multiple [string]`$objects to Set-Content through the pipeline to output a dynamic Path file" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 9058182)]
"hello","world"|set-content testdrive:\dynamicfile2.txt
$result=get-content testdrive:\dynamicfile2.txt
$result.length |Should be 2
$result[0] |Should be "hello"
$result[1] |Should be "world"
}
Describe "Set-Content cmdlet tests" -Tags:DRT {
$file1 = "file1.txt"
Setup -File "$file1" -Content $file1
Context "Set-Content should actually set content" {
It "should set-Content of testdrive:\$file1" {
$result=set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru
$result| Should be "ExpectedContent"
}
}
It "should return expected string from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly "ExpectedContent"
}
It "should Set-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result=set-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru
$result| Should BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
$result = get-content -path testdrive:\dynamicfile.txt
$result | Should BeExactly "ExpectedContent"
}
It "should remove existing content from testdrive:\$file1 when the -Value is `$null" {
$AsItWas=get-content testdrive:\$file1
$AsItWas |Should BeExactly "ExpectedContent"
{set-content -path testdrive:\$file1 -value $null -ea stop} | Should Not Throw
$AsItIs=get-content testdrive:\$file1
$AsItIs| Should Not Be $AsItWas
}
It "should throw 'ParameterArgumentValidationErrorNullNotAllowed' when -Path is `$null" {
Try {set-content -path $null -value "ShouldNotWorkBecausePathIsNull" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
It "should throw 'ParameterArgumentValidationErrorNullNotAllowed' when -Path is `$()" {
Try {set-content -path $() -value "ShouldNotWorkBecausePathIsInvalid" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'PSNotSupportedException' when you set-content to an unsupported provider" -Skip:($IsLinux -Or $IsOSX) {
Try {set-content -path HKLM:\\software\\microsoft -value "ShouldNotWorkBecausePathIsUnsupported" -ea stop; Throw "Previous statement unexpectedly succeeded..."
} Catch {$_.FullyQualifiedErrorId | Should Be "NotSupported,Microsoft.PowerShell.Commands.SetContentCommand"}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 9058182)]
It "should be able to pass multiple [string]`$objects to Set-Content through the pipeline to output a dynamic Path file" -Pending:($IsLinux -Or $IsOSX) {#https://github.com/PowerShell/PowerShell/issues/891
"hello","world"|set-content testdrive:\dynamicfile2.txt
$result=get-content testdrive:\dynamicfile2.txt
$result.length |Should be 2
$result[0] |Should be "hello"
$result[1] |Should be "world"
}
}
}