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
13 changes: 7 additions & 6 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ Describe 'minishell for native executables' -Tag 'CI' {

It 'gets a hashtable object from minishell' {
$output = & $powershell -noprofile { @{'a' = 'b'} }
($output | measure).Count | Should Be 1
($output.GetType().Name) | Should Be 'Hashtable'
($output | Measure-Object).Count | Should Be 1
$output | Should BeOfType 'Hashtable'
$output['a'] | Should Be 'b'
}

It 'gets the error stream from minishell' {
$output = & $powershell -noprofile { Write-Error 'foo' } 2>&1
($output | measure).Count | Should Be 1
($output.GetType().Name) | Should Be 'ErrorRecord'
($output | Measure-Object).Count | Should Be 1
$output | Should BeOfType 'System.Management.Automation.ErrorRecord'
$output.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException'
}

It 'gets the information stream from minishell' {
$output = & $powershell -noprofile { Write-Information 'foo' } 6>&1
($output.GetType().Name) | Should Be 'InformationRecord'
($output | Measure-Object).Count | Should Be 1
$output | Should BeOfType 'System.Management.Automation.InformationRecord'
$output | Should Be 'foo'
}
}
Expand Down Expand Up @@ -150,7 +151,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
}
foreach ($x in "--help", "-help", "-h", "-?", "--he", "-hel", "--HELP", "-hEl") {
It "Accepts '$x' as a parameter for help" {
& $powershell -noprofile $x | ?{ $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
& $powershell -noprofile $x | Where-Object { $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ Describe "Exception from initializer" -Tags "CI" {
It "static member w/ ctor" {
try {
$null = [MSFT_6397334c]::a
throw "[MSFT_6397334c]::a should have thrown"
throw "No Exception!"
}
catch
{
$_.Exception.GetType().FullName | Should Be System.TypeInitializationException
$_.Exception | Should BeOfType System.TypeInitializationException
$e = $_.Exception.InnerException.InnerException.ErrorRecord
$e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger
$e.InvocationInfo.Line | Should Match 'a = "zz"'
Expand All @@ -336,11 +336,11 @@ Describe "Exception from initializer" -Tags "CI" {
It "static member w/o ctor" {
try {
$null = [MSFT_6397334d]::a
throw "[MSFT_6397334d]::a should have thrown"
throw "No Exception!"
}
catch
{
$_.Exception.GetType().FullName | Should Be System.TypeInitializationException
$_.Exception | Should BeOfType System.TypeInitializationException
$e = $_.Exception.InnerException.InnerException.ErrorRecord
$e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger
$e.InvocationInfo.Line | Should Match 'a = "zz"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ Describe 'Classes inheritance syntax' -Tags "CI" {
[A]::b = [B]::new()
try {
[A]::b = "bla"
throw "No Exception!"
} catch {
$_.Exception.GetType().Name | Should Be SetValueInvocationException
return
$_.Exception | Should BeOfType 'System.Management.Automation.SetValueInvocationException'
}
# Fail, if come heres
'' | Should Be "Exception expected"
}
}

Expand Down Expand Up @@ -419,12 +417,10 @@ Describe 'Classes inheritance ctors' -Tags "CI" {

try {
[B]::new(101)
throw "No Exception!"
} catch {
$_.Exception.GetType().Name | Should Be MethodException
return
$_.Exception | Should BeOfType "System.Management.Automation.MethodException"
}
# Fail
'' | Should Be "Exception expected"
}

It 'call default base ctor implicitly' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ Describe "DotNetAPI" -Tags "CI" {
It "Should be able to create a new instance of a .Net object" {
[System.Guid]$guidVal = [System.Guid]::NewGuid()

$guidVal.GetType().Name | Should Be "Guid"
$guidVal | Should BeOfType Guid
}
}
4 changes: 2 additions & 2 deletions test/powershell/Language/LanguageTestSupport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function Test-ErrorStmt
$ast = Get-ParseResults $src -Ast
$asts = @(Flatten-Ast $ast.EndBlock.Statements[0])

It 'Type is ErrorStatementAst' { $asts[0].GetType() | Should Be System.Management.Automation.Language.ErrorStatementAst }
It 'Type is ErrorStatementAst' { $asts[0] | Should BeOfType System.Management.Automation.Language.ErrorStatementAst }
It "`$asts.count" { $asts.Count | Should Be ($a.Count + 1) }
It "`$asts[0].Extent.Text" { $asts[0].Extent.Text | Should Be $errorStmtExtent }
for ($i = 0; $i -lt $a.Count; ++$i)
Expand Down Expand Up @@ -198,7 +198,7 @@ function Test-Ast
$ast = Get-ParseResults $src -Ast
$ast = $ast.EndBlock.Statements[0]
Context "Ast Validation: <<$src>>" {
$ast.GetType() | Should Be System.Management.Automation.Language.ErrorStatementAst
$ast | Should BeOfType System.Management.Automation.Language.ErrorStatementAst
$ast.Flags.ContainsKey($flagName) | Should be $true

$asts = @(Flatten-Ast $ast.Flags[$flagName].Item2)
Expand Down
10 changes: 6 additions & 4 deletions test/powershell/Language/Parser/Ast.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ Describe "The SafeGetValue method on AST returns safe values" -Tags "CI" {
$HtAst = {
@{ one = 1 }
}.ast.Find({$args[0] -is $HashtableAstType}, $true)
$HtAst.SafeGetValue().GetType().Name | Should be Hashtable
$HtAst | Should Not BeNullOrEmpty
$HtAst.SafeGetValue() | Should BeOfType "Hashtable"
}
It "An Array is returned from a LiteralArrayAst" {
$ArrayAstType = [ArrayLiteralAst]
$ArrayAst = {
@( 1,2,3,4)
}.ast.Find({$args[0] -is $ArrayAstType}, $true)
$ArrayAst.SafeGetValue().GetType().Name | Should be "Object[]"
$ArrayAst | Should Not BeNullOrEmpty
,$ArrayAst.SafeGetValue() | Should BeOfType "Object[]"
}
It "The proper error is returned when a variable is referenced" {
$ast = { $a }.Ast.Find({$args[0] -is "VariableExpressionAst"},$true)
try {
$ast.SafeGetValue() | out-null
Throw "Execution Succeeded"
throw "No Exception!"
}
catch {
$_.FullyQualifiedErrorId | Should be "InvalidOperationException"
Expand All @@ -28,7 +30,7 @@ Describe "The SafeGetValue method on AST returns safe values" -Tags "CI" {
It "A ScriptBlock AST fails with the proper error" {
try {
{ 1 }.Ast.SafeGetValue()
Throw "Execution Succeeded"
throw "No Exception!"
}
catch {
$_.FullyQualifiedErrorId | Should be "InvalidOperationException"
Expand Down
24 changes: 12 additions & 12 deletions test/powershell/Language/Parser/BNotOperator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ Describe "bnot on enums" -Tags "CI" {
It "max - 1" {
$res = -bnot $enumType::MaxMinus1
$res | Should Be $enumType::MinPlus1
$res.GetType() | Should Be $enumType
$res | Should BeOfType $enumType
}

It "min + 1" {
$res = -bnot $enumType::MinPlus1
$res | Should Be $enumType::MaxMinus1
$res.GetType() | Should Be $enumType
$res | Should BeOfType $enumType
}

It "Max" {
$res = -bnot $enumType::Max
$res | Should Be $enumType::Min
$res.GetType() | Should Be $enumType
$res | Should BeOfType $enumType
}

It "Min" {
$res = -bnot $enumType::Min
$res | Should Be $enumType::Max
$res.GetType() | Should Be $enumType
$res | Should BeOfType $enumType
}
}
}
Expand Down Expand Up @@ -90,51 +90,51 @@ Describe "bnot on integral types" -Tags "CI" {
It "max - 1" {
$res = -bnot $maxMinus1
$res | Should Be (-bnot [int]$maxMinus1)
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "min + 1" {
$res = -bnot $minPlus1
$res | Should Be (-bnot [int]$minPlus1)
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "max" {
$res = -bnot $max
$res | Should Be (-bnot [int]$max)
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "min" {
$res = -bnot $min
$res | Should Be (-bnot [int]$min)
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}
return
}

It "max - 1" {
$res = -bnot $maxMinus1
$res | Should Be $minPlus1
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "min + 1" {
$res = -bnot $minPlus1
$res | Should Be $maxMinus1
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "max" {
$res = -bnot $max
$res | Should Be $min
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}

It "min" {
$res = -bnot $min
$res | Should Be $max
$res.GetType() | Should Be $expectedResultType
$res | Should BeOfType $expectedResultType
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

It '$err.Count' { $err.Count | Should Be 1 }
It '$err[0] should not be $null' { $err[0] | Should Not Be $null }
It '$err[0].GetType().Name' { $err[0].GetType().Name | Should Be ActionPreferenceStopException }
It '$err[0].GetType().Name' { $err[0] | Should BeOfType "System.Management.Automation.ActionPreferenceStopException" }
It '$err[0].ErrorRecord' { $err[0].ErrorRecord | Should not BeNullOrEmpty }
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception.GetType().Name | Should Be ItemNotFoundException }
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception | Should BeOfType "System.Management.Automation.ItemNotFoundException" }
}

It 'ActionPreference Ignore Works' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,13 @@ Describe "Unit tests for various script breakpoints" -Tags "CI" {
{
& $command

It "Script should fail to verify exception" {
$false | Should Be $true
}
throw "No Exception!"
}
catch
{
$type = $_.Exception.GetType().Name

It "Script failed expected exception" {
$type | Should Be $exception
}
It "Script failed expected exception" {
$_.Exception.GetType().Name | Should Be $exception
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this be $_.Exception | Should BeOfType $exception?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Don't work 😕

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see what is happening. $exception is point to internal types, and thus Pester cannot resolve. #Closed

}
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/powershell/Language/Scripting/I18n.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Describe 'Testing of script internationalization' -Tags "CI" {

import-localizedData mydata -uiculture nl-NL -ea SilentlyContinue -ev ev

$ev[0].Exception.GetType() | Should Be System.Management.Automation.PSInvalidOperationException
$ev | Should Not BeNullOrEmpty
$ev[0].Exception | Should BeOfType "System.Management.Automation.PSInvalidOperationException"
}

It 'Import different file name is done correctly' {
Expand Down Expand Up @@ -110,7 +111,8 @@ Describe 'Testing of script internationalization' -Tags "CI" {
import-localizedData mydata -filename bad
}

$script:exception.exception.gettype() | Should Be System.management.automation.psinvalidoperationexception
$script:exception.exception | Should Not BeNullOrEmpty
$script:exception.exception | Should BeOfType System.management.automation.psinvalidoperationexception
}

It 'Import if psd1 file is done correctly' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ else {
$PesterSkipOrPending = @{}
}
Describe "NativeLinuxCommands" -tags "CI" {
It "Should return a type of System.Object for hostname cmdlet" {
(hostname).GetType().BaseType | Should Be 'System.Object'
(hostname).GetType().Name | Should Be String
It "Should return a type of 'string' for hostname cmdlet" {
$result = hostname
$result | Should Not BeNullOrEmpty
$result | Should BeOfType string
}

It "Should find Application grep" @PesterSkipOrPending {
Expand Down
15 changes: 11 additions & 4 deletions test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,19 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" {

Context 'Error variable in multi-command pipeline (with native cmdlet)' {

(get-foo -ev foo_err | get-item -ev get_item_err ) 2>&1 > $null
BeforeAll {
(get-foo -ev foo_err | get-item -ev get_item_err ) 2>&1 > $null
}

$foo_err | Should Be "foo-error"
It '$foo_err should be "foo-error"' {
$foo_err | Should Be "foo-error"
}

It '$get_item_err.count' { $get_item_err.count | Should Be 1 }
It '$get_item_err[0].exception' { $get_item_err[0].exception.GetType() | Should Be 'System.Management.Automation.ItemNotFoundException' }
It '$get_item_err.count and $get_item_err[0].exception' {
$get_item_err.count | Should Be 1
$get_item_err[0].exception | Should Not BeNullOrEmpty
$get_item_err[0].exception | Should BeOftype 'System.Management.Automation.ItemNotFoundException'
}
}

It 'Multi-command pipeline with nested commands' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
$j = start-job -scriptblock { 1 + 1 }
}
It "Start-Job produces a job object" {
$j.gettype().fullname | should be "System.Management.Automation.PSRemotingJob"
$j | Should BeOfType System.Management.Automation.Job
}
It "Get-Job retrieves a job object" {
(Get-Job -id $j.id).gettype().fullname | should be "System.Management.Automation.PSRemotingJob"
(Get-Job -id $j.id) | Should BeOfType System.Management.Automation.Job
}
It "Remove-Job can remove a job" {
remove-job $j -force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Describe "Basic Alias Provider Tests" -Tags "CI" {

It "Test executing the new alias" {
$result = Invoke-Expression $testAliasName
$result.GetType().Name | Should Be "DateTime"
$result | Should BeOfType DateTime
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ try {

It "Verify type returned by Get-ComputerInfo" {
$computerInfo = Get-ComputerInfo
$computerInfo.GetType().Name | Should Be "ComputerInfo"
$computerInfo | Should BeOfType Microsoft.PowerShell.Commands.ComputerInfo
}
}

Expand Down Expand Up @@ -1331,9 +1331,9 @@ try {
($observed.OsFreeVirtualMemory -gt 0) | Should Be $true
}

It "(special case) Test for property = OsLocalDateTime" {
It "(special case) Test for property = OsLocalDateTime" -Pending:$true {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it failing? If it is we better have an issue tracking it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OsLocalDateTime return empty to me. And the test is wrong. Yes, we should open a new Issue...

Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw Feb 14, 2017

Choose a reason for hiding this comment

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

Yup, the test doesn't do anything about OsLocalDateTime. Please open an issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done #3146

$computerInfo = Get-ComputerInfo
$computerInfo.GetType().Name | Should Be "ComputerInfo"
$computerInfo | Should BeOfType "ComputerInfo"
}

It "(special case) Test for property = OsMaxNumberOfProcesses" {
Expand All @@ -1356,7 +1356,7 @@ try {
It "(special case) Test for Filter Property - Property filter with special wild card * and fixed" {
$propertyFilter = @("BiosC*","*")
$computerInfo = Get-ComputerInfo -Property $propertyFilter
$computerInfo.GetType().Name | Should Be "ComputerInfo"
$computerInfo | Should BeOfType Microsoft.PowerShell.Commands.ComputerInfo
}
}
}
Expand Down
Loading