-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Block type update in Add-Type cmdlet #9609
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "Add-Type" -Tags "CI" { | ||
| BeforeAll { | ||
| $guid = [Guid]::NewGuid().ToString().Replace("-","") | ||
|
|
@@ -65,7 +66,7 @@ Describe "Add-Type" -Tags "CI" { | |
| $code = @" | ||
| using System.Management.Automation; | ||
| [System.Management.Automation.Cmdlet("Get", "Thing$guid", ConfirmImpact = System.Management.Automation.ConfirmImpact.High, SupportsPaging = true)] | ||
| public class AttributeTest$guid : PSCmdlet | ||
| public class SMAAttributeTest$guid : PSCmdlet | ||
| { | ||
| protected override void EndProcessing() | ||
|
|
||
|
|
@@ -207,6 +208,15 @@ public class AttributeTest$guid : PSCmdlet | |
| { Add-Type -CompilerOptions "/platform:anycpuERROR" -Language CSharp -MemberDefinition "public static string TestString() { return ""}" -Name "TestType1" -Namespace "TestNS" -ErrorAction Stop } | Should -Throw -ErrorId "SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand" | ||
| } | ||
|
|
||
| It "Throw if the type already exists" { | ||
| Add-Type -TypeDefinition "public class Foo$guid {}" | ||
|
|
||
| # The cmdlet writes TYPE_ALREADY_EXISTS for every duplicated type and then terminates with COMPILER_ERRORS. | ||
| # So here we check 2 errors. | ||
| { Add-Type -TypeDefinition "public class Foo$guid { public int Bar {get {return 42;} }" -ErrorAction SilentlyContinue } | Should -Throw -ErrorId "COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand" | ||
| $error[1].FullyQualifiedErrorId | Should -BeExactly "TYPE_ALREADY_EXISTS,Microsoft.PowerShell.Commands.AddTypeCommand" | ||
|
Member
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. You should use
Collaborator
Author
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. The cmdlet writes TYPE_ALREADY_EXISTS for every duplicated type and then terminates with COMPILER_ERRORS. So the test is correct. (Note that we have to use
Member
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. I see. Perhaps add a comment.
Collaborator
Author
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. Comment added. |
||
| } | ||
|
|
||
| It "OutputType parameter requires that the OutputAssembly parameter be specified." { | ||
| $code = "public static string TestString() {}" | ||
| { Add-Type -TypeDefinition $code -OutputType Library } | Should -Throw -ErrorId "OUTPUTTYPE_REQUIRES_ASSEMBLY,Microsoft.PowerShell.Commands.AddTypeCommand" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.