Added comma to replaced characters in assemblyname#4136
Added comma to replaced characters in assemblyname#4136daxian-dbw merged 9 commits intoPowerShell:masterfrom TimCurwick:master
Conversation
|
@TimCurwick, |
|
|
||
| It "Script with a class definition can run from a path without a comma" { | ||
|
|
||
| $FilePath = '.\MyTest.ps1' |
There was a problem hiding this comment.
Please use $TestDrive for temporary files.
| } | ||
|
|
||
| catch { | ||
| $Success = $False |
There was a problem hiding this comment.
Instead use the Should Not Throw pattern. Example:
| $Success | Should Be $True | ||
| } | ||
|
|
||
| It "Script with a class definition can run from a path with a comma" { |
There was a problem hiding this comment.
Same comments as above test
| $Success | Should Be $True | ||
| } | ||
|
|
||
| It "Script with a class definition can run from a path with a comma" { |
There was a problem hiding this comment.
These two test cases can be combined into 1 using the -TestCases parameter for It. Example:
| @@ -1113,12 +1113,13 @@ internal static Assembly DefineTypes(Parser parser, Ast rootAst, TypeDefinitionA | |||
| var definedTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | |||
|
|
|||
| // First character is a special mark that allows us to cheaply ignore dynamic generated assemblies in ClrFacede.GetAssemblies() | |||
There was a problem hiding this comment.
Typo in comment for ClrFacade.
| $FilePath = '.\MyTest.ps1' | ||
|
|
||
| try { | ||
| 'class MyClass { [string]$MyProperty }; $True' | Out-File -FilePath $FilePath |
There was a problem hiding this comment.
Use testdrive: or $testdrive - then Pester will ensure the file is deleted when the test completes.
| Remove-Item -Path $FilePath | ||
| } | ||
|
|
||
| $Success | Should Be $True |
There was a problem hiding this comment.
Avoid Should Be $True - this results in a typically unhelpful message in the log.
I suggest a test that actually uses the class, so maybe something like:
Instead, try something like:
`@
class MyClass { static [string]$MyProperty = $PSScriptRoot }
[MyClass]::MyProperty
'@ > $testDrive/My,Test.ps1
& $testDrive/My,Test.ps1 | Should Match ".*My,Test.ps1"Or something like that.
There was a problem hiding this comment.
$PSScriptRoot doesn't work inside a class.
| @@ -1,42 +1,21 @@ | |||
| Describe "Script with a class definition run path" -Tags "CI" { | |||
| Describe "Script with a class definition run path" { | |||
| } | ||
|
|
||
| $Success | Should Be $True | ||
| { . $FilePath } | Should Not Throw |
There was a problem hiding this comment.
This test is not necessary - the next test covers this case.
|
@adityapatwardhan and @lzybkr could you please take another look? I think the author has addressed all your comments. |
|
@TimCurwick Thanks for your contribution! 👍 |
A script with a native class will not run if it is saved with a name or full path with a comma.
I added the comma to the list of characters that are replaced with a similar character when creating an assemblyName based on a file path. Added pester test to test.
Discussed with Jason Shirk.