Repository navigation
Fixing HashMap to PSCustomObject object conversion (#2295) #2533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,14 @@ | |
| @{ Name = 'Hashtable(Stored in a variable) conversion to PSCustomObject succeeds (Insertion Order is not retained)'; | ||
| Cmd = "`$ht = @{one=1;two=2};[pscustomobject]`$ht"; | ||
| ExpectedType = 'System.Management.automation.psobject' | ||
| }, | ||
| @{ Name = 'New-Object cmdlet should accept `$null as Property argument for pscustomobject'; | ||
| Cmd = "new-object pscustomobject -property `$null"; | ||
| ExpectedType = 'System.Management.automation.psobject' | ||
| }, | ||
| @{ Name = 'New-Object cmdlet should accept empty hashtable as property argument for pscustomobject'; | ||
| Cmd = "`$ht = @{};new-object pscustomobject -property `$ht"; | ||
| ExpectedType = 'System.Management.automation.psobject' | ||
| } | ||
| ) | ||
|
|
||
|
|
@@ -129,5 +137,21 @@ | |
| $obj.PSTypeNames.Count | Should Be 3 | ||
| $obj.PSTypeNames[0] | Should Be 'System.Object' | ||
| } | ||
| It "new-object should fail to create object for System.Management.Automation.PSCustomObject" { | ||
|
|
||
| $errorObj = $null | ||
| $obj = $null | ||
| $ht = @{one=1;two=2} | ||
| try | ||
| { | ||
| $obj = New-Object System.Management.Automation.PSCustomObject -property $ht | ||
| } | ||
| catch | ||
| { | ||
| $errorObj = $_ | ||
| } | ||
| $obj | should be $null | ||
| $errorObj.FullyQualifiedErrorId | should be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a follow-up item on that to completely remove this type?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably not worth the hassle - it's a public api and hence a breaking change, and there is one valid use of the type (though that use can be expressed differently). |
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any object?
-Property $nullseems like a special case.Again the same question: is it the right test or it's just the current behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. Corrected the test.