Releases: nohwnd/Assert
0.9.7
What's Changed
-
Add pipeline input by @ronaldborman in #52
-
Add publish.ps1 for easier release.
New Contributors
- @ronaldborman made their first contribution in #52
Full Changelog: 0.9.6...0.9.7
0.9.6
What's Changed
- Fix exception serialization problem that happen on PowerShell 7, and prevents this module from being used.
Infrastructure changes:
- Move to pester 5 by @nohwnd in #49
- Use newer version of Pester (4.4.3 instead of 4.4.0) in CI and do not use -SkipPublisherCheck switch on Install-Module any more by @bergmeister in #42
- Auto-fix PSSA warnings (2nd attempt with no encoding change) by @bergmeister in #43
- Add Appveyor yml file to run tests against Windows PowerShell 5.1, PowerShell Core on Windows and PowerShell Core on Linux (Ubuntu) by @bergmeister in #40
New Contributors
- @bergmeister made their first contribution in #42
Full Changelog: 0.9.5...0.9.6
0.9.5
0.9.4 is unlisted in gallery. It was tagged on incorrect commit.
What is new since 0.9.3
PowerShell 2 and cross-platform compatibility
Assert is now compatible PowerShell 2, 3, 4, 5 and PowerShell Core 6 on Linux and MacOS 🎉🍾🥂🧁
Only compare what is on Expected
Use -ExcludePathsNotOnExpected
to compare only what is defined on Expected. This is extremely useful when you are only interested in a subset of data on the object, and especially when the object contains volatile data such as counters.
$expected = [PSCustomObject] @{
Status = 'OK'
Caption = 'Microsoft Windows 10 Pro N'
WindowsDirectory = 'C:\Windows'
}
$actual = Get-CimInstance -class win32_OperatingSystem
$options = Get-EquivalencyOption -ExcludePathsNotOnExpected
Assert-Equivalent -Expected $expected -Actual $actual -Option $options
# compare the results with
# Assert-Equivalent -Expected $expected -Actual $actual
Exclude paths, and wildcarded paths
Use -ExcludePath
option to exclude a path from the comparison. This is useful when there is a small set of properties to skip, because it allows your tests to detect changes in the actual object if any property is added, so for example a great opportunity to use this would be for REST api the uses CreatedAt
timestamps on objects.
Here a more local example that skips Type property on any Language key in the hashtable. Notice that we are using traversing different types of objects (PSObject and Hashtable) and are still able to define the path easily.
$expected = [PSCustomObject] @{
ProgrammingLanguages = @{
Language1 = [PSCustomObject] @{
Name = "C#"
Type = "OO"
}
Language2 = [PSCustomObject] @{
Name = "PowerShell"
Type = "Scripting"
}
}
}
$actual = [PSCustomObject] @{
ProgrammingLanguages = @{
Language1 = [PSCustomObject] @{
Name = "C#"
}
Language2 = [PSCustomObject] @{
Name = "PowerShell"
}
}
}
$options = Get-EquivalencyOption -ExcludePath "ProgrammingLanguages.Language*.Type"
Assert-Equivalent -Actual $actual -Expected $expected -Options $options
Breaking changes
There should be none, but the api for Options is not final, and will most likely get placed on Assert-Equivalent
directly in release 1.0.0
.
0.9.3
What is new in 0.9.3
?
-Verbose
parameter to Assert-Equivalence
Comparing big objects with many properties is very difficult to debug when you don't see what exactly is happening. So Assert-Equivalent
now has a -Verbose
switch that shows where in the object we are, if there was a difference or equivalence, and other verbose information about what is happening.
( The feature is mostly done, all types are logging, except for DataTable and DataRow.)
Example:
Import-Module -Name Assert -RequiredVersion 0.9.3
function Get-Object () {
[PSCustomObject]@{
Name = 'Jakub'
Age = 28
KnowsPowerShell = $true
Languages = 'Czech', 'English'
ProgrammingLanguage =
[PSCustomObject]@{
Name = 'PowerShell'
Type = 'Scripting'
}
}
}
# get two objects that have the same data, but are different instances
Assert-Equivalent -Actual (Get-Object) -Expected (Get-Object) -Verbose
VERBOSE: $Expected has type System.Management.Automation.PSCustomObject, $Actual has type System.Management.Automation.PSCustomObject, they are both non-null.
VERBOSE: $Expected is an object of type System.Management.Automation.PSCustomObject, we will be comparing $Actual to objects.
VERBOSE: Comparing all (5) properties of $Expected to $Actual.
VERBOSE: Property 'Name was found on $Actual, comparing them for equivalence.
VERBOSE: (.Name) - $Expected has type string, $Actual has type string, they are both non-null.
VERBOSE: (.Name) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.Name) - Comparing values as string because $Expected has that type.
VERBOSE: (.Name) EQUIVALENCE - $Actual is equivalent to Jakub because it is Jakub, and Jakub coalesced to string is Jakub.
VERBOSE: EQUIVALENCE - Property 'Name is equivalent.
VERBOSE: Property 'Age was found on $Actual, comparing them for equivalence.
VERBOSE: (.Age) - $Expected has type int, $Actual has type int, they are both non-null.
VERBOSE: (.Age) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.Age) - Comparing values as int because $Expected has that type.
VERBOSE: (.Age) EQUIVALENCE - $Actual is equivalent to 28 because it is 28, and 28 coalesced to int is 28.
VERBOSE: EQUIVALENCE - Property 'Age is equivalent.
VERBOSE: Property 'KnowsPowerShell was found on $Actual, comparing them for equivalence.
VERBOSE: (.KnowsPowerShell) - $Expected has type bool, $Actual has type bool, they are both non-null.
VERBOSE: (.KnowsPowerShell) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.KnowsPowerShell) - Comparing values as bool because $Expected has that type.
VERBOSE: (.KnowsPowerShell) EQUIVALENCE - $Actual is equivalent to $true because it is $true, and $true coalesced to bool is $true.
VERBOSE: EQUIVALENCE - Property 'KnowsPowerShell is equivalent.
VERBOSE: Property 'Languages was found on $Actual, comparing them for equivalence.
VERBOSE: (.Languages) - $Expected has type System.Object[], $Actual has type System.Object[], they are both non-null.
VERBOSE: (.Languages) - $Expected is a collection, we will be comparing $Actual to collections.
VERBOSE: (.Languages) - Comparing items in collection, $Expected has lenght 2, $Actual has length 2.
VERBOSE: (.Languages) -
Searching for $Expected[0]:
VERBOSE: (.Languages) - Comparing $Actual[0] to $Expected[0] to see if they are equivalent.
VERBOSE: (.Languages) - $Expected has type string, $Actual has type string, they are both non-null.
VERBOSE: (.Languages) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.Languages) - Comparing values as string because $Expected has that type.
VERBOSE: (.Languages) EQUIVALENCE - $Actual is equivalent to Czech because it is Czech, and Czech coalesced to string is Czech.
VERBOSE: (.Languages) EQUIVALENCE - Found equivalent item for $Expected[0] at $Actual[0].
VERBOSE: (.Languages) -
Searching for $Expected[1]:
VERBOSE: (.Languages) - Skipping $Actual[0] because it is already taken.
VERBOSE: (.Languages) - Comparing $Actual[1] to $Expected[1] to see if they are equivalent.
VERBOSE: (.Languages) - $Expected has type string, $Actual has type string, they are both non-null.
VERBOSE: (.Languages) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.Languages) - Comparing values as string because $Expected has that type.
VERBOSE: (.Languages) EQUIVALENCE - $Actual is equivalent to English because it is English, and English coalesced to string is English.
VERBOSE: (.Languages) EQUIVALENCE - Found equivalent item for $Expected[1] at $Actual[1].
VERBOSE: (.Languages) EQUIVALENCE - $Actual and $Expected arrays are equivalent.
VERBOSE: EQUIVALENCE - Property 'Languages is equivalent.
VERBOSE: Property 'ProgrammingLanguage was found on $Actual, comparing them for equivalence.
VERBOSE: (.ProgrammingLanguage) - $Expected has type System.Management.Automation.PSCustomObject, $Actual has type System.Management.Automation.PSCustomObject, they are both non-null.
VERBOSE: (.ProgrammingLanguage) - $Expected is an object of type System.Management.Automation.PSCustomObject, we will be comparing $Actual to objects.
VERBOSE: (.ProgrammingLanguage) - Comparing all (2) properties of $Expected to $Actual.
VERBOSE: (.ProgrammingLanguage) - Property 'Name was found on $Actual, comparing them for equivalence.
VERBOSE: (.ProgrammingLanguage.Name) - $Expected has type string, $Actual has type string, they are both non-null.
VERBOSE: (.ProgrammingLanguage.Name) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.ProgrammingLanguage.Name) - Comparing values as string because $Expected has that type.
VERBOSE: (.ProgrammingLanguage.Name) EQUIVALENCE - $Actual is equivalent to PowerShell because it is PowerShell, and PowerShell coalesced to string is PowerShell.
VERBOSE: (.ProgrammingLanguage) EQUIVALENCE - Property 'Name is equivalent.
VERBOSE: (.ProgrammingLanguage) - Property 'Type was found on $Actual, comparing them for equivalence.
VERBOSE: (.ProgrammingLanguage.Type) - $Expected has type string, $Actual has type string, they are both non-null.
VERBOSE: (.ProgrammingLanguage.Type) - $Expected is a value (value type, string, single value array, or a scriptblock), we will be comparing $Actual to value types.
VERBOSE: (.ProgrammingLanguage.Type) - Comparing values as string because $Expected has that type.
VERBOSE: (.ProgrammingLanguage.Type) EQUIVALENCE - $Actual is equivalent to Scripting because it is Scripting, and Scripting coalesced to string is Scripting.
VERBOSE: (.ProgrammingLanguage) EQUIVALENCE - Property 'Type is equivalent.
VERBOSE: (.ProgrammingLanguage) EQUIVALENCE - $Actual has no extra properties that $Expected does not have.
VERBOSE: EQUIVALENCE - Property 'ProgrammingLanguage is equivalent.
VERBOSE: EQUIVALENCE - $Actual has no extra properties that $Expected does not have.
VERBOSE: EQUIVALENCE - $Actual and $Expected are equivalent.
(The output is still in progress, suggestions to make it better are welcome, but keep in mind that it needs to work for objects much bigger than this.)
Bug fixes:
- Fixes bug where equivalent collections with three or more same items were reported as different
- Fixes bug where the only diff the only