Skip to content

Commit

Permalink
Remove Compatibility.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd committed Apr 7, 2024
1 parent 333417c commit 0230d8c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
2 changes: 0 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ $script = @(
"$PSScriptRoot/src/Pester.RSpec.ps1"
"$PSScriptRoot/src/Main.ps1"

# TODO: Imports Compatibility.ps1, remove the code that is there, because it is for PowerShell 2.0 compatibility!
"$PSScriptRoot/src/functions/assert/*"
"$PSScriptRoot/src/functions/assert/*/*"
"$PSScriptRoot/src/functions/assertions/*"
"$PSScriptRoot/src/functions/*"
Expand Down
4 changes: 2 additions & 2 deletions src/Format2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function Format-Nicely2 ($Value, [switch]$Pretty) {
return Format-Collection2 -Value $Value -Pretty:$Pretty
}

Format-Object2 -Value $Value -Property (Get-DisplayProperty2 (Get-Type $Value)) -Pretty:$Pretty
Format-Object2 -Value $Value -Property (Get-DisplayProperty2 $Value.GetType()) -Pretty:$Pretty
}

function Get-DisplayProperty2 ([Type]$Type) {
Expand All @@ -139,7 +139,7 @@ function Get-DisplayProperty2 ([Type]$Type) {

function Get-ShortType2 ($Value) {
if ($null -ne $value) {
Format-Type2 (Get-Type $Value)
Format-Type2 $Value.GetType()
}
else {
Format-Type2 $null
Expand Down
21 changes: 0 additions & 21 deletions src/functions/assert/Compatibility.ps1

This file was deleted.

18 changes: 9 additions & 9 deletions src/functions/assert/Equivalence/Assert-Equivalent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Compare-CollectionEquivalent ($Expected, $Actual, $Property, $Options)
}

if (-not (Is-Collection -Value $Actual)) {
v -Difference "`$Actual is not a collection it is a $(Format-Nicely2 (Get-Type $Actual)), so they are not equivalent."
v -Difference "`$Actual is not a collection it is a $(Format-Nicely2 $Actual.GetType()), so they are not equivalent."
$expectedFormatted = Format-Collection2 -Value $Expected
$expectedLength = $expected.Length
$actualFormatted = Format-Nicely2 -Value $actual
Expand Down Expand Up @@ -240,9 +240,9 @@ function Compare-ValueEquivalent ($Actual, $Expected, $Property, $Options) {
v "Equality comparator is used, values will be compared for equality."
}

v "Comparing values as $(Format-Nicely2 (Get-Type $Expected)) because `$Expected has that type."
v "Comparing values as $(Format-Nicely2 $Expected.GetType()) because `$Expected has that type."
# todo: shorter messages when both sides have the same type (do not compare by using -is, instead query the type and compare it) because -is is true even for parent types
$type = Get-Type $Expected
$type = $Expected.GetType()
$coalescedActual = $Actual -as $type
if ($Expected -ne $Actual) {
v -Difference "`$Actual is not equivalent to $(Format-Nicely2 $Expected) because it is $(Format-Nicely2 $Actual), and $(Format-Nicely2 $Actual) coalesced to $(Format-Nicely2 $type) is $(Format-Nicely2 $coalescedActual)."
Expand All @@ -257,7 +257,7 @@ function Compare-HashtableEquivalent ($Actual, $Expected, $Property, $Options) {
}

if (-not (Is-Hashtable -Value $Actual)) {
v -Difference "`$Actual is not a hashtable it is a $(Format-Nicely2 (Get-Type $Actual)), so they are not equivalent."
v -Difference "`$Actual is not a hashtable it is a $(Format-Nicely2 $Actual.GetType()), so they are not equivalent."
$expectedFormatted = Format-Nicely2 -Value $Expected
$actualFormatted = Format-Nicely2 -Value $Actual
return "Expected hashtable '$expectedFormatted', but got '$actualFormatted'."
Expand Down Expand Up @@ -323,7 +323,7 @@ function Compare-DictionaryEquivalent ($Actual, $Expected, $Property, $Options)
}

if (-not (Is-Dictionary -Value $Actual)) {
v -Difference "`$Actual is not a dictionary it is a $(Format-Nicely2 (Get-Type $Actual)), so they are not equivalent."
v -Difference "`$Actual is not a dictionary it is a $(Format-Nicely2 $Actual.GetType()), so they are not equivalent."
$expectedFormatted = Format-Nicely2 -Value $Expected
$actualFormatted = Format-Nicely2 -Value $Actual
return "Expected dictionary '$expectedFormatted', but got '$actualFormatted'."
Expand Down Expand Up @@ -387,7 +387,7 @@ function Compare-ObjectEquivalent ($Actual, $Expected, $Property, $Options) {
}

if (-not (Is-Object -Value $Actual)) {
v -Difference "`$Actual is not an object it is a $(Format-Nicely2 (Get-Type $Actual)), so they are not equivalent."
v -Difference "`$Actual is not an object it is a $(Format-Nicely2 $Actual.GetType()), so they are not equivalent."
$expectedFormatted = Format-Nicely2 -Value $Expected
$actualFormatted = Format-Nicely2 -Value $Actual
return "Expected object '$expectedFormatted', but got '$actualFormatted'."
Expand Down Expand Up @@ -553,11 +553,11 @@ function Compare-Equivalent {
}

if ($null -eq $Actual) {
v -Difference "`$Actual is $(Format-Nicely2), but `$Expected has value of type $(Format-Nicely2 (Get-Type $Expected)), so they are not equivalent."
v -Difference "`$Actual is $(Format-Nicely2), but `$Expected has value of type $(Format-Nicely2 $Expected.GetType()), so they are not equivalent."
return Get-ValueNotEquivalentMessage -Expected $Expected -Actual $Actual -Property $Path
}

v "`$Expected has type $(Get-Type $Expected), `$Actual has type $(Get-Type $Actual), they are both non-null."
v "`$Expected has type $$Expected.GetType(), `$Actual has type $$Actual.GetType(), they are both non-null."

# test value types, strings, and single item arrays with values in them as values
# expand the single item array to get to the value in it
Expand Down Expand Up @@ -609,7 +609,7 @@ function Compare-Equivalent {
return
}

v "`$Expected is an object of type $(Get-Type $Expected), we will be comparing `$Actual to objects."
v "`$Expected is an object of type $$Expected.GetType(), we will be comparing `$Actual to objects."
Compare-ObjectEquivalent -Expected $Expected -Actual $Actual -Property $Path -Options $Options
}

Expand Down
4 changes: 2 additions & 2 deletions src/functions/assert/Exception/Assert-Throw.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ function Assert-Throw {
}
}

$filterOnMessage = -not (Test-NullOrWhiteSpace $ExceptionMessage)
$filterOnMessage = -not ([string]::IsNullOrWhiteSpace($ExceptionMessage))
if ($filterOnMessage) {
$filters += "with message '$ExceptionMessage'"
if ($err.ExceptionMessage -notlike $ExceptionMessage) {
$buts += "the message was '$($err.ExceptionMessage)'"
}
}

$filterOnId = -not (Test-NullOrWhiteSpace $FullyQualifiedErrorId)
$filterOnId = -not ([string]::IsNullOrWhiteSpace($FullyQualifiedErrorId))
if ($filterOnId) {
$filters += "with FullyQualifiedErrorId '$FullyQualifiedErrorId'"
if ($err.FullyQualifiedErrorId -notlike $FullyQualifiedErrorId) {
Expand Down

0 comments on commit 0230d8c

Please sign in to comment.