Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6e0b7dc
Clean up tests in Microsoft.PowerShell.Management to use -Parameter s…
kalgiz Mar 2, 2018
6fb3282
[Feature] Merge branch 'master' of https://github.com/kalgiz/PowerShe…
kalgiz Mar 2, 2018
a453e49
Add line deleted by mistake.
kalgiz Mar 2, 2018
2645036
[Feature] Resolve conflict
kalgiz Mar 3, 2018
f7e6998
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 6, 2018
8661ef7
Tests syntax correction for module Microsoft.PowerShell.Management
kalgiz Mar 6, 2018
ec1292f
Tests syntax correction for module Microsoft.PowerShell.Management
kalgiz Mar 6, 2018
170da9f
Test correction
kalgiz Mar 6, 2018
b591202
[Feature] Tests correction in module Microsoft.PowerShell.Management.
kalgiz Mar 6, 2018
3113dcb
[Feature] Clear-Content test correction.
kalgiz Mar 7, 2018
57a2688
[Feature] Test correction.
kalgiz Mar 7, 2018
f4955aa
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 7, 2018
030ffa0
[Feature] Microsoft.PowerShell.Management module tests.
kalgiz Mar 7, 2018
5a0c067
[Feature] Remove-EventLog test correction.
kalgiz Mar 7, 2018
9c93d1a
[Feature] Use Should -Throw -ErrorId instead of try-catch in module M…
kalgiz Mar 7, 2018
ddff370
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 8, 2018
7531e93
[Feature] Tests correction in Microsoft.PowerShell.Managemet module.
kalgiz Mar 8, 2018
67ff3ef
[Feature] Merge branch 'master' of https://github.com/kalgiz/PowerShe…
kalgiz Mar 8, 2018
f0cc737
[Feature] Tests correction in Microsoft.PowerShell.Managemet module.
kalgiz Mar 8, 2018
ea48f96
Merge branch 'master' of https://github.com/kalgiz/PowerShell into ne…
kalgiz Mar 9, 2018
fda9da7
[Feature] Tests correction
kalgiz Mar 9, 2018
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 @@ -7,46 +7,43 @@ Describe "Add-Content cmdlet tests" -Tags "CI" {
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"
$result| Should -BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\$file1" {
$result = get-content -path testdrive:\$file1
$result | Should BeExactly "ExpectedContent"
$result | Should -BeExactly "ExpectedContent"
}
It "should Add-Content to testdrive:\dynamicfile.txt with dynamic parameters" -Pending:($IsLinux -Or $IsMacOS) {#https://github.com/PowerShell/PowerShell/issues/891
$result=add-content -path testdrive:\dynamicfile.txt -value "ExpectedContent" -passthru
$result| Should BeExactly "ExpectedContent"
$result| Should -BeExactly "ExpectedContent"
}
It "should return expected string from testdrive:\dynamicfile.txt" -Pending:($IsLinux -Or $IsMacOS) {#https://github.com/PowerShell/PowerShell/issues/891
$result = get-content -path testdrive:\dynamicfile.txt
$result | Should BeExactly "ExpectedContent"
$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
{add-content -path testdrive:\$file1 -value $null -ErrorAction 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"}
{ Add-Content -Path $null -Value "ShouldNotWorkBecausePathIsNull" -ErrorAction Stop } | Should -Throw -ErrorId "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"}
{ Add-Content -Path $() -Value "ShouldNotWorkBecausePathIsInvalid" -ErrorAction Stop } | Should -Throw -ErrorId "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentCommand"
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'NotSupportedException' when you add-content to an unsupported provider" -Skip:($IsLinux -Or $IsMacOS) {
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"}
{ Add-Content -Path HKLM:\\software\\microsoft -Value "ShouldNotWorkBecausePathIsUnsupported" -ErrorAction Stop } | Should -Throw -ErrorId "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 $IsMacOS) {#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"
$result.length | Should -Be 2
$result[0] | Should -BeExactly "hello"
$result[1] | Should -BeExactly "world"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ Describe "Basic Alias Provider Tests" -Tags "CI" {

It "Test number of alias not Zero" {
$aliases = @(Get-ChildItem "Alias:\")
$aliases.Count | Should Not Be 0
$aliases.Count | Should -Not -Be 0
}

It "Test alias dir" {
$dirAlias = Get-Item "Alias:\dir"
$dirAlias.CommandType | Should Be "Alias"
$dirAlias.Name | Should Be "dir"
$dirAlias.Definition | Should Be "Get-ChildItem"
$dirAlias.CommandType | Should -BeExactly "Alias"
$dirAlias.Name | Should -BeExactly "dir"
$dirAlias.Definition | Should -BeExactly "Get-ChildItem"
}

It "Test creating new alias" {
try {
$newAlias = New-Item -Path "Alias:\" -Name "NewTestAlias" -Value $testAliasValue
$newAlias.CommandType | Should Be "Alias"
$newAlias.Name | Should Be "NewTestAlias"
$newAlias.Definition | Should Be $testAliasValue
$newAlias.CommandType | Should -BeExactly "Alias"
$newAlias.Name | Should -BeExactly "NewTestAlias"
$newAlias.Definition | Should -BeExactly $testAliasValue
}
finally {
Remove-Item -Path "Alias:\NewTestAlias" -Force -ErrorAction SilentlyContinue
Expand All @@ -40,19 +40,19 @@ Describe "Basic Alias Provider Tests" -Tags "CI" {

It "Test Get-Item on alias provider" {
$alias = Get-Item -Path "Alias:\${testAliasName}"
$alias.CommandType | Should Be "Alias"
$alias.Name | Should Be $testAliasName
$alias.Definition | Should Be $testAliasValue
$alias.CommandType | Should -BeExactly "Alias"
$alias.Name | Should -BeExactly $testAliasName
$alias.Definition | Should -BeExactly $testAliasValue
}

It "Test Test-Path on alias provider" {
$aliasExists = Test-Path "Alias:\testAlias"
$aliasExists | Should Be $true
$aliasExists | Should -BeTrue
}

It "Test executing the new alias" {
$result = Invoke-Expression $testAliasName
$result | Should BeOfType DateTime
$result | Should -BeOfType [DateTime]
}
}

Expand All @@ -78,35 +78,35 @@ Describe "Extended Alias Provider Tests" -Tags "Feature" {
$before = (Get-Item -Path "Alias:\${testAliasName}").Definition
Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Whatif
$after = (Get-Item -Path "Alias:\${testAliasName}").Definition
$after | Should Be $before # Definition should not have changed
$after | Should -BeExactly $before # Definition should not have changed
}

It "Verifying Confirm can be bypassed" {
Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Confirm:$false
$result = Get-Item -Path "Alias:\${testAliasName}"
$result.Definition | Should Be "Get-Location"
$result.Definition | Should -BeExactly "Get-Location"
}

It "Verifying Force" {
Set-Item -Path "Alias:\${testAliasName}" -Value "Get-Location" -Force
$result = Get-Item -Path "Alias:\${testAliasName}"
$result.Definition | Should Be "Get-Location"
$result.Definition | Should -BeExactly "Get-Location"
}

It "Verifying Include" {
Set-Item -Path "Alias:\*" -Value "Get-Location" -Include "TestAlias*"
$alias1 = Get-Item -Path "Alias:\${testAliasName}"
$alias2 = Get-Item -Path "Alias:\${testAliasName2}"
$alias1.Definition | Should Be "Get-Location"
$alias2.Definition | Should Be "Get-Location"
$alias1.Definition | Should -BeExactly "Get-Location"
$alias2.Definition | Should -BeExactly "Get-Location"
}

It "Verifying Exclude" {
Set-Item -Path "Alias:\TestAlias*" -Value "Get-Location" -Exclude "*2"
$alias1 = Get-Item -Path "Alias:\${testAliasName}"
$alias2 = Get-Item -Path "Alias:\${testAliasName2}"
$alias1.Definition | Should Be "Get-Location"
$alias2.Definition | Should Be "Get-Date"
$alias1.Definition | Should -BeExactly "Get-Location"
$alias2.Definition | Should -BeExactly "Get-Date"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,41 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" {

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"
set-content -path testdrive:\$file1 -value "ExpectedContent" -passthru | Should -BeExactly "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
$result | Should -BeNullOrEmpty
}

# we could suppress the WhatIf output here if we use the testhost, but it's not necessary
It "The filesystem provider supports should process" -skip:(!$IsWindows) {
clear-content TESTDRIVE:\$file2 -WhatIf
"TESTDRIVE:\$file2" | should FileContentMatch "This is content"
"TESTDRIVE:\$file2" | Should -FileContentMatch "This is content"
}

It "The filesystem provider should support ShouldProcess (reference ProviderSupportsShouldProcess member)" {
$cci = ((get-command clear-content).ImplementingType)::new()
$cci.SupportsShouldProcess | should be $true
$cci.SupportsShouldProcess | Should -BeTrue
}

It "Alternate streams should be cleared with clear-content" -skip:(!$IsWindows) {
# make sure that the content is correct
# this is here rather than BeforeAll because only windows can write to an alternate stream
set-content -path "TESTDRIVE:/$file3" -stream $streamName -value $streamContent
get-content -path "TESTDRIVE:/$file3" | Should be $content2
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | should be $streamContent
get-content -path "TESTDRIVE:/$file3" | Should -BeExactly $content2
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeExactly $streamContent
clear-content -PATH "TESTDRIVE:/$file3" -stream $streamName
get-content -Path "TESTDRIVE:/$file3" | should be $content2
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | should BeNullOrEmpty
get-content -Path "TESTDRIVE:/$file3" | Should -BeExactly $content2
get-content -Path "TESTDRIVE:/$file3" -stream $streamName | Should -BeNullOrEmpty
}

It "the '-Stream' dynamic parameter is visible to get-command in the filesystem" -Skip:(!$IsWindows) {
try {
push-location TESTDRIVE:
(get-command clear-content -stream foo).parameters.keys -eq "stream" | should be "stream"
(get-command clear-content -stream foo).parameters.keys -eq "stream" | Should -Be "stream"
}
finally {
pop-location
Expand All @@ -103,7 +103,7 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" {
throw "ExpectedExceptionNotDelivered"
}
catch {
$_.FullyQualifiedErrorId | should be "NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand"
$_.FullyQualifiedErrorId | Should -Be "NamedParameterNotFound,Microsoft.PowerShell.Commands.GetCommandCommand"
}
finally {
pop-location
Expand All @@ -114,64 +114,64 @@ Describe "Clear-Content cmdlet tests" -Tags "CI" {
Context "Proper errors should be delivered when bad locations are specified" {
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$null" {
try {
clear-content -path $null -ea stop
clear-content -path $null -ErrorAction Stop
throw "expected exception was not delivered"
}
catch {
$_.FullyQualifiedErrorId | should be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
#[BugId(BugDatabase.WindowsOutOfBandReleases, 903880)]
It "should throw `"Cannot bind argument to parameter 'Path'`" when -Path is `$()" {
try {
clear-content -path $() -ea stop
clear-content -path $() -ErrorAction Stop
throw "expected exception was not delivered"
}
catch {
$_.FullyQualifiedErrorId | should be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
#[DRT][BugId(BugDatabase.WindowsOutOfBandReleases, 906022)]
It "should throw 'PSNotSupportedException' when you clear-content to an unsupported provider" {
$functionName = Get-NonExistantFunctionName
$null = new-item function:$functionName -Value { 1 }
try {
clear-content -path function:$functionName -ea Stop
clear-content -path function:$functionName -ErrorAction Stop
throw "Expected exception was not thrown"
}
catch {
$_.FullyQualifiedErrorId | should be "NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "NotSupported,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
It "should throw FileNotFound error when referencing a non-existant file" {
try {
$badFile = "TESTDRIVE:/badfilename.txt"
clear-content -path $badFile -ea Stop
clear-content -path $badFile -ErrorAction Stop
throw "ExpectedExceptionNotDelivered"
}
catch {
$_.FullyQualifiedErrorId | should be "PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "PathNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
It "should throw DriveNotFound error when referencing a non-existant drive" {
try {
$badDrive = "{0}:/file.txt" -f (Get-NonExistantDriveName)
clear-content -path $badDrive -ea Stop
clear-content -path $badDrive -ErrorAction Stop
thow "ExpectedExceptionNotDelivered"
}
catch {
$_.FullyQualifiedErrorId | Should be "DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "DriveNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
# we'll use a provider qualified path to produce this error
It "should throw ProviderNotFound error when referencing a non-existant provider" {
try {
$badProviderPath = "{0}::C:/file.txt" -f (Get-NonExistantProviderName)
clear-content -path $badProviderPath -ea Stop
clear-content -path $badProviderPath -ErrorAction Stop
thow "ExpectedExceptionNotDelivered"
}
catch {
$_.FullyQualifiedErrorId | Should be "ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
$_.FullyQualifiedErrorId | Should -Be "ProviderNotFound,Microsoft.PowerShell.Commands.ClearContentCommand"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {

It "should be able to Clear-EventLog" -Pending:($True) {
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
{New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop} | Should -Not -Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction 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
($result.Count) | Should -Be 0
{Remove-EventLog -LogName TestLog -ErrorAction Stop} | Should -Not -Throw
}
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Pending:($True) {
Remove-EventLog -LogName MissingTestLog -ea Ignore
try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.ClearEventLogCommand"}
{ Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand"
}
It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True) {
try {Clear-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.ClearEventLogCommand"}
{ Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Describe "Clear-Item tests" -Tag "CI" {
${myClearItemVariableTest} = "Value is here"
}
It "Clear-Item can clear an item" {
$myClearItemVariableTest | Should be "Value is here"
$myClearItemVariableTest | Should -BeExactly "Value is here"
Clear-Item variable:myClearItemVariableTest
test-path variable:myClearItemVariableTest | should be $true
$myClearItemVariableTest | Should BeNullOrEmpty
test-path variable:myClearItemVariableTest | Should -BeTrue
$myClearItemVariableTest | Should -BeNullOrEmpty
}
}
Loading