diff --git a/Dependencies/Axiom/Axiom.psm1 b/Dependencies/Axiom/Axiom.psm1 index df782c5e3..45b4ea7e0 100644 --- a/Dependencies/Axiom/Axiom.psm1 +++ b/Dependencies/Axiom/Axiom.psm1 @@ -13,4 +13,4 @@ . $PSScriptRoot\Verify-Type.ps1 -. $PSScriptRoot\Verify-AssertionFailed.ps1 \ No newline at end of file +. $PSScriptRoot\Verify-AssertionFailed.ps1 diff --git a/Dependencies/Axiom/Verify-AssertionFailed.ps1 b/Dependencies/Axiom/Verify-AssertionFailed.ps1 index 6eaa729da..d95f586a4 100644 --- a/Dependencies/Axiom/Verify-AssertionFailed.ps1 +++ b/Dependencies/Axiom/Verify-AssertionFailed.ps1 @@ -15,9 +15,9 @@ function Verify-AssertionFailed { $err = $_ $err } - + if (-not $assertionExceptionThrown) { - $result = if ($null -eq $err) { "no assertion failure error was thrown!" } + $result = if ($null -eq $err) { "no assertion failure error was thrown!" } else { "other error was thrown! $($err | Format-List -Force * | Out-String)" } throw [Exception]"Expected the script block { $ScriptBlock } to fail in Pester assertion, but $result" } diff --git a/Dependencies/Axiom/Verify-Equal.ps1 b/Dependencies/Axiom/Verify-Equal.ps1 index 3a60a04ae..76070da61 100644 --- a/Dependencies/Axiom/Verify-Equal.ps1 +++ b/Dependencies/Axiom/Verify-Equal.ps1 @@ -9,12 +9,12 @@ if ($Expected -ne $Actual) { $message = "Expected and actual values differ!`n"+ "Expected: '$Expected'`n"+ - "Actual : '$Actual'" + "Actual : '$Actual'" if ($Expected -is [string] -and $Actual -is [string]) { $message += "`nExpected length: $($Expected.Length)`nActual length: $($Actual.Length)" } throw [Exception]$message } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-False.ps1 b/Dependencies/Axiom/Verify-False.ps1 index 8bb61fa2e..cf6c40809 100644 --- a/Dependencies/Axiom/Verify-False.ps1 +++ b/Dependencies/Axiom/Verify-False.ps1 @@ -9,4 +9,4 @@ function Verify-False { } $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-NotNull.ps1 b/Dependencies/Axiom/Verify-NotNull.ps1 index 5447b50c7..2774818a5 100644 --- a/Dependencies/Axiom/Verify-NotNull.ps1 +++ b/Dependencies/Axiom/Verify-NotNull.ps1 @@ -7,6 +7,6 @@ function Verify-NotNull { if ($null -eq $Actual) { throw [Exception]"Expected not `$null but got `$null." } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-NotSame.ps1 b/Dependencies/Axiom/Verify-NotSame.ps1 index fb47c0283..923bcc822 100644 --- a/Dependencies/Axiom/Verify-NotSame.ps1 +++ b/Dependencies/Axiom/Verify-NotSame.ps1 @@ -9,6 +9,6 @@ if ([object]::ReferenceEquals($Expected, $Actual)) { throw [Exception]"Expected the objects to be different instance but they were the same instance." } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-Null.ps1 b/Dependencies/Axiom/Verify-Null.ps1 index 002981315..6f3f203d3 100644 --- a/Dependencies/Axiom/Verify-Null.ps1 +++ b/Dependencies/Axiom/Verify-Null.ps1 @@ -7,6 +7,6 @@ function Verify-Null { if ($null -ne $Actual) { throw [Exception]"Expected `$null but got '$Actual'." } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-Same.ps1 b/Dependencies/Axiom/Verify-Same.ps1 index 7a99d74dd..eb77ea837 100644 --- a/Dependencies/Axiom/Verify-Same.ps1 +++ b/Dependencies/Axiom/Verify-Same.ps1 @@ -9,6 +9,6 @@ function Verify-Same { if (-not [object]::ReferenceEquals($Expected, $Actual)) { throw [Exception]"Expected the objects to be the same instance but they were not." } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-Throw.ps1 b/Dependencies/Axiom/Verify-Throw.ps1 index bf0115c85..979985469 100644 --- a/Dependencies/Axiom/Verify-Throw.ps1 +++ b/Dependencies/Axiom/Verify-Throw.ps1 @@ -1,4 +1,4 @@ -function Verify-Throw +function Verify-Throw { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] @@ -14,8 +14,8 @@ function Verify-Throw $exceptionThrown = $true $_ } - + if (-not $exceptionThrown) { throw [Exception]"An exception was expected, but no exception was thrown!" } -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-True.ps1 b/Dependencies/Axiom/Verify-True.ps1 index 0c22758fc..1fceb7dee 100644 --- a/Dependencies/Axiom/Verify-True.ps1 +++ b/Dependencies/Axiom/Verify-True.ps1 @@ -9,4 +9,4 @@ function Verify-True { } $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Axiom/Verify-Type.ps1 b/Dependencies/Axiom/Verify-Type.ps1 index fe9b59ce4..cbe5a9fa6 100644 --- a/Dependencies/Axiom/Verify-Type.ps1 +++ b/Dependencies/Axiom/Verify-Type.ps1 @@ -8,10 +8,10 @@ if ($Actual -isnot $Expected) { $message = "Expected value to be of type $($Expected.FullName)" - $Actual = "but got " + $(if ($null -eq $Actual) { "''" } + $Actual = "but got " + $(if ($null -eq $Actual) { "''" } else { "'$($Actual.GetType().FullName)'" }) throw [Exception]"$message, $Actual" } - + $Actual -} \ No newline at end of file +} diff --git a/Dependencies/Format/Format.Tests.ps1 b/Dependencies/Format/Format.Tests.ps1 index 483587d31..b4aa40098 100644 --- a/Dependencies/Format/Format.Tests.ps1 +++ b/Dependencies/Format/Format.Tests.ps1 @@ -1,6 +1,6 @@ $here = $MyInvocation.MyCommand.Path | Split-Path Get-Module Axiom,Format | Remove-Module -Import-Module $here\..\Axiom\Axiom.psm1 -ErrorAction 'stop' -DisableNameChecking +Import-Module $here\..\Axiom\Axiom.psm1 -ErrorAction 'stop' -DisableNameChecking Import-Module $here\Format.psm1 -ErrorAction 'stop' -DisableNameChecking function New-PSObject ([hashtable]$Property) { @@ -9,30 +9,30 @@ function New-PSObject ([hashtable]$Property) { function New-Dictionary ([hashtable]$Hashtable) { $d = new-object "Collections.Generic.Dictionary[string,object]" - + $Hashtable.GetEnumerator() | foreach { $d.Add($_.Key, $_.Value) } $d } # Add-Type -TypeDefinition 'namespace Assertions.TestType { public class Person { public string Name {get;set;} public int Age {get;set;}}}' -Describe "Format-Collection" { +Describe "Format-Collection" { It "Formats collection of values '' to '' using comma separator" -TestCases @( @{ Value = (1, 2, 3); Expected = "@(1, 2, 3)" } - ) { + ) { param ($Value, $Expected) Format-Collection -Value $Value | Verify-Equal $Expected } } -Describe "Format-Number" { +Describe "Format-Number" { It "Formats number to use . separator (tests anything only on non-english systems --todo)" -TestCases @( @{ Value = 1.1; }, @{ Value = [double] 1.1; }, @{ Value = [float] 1.1; }, @{ Value = [single] 1.1; }, @{ Value = [decimal] 1.1; } - ) { + ) { param ($Value) Format-Number -Value $Value | Verify-Equal "1.1" } @@ -43,7 +43,7 @@ Describe "Format-Number" { # It "Formats object '' to ''" -TestCases @( # @{ Value = (New-PSObject @{Name = 'Jakub'; Age = 28}); Expected = "PSObject{Age=28; Name=Jakub}"}, # @{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"} -# ) { +# ) { # param ($Value, $Expected) # Format-Object -Value $Value | Verify-Equal $Expected # } @@ -51,12 +51,12 @@ Describe "Format-Number" { # It "Formats object '' with selected properties '' to ''" -TestCases @( # @{ Value = (New-PSObject @{Name = 'Jakub'; Age = 28}); SelectedProperties = "Age"; Expected = "PSObject{Age=28}"}, # @{ Value = (Get-Process -Name Idle); SelectedProperties = 'Name', 'Id'; Expected = "Diagnostics.Process{Id=0; Name=Idle}" }, -# @{ +# @{ # Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}) # SelectedProperties = 'Name' # Expected = "Assertions.TestType.Person{Name=Jakub}" # } -# ) { +# ) { # param ($Value, $SelectedProperties, $Expected) # Format-Object -Value $Value -Property $SelectedProperties | Verify-Equal $Expected # } @@ -72,13 +72,13 @@ Describe "Format-Boolean" { } } -Describe "Format-Null" { +Describe "Format-Null" { It "Formats null to '`$null'" { Format-Null | Verify-Equal '$null' } } -Describe "Format-String" { +Describe "Format-String" { It "Formats empty string to ''" { Format-String -Value "" | Verify-Equal '' } @@ -88,20 +88,20 @@ Describe "Format-String" { } } -Describe "Format-DateTime" { +Describe "Format-DateTime" { It "Formats date to orderable format with ticks" { Format-Date -Value ([dateTime]239842659899234234) | Verify-Equal '0761-01-12T16:06:29.9234234' } } -Describe "Format-ScriptBlock" { +Describe "Format-ScriptBlock" { It "Formats scriptblock as string with curly braces" { Format-ScriptBlock -Value {abc} | Verify-Equal '{abc}' } } # skipping object formatting for now -# Describe "Format-Hashtable" { +# Describe "Format-Hashtable" { # It "Formats empty hashtable as @{}" { # Format-Hashtable @{} | Verify-Equal '@{}' # } @@ -117,7 +117,7 @@ Describe "Format-ScriptBlock" { # } # skipping object formatting for now -# Describe "Format-Dictionary" { +# Describe "Format-Dictionary" { # It "Formats empty dictionary as @{}" { # Format-Dictionary (New-Dictionary @{}) | Verify-Equal 'Dictionary{}' # } @@ -149,7 +149,7 @@ Describe "Format-Nicely" { #@{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"} #@{ Value = @{Name = 'Jakub'; Age = 28}; Expected = '@{Age=28; Name=Jakub}' } #@{ Value = New-Dictionary @{Age = 28; Name = 'Jakub'}; Expected = 'Dictionary{Age=28; Name=Jakub}' } - ) { + ) { param($Value, $Expected) Format-Nicely -Value $Value | Verify-Equal $Expected } @@ -177,7 +177,7 @@ Describe "Format-Type" { Format-Type -Value $Value | Verify-Equal $Expected } } - + Describe "Get-ShortType" { It "Given '' it returns the correct shortened type name ''" -TestCases @( @@ -192,4 +192,3 @@ Describe "Get-ShortType" { Get-ShortType -Value $Value | Verify-Equal $Expected } } - \ No newline at end of file diff --git a/Dependencies/Format/Format.psm1 b/Dependencies/Format/Format.psm1 index 1b1f4175a..a1f58850a 100644 --- a/Dependencies/Format/Format.psm1 +++ b/Dependencies/Format/Format.psm1 @@ -1,6 +1,6 @@ Import-Module $PSScriptRoot\..\TypeClass\TypeClass.psm1 -DisableNameChecking -function Format-Collection ($Value, [switch]$Pretty) { +function Format-Collection ($Value, [switch]$Pretty) { $Limit = 10 $separator = ', ' if ($Pretty){ @@ -54,7 +54,7 @@ function Format-ScriptBlock ($Value) { '{' + $Value + '}' } -function Format-Number ($Value) { +function Format-Number ($Value) { [string]$Value } @@ -62,10 +62,10 @@ function Format-Hashtable ($Value) { $head = '@{' $tail = '}' - $entries = $Value.Keys | sort | foreach { + $entries = $Value.Keys | sort | foreach { $formattedValue = Format-Nicely $Value.$_ "$_=$formattedValue" } - + $head + ( $entries -join '; ') + $tail } @@ -73,16 +73,16 @@ function Format-Dictionary ($Value) { $head = 'Dictionary{' $tail = '}' - $entries = $Value.Keys | sort | foreach { + $entries = $Value.Keys | sort | foreach { $formattedValue = Format-Nicely $Value.$_ "$_=$formattedValue" } - + $head + ( $entries -join '; ') + $tail } -function Format-Nicely ($Value, [switch]$Pretty) { - if ($null -eq $Value) - { +function Format-Nicely ($Value, [switch]$Pretty) { + if ($null -eq $Value) + { return Format-Null -Value $Value } @@ -104,7 +104,7 @@ function Format-Nicely ($Value, [switch]$Pretty) { return '['+ (Format-Type -Value $Value) + ']' } - if (Is-DecimalNumber -Value $Value) + if (Is-DecimalNumber -Value $Value) { return Format-Number -Value $Value } @@ -114,8 +114,8 @@ function Format-Nicely ($Value, [switch]$Pretty) { return Format-ScriptBlock -Value $Value } - if (Is-Value -Value $Value) - { + if (Is-Value -Value $Value) + { return $Value } @@ -125,7 +125,7 @@ function Format-Nicely ($Value, [switch]$Pretty) { return [string]$Value #return Format-Hashtable -Value $Value } - + if (Is-Dictionary -Value $Value) { # no advanced formatting of objects in the first version, till I balance it @@ -133,8 +133,8 @@ function Format-Nicely ($Value, [switch]$Pretty) { #return Format-Dictionary -Value $Value } - if (Is-Collection -Value $Value) - { + if (Is-Collection -Value $Value) + { return Format-Collection -Value $Value -Pretty:$Pretty } @@ -145,13 +145,13 @@ function Format-Nicely ($Value, [switch]$Pretty) { function Sort-Property ($InputObject, [string[]]$SignificantProperties, $Limit = 4) { - $properties = @($InputObject.PSObject.Properties | - where { $_.Name -notlike "_*"} | - select -expand Name | + $properties = @($InputObject.PSObject.Properties | + where { $_.Name -notlike "_*"} | + select -expand Name | sort) $significant = @() $rest = @() - foreach ($p in $properties) { + foreach ($p in $properties) { if ($significantProperties -contains $p) { $significant += $p } @@ -182,7 +182,7 @@ function Get-ShortType ($Value) { -replace "^PSCustomObject$","PSObject" ` -replace "^Object\[\]$","collection" ` } - else + else { Format-Type $null } @@ -192,8 +192,8 @@ function Format-Type ([Type]$Value) { if ($null -eq $Value) { return '' } - - [string]$Value + + [string]$Value } @@ -212,4 +212,4 @@ Export-ModuleMember -Function @( 'Format-Nicely' 'Get-DisplayProperty' 'Get-ShortType' -) \ No newline at end of file +) diff --git a/Dependencies/TypeClass/TypeClass.Tests.ps1 b/Dependencies/TypeClass/TypeClass.Tests.ps1 index 8c02bf757..c6e122bf3 100644 --- a/Dependencies/TypeClass/TypeClass.Tests.ps1 +++ b/Dependencies/TypeClass/TypeClass.Tests.ps1 @@ -3,7 +3,7 @@ Import-Module $here/TypeClass.psm1 -DisableNameChecking function New-Dictionary ([hashtable]$Hashtable) { $d = new-object "Collections.Generic.Dictionary[string,object]" - + $Hashtable.GetEnumerator() | foreach { $d.Add($_.Key, $_.Value) } $d @@ -20,7 +20,7 @@ Describe "Is-Value" { @{ Value = @("abc")}, @{ Value = @(1)}, @{ Value = {abc}} - ) { + ) { param($Value) Is-Value -Value $Value | Verify-True } @@ -35,7 +35,7 @@ Describe "Is-Value" { @{ Value = @{} }, @{ Value = [type] }, @{ Value = (New-Object -TypeName Diagnostics.Process) } - ) { + ) { param($Value) Is-Value -Value $Value | Verify-False } @@ -43,31 +43,31 @@ Describe "Is-Value" { #number -Describe "Is-DecimalNumber" { +Describe "Is-DecimalNumber" { It "Given a number it returns `$true" -TestCases @( @{ Value = 1.1; }, @{ Value = [double] 1.1; }, @{ Value = [float] 1.1; }, @{ Value = [single] 1.1; }, @{ Value = [decimal] 1.1; } - ) { + ) { param ($Value) Is-DecimalNumber -Value $Value | Verify-True } - It "Given a string it returns `$false" { + It "Given a string it returns `$false" { Is-DecimalNumber -Value "abc" | Verify-False } } -Describe "Is-ScriptBlock" { +Describe "Is-ScriptBlock" { It "Given a scriptblock '{}' it returns `$true" -TestCases @( @{ Value = {} }, @{ Value = {abc} }, @{ Value = { Get-Process -Name Idle } } ) { param ($Value) - Is-ScriptBlock -Value $Value | Verify-True + Is-ScriptBlock -Value $Value | Verify-True } It "Given a value '' that is not a scriptblock it returns `$false" -TestCases @( @@ -77,16 +77,16 @@ Describe "Is-ScriptBlock" { @{ Value = [Type] } ) { param ($Value) - Is-ScriptBlock -Value $Value | Verify-False + Is-ScriptBlock -Value $Value | Verify-False } } # -- KeyValue collections -Describe "Is-Hashtable" { +Describe "Is-Hashtable" { It "Given hashtable '' it returns `$true" -TestCases @( @{Value = @{} } @{Value = @{Name="Jakub"} } - ) { + ) { param($Value) Is-Hashtable -Value $Value | Verify-True @@ -95,18 +95,18 @@ Describe "Is-Hashtable" { It "Given a value '' which is not a hashtable it returns `$false" -TestCases @( @{ Value = "Jakub" } @{ Value = 1..4 } - ) { + ) { param ($Value) Is-Hashtable -Value $Value | Verify-False } } -Describe "Is-Dictionary" { +Describe "Is-Dictionary" { It "Given dictionary '' it returns `$true" -TestCases @( @{ Value = New-Object "Collections.Generic.Dictionary[string,object]" } @{ Value= New-Dictionary @{Name="Jakub"} } - ) { + ) { param($Value) Is-Dictionary -Value $Value | Verify-True @@ -115,7 +115,7 @@ Describe "Is-Dictionary" { It "Given a value '' which is not a dictionary it returns `$false" -TestCases @( @{ Value = "Jakub" } @{ Value = 1..4 } - ) { + ) { param ($Value) Is-Dictionary -Value $Value | Verify-False @@ -140,7 +140,7 @@ Describe "Is-Collection" { It "Given an object '' of type '' that is not a collection it returns `$false" -TestCases @( @{ Value = $null } - + @{ Value = [char] 'a' } @{ Value = "a" } @@ -168,4 +168,4 @@ Describe "Is-Collection" { param($Value) Is-Collection -Value $Value | Verify-False } -} \ No newline at end of file +} diff --git a/Dependencies/TypeClass/TypeClass.psm1 b/Dependencies/TypeClass/TypeClass.psm1 index 8aafcb6de..a29d50c16 100644 --- a/Dependencies/TypeClass/TypeClass.psm1 +++ b/Dependencies/TypeClass/TypeClass.psm1 @@ -3,7 +3,7 @@ function Is-Value ($Value) { $Value -is [ValueType] -or $Value -is [string] -or $value -is [scriptblock] } -function Is-Collection ($Value) { +function Is-Collection ($Value) { # check for value types and strings explicitly # because otherwise it does not work for decimal # so let's skip all values we definitely know @@ -20,22 +20,22 @@ function Is-ScriptBlock ($Value) { $Value -is [ScriptBlock] } -function Is-DecimalNumber ($Value) { +function Is-DecimalNumber ($Value) { $Value -is [float] -or $Value -is [single] -or $Value -is [double] -or $Value -is [decimal] } -function Is-Hashtable ($Value) { - $Value -is [hashtable] +function Is-Hashtable ($Value) { + $Value -is [hashtable] } -function Is-Dictionary ($Value) { - $Value -is [System.Collections.IDictionary] +function Is-Dictionary ($Value) { + $Value -is [System.Collections.IDictionary] } function Is-Object ($Value) { - # here we need to approximate that that object is not value - # or any special category of object, so other checks might + # here we need to approximate that that object is not value + # or any special category of object, so other checks might # need to be added -not ($null -eq $Value -or (Is-Value -Value $Value) -or (Is-Collection -Value $Value)) diff --git a/Pester.Tests.ps1 b/Pester.Tests.ps1 index 8ae4779bd..e13110a5a 100644 --- a/Pester.Tests.ps1 +++ b/Pester.Tests.ps1 @@ -157,6 +157,7 @@ Describe 'Style rules' -Tag StyleRules { Get-ChildItem $pesterRoot\* -Include *.ps1,*.psm1, *.psd1 Get-ChildItem (Join-Path $pesterRoot 'en-US') -Include *.ps1,*.psm1, *.psd1, *.txt -Recurse Get-ChildItem (Join-Path $pesterRoot 'Functions') -Include *.ps1,*.psm1, *.psd1 -Recurse + Get-ChildItem (Join-Path $pesterRoot 'Dependencies') -Include *.ps1,*.psm1, *.psd1 -Recurse ) It 'Pester source files contain no trailing whitespace' {