Closed indented-automation closed 6 years ago
@indented-automation, thank you for your awesome script! I just migrated all Pester itself tests to the new syntax using it.
In the near future, I'll add it to documentation.
@indented-automation, could you declare directly that your script 'Update-PesterTest.ps1' can be used under the Apache License 2.0?
Pester itself use that license.
Thank you.
Yep, I can confirm I am happy for this to be used under that licence.
Explicit version: I am happy for Update-PesterTest.ps1 to be used under the Apache License 2.0.
Added license to gist too, just in case :)
Chris
@indented-automation, thank you.
Some tests are not correctly rewritten.
The issue with some characters is probably related to the file encoding.
PS >Get-FileEncoding <BEFORE_UPDATE>\pester\Functions\Mock.ps1
BodyName : utf-8
EncodingName : Unicode (UTF-8)
HeaderName : utf-8
WebName : utf-8
WindowsCodePage : 1200
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
IsSingleByte : False
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 65001
PS >Get-FileEncoding <AFTER_UPDATE>\pester\Functions\Mock.ps1
BodyName : utf-7
EncodingName : Unicode (UTF-7)
HeaderName : utf-7
WebName : utf-7
WindowsCodePage : 1200
IsBrowserDisplay : False
IsBrowserSave : False
IsMailNewsDisplay : True
IsMailNewsSave : True
IsSingleByte : False
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.UTF7Encoding+DecoderUTF7Fallback
IsReadOnly : True
CodePage : 65000
All files what were UTF-8 encoded before conversion and correction script are below
$Names = @( ".\Functions\Assertions\FileContentMatch.Tests.ps1"
".\Functions\Assertions\FileContentMatchExactly.Tests.ps1"
".\Functions\Mock.ps1"
".\Functions\Mock.Tests.ps1"
".\Functions\Output.Tests.ps1"
".\Functions\TestsRunningInCleanRunspace.Tests.ps1"
".\Pester.Tests.ps1")
ForEach ( $Name in $Names) {
[String]$TemporaryName = "{0}.temp" -f $Name
Get-Content $Name | Set-Content -Encoding UTF8 -Path $TemporaryName
Move-Item -Path $TemporaryName -Destination $Name -force
}
It could likely do with injection of your original encoding detection function. I haven't needed that for my purposes, but I couldn't find fault with the approach.
Realistically this only replaces the regex matching part of the process.
Finally, I found a time to add the function provided by @indented-automation to the Pester wiki.
Guys, can you review it?
@it-praktyk LGTM
I don't have time to do a PR right now, but in case it helps (anyone).
This is a different version of the migration script which (in part) rewrites the "Should Contain" assertion. This particular version also updates notation to parameterized assertions.
Posted because it does away with the use of regular expressions to find statements to update which means it should be a more robust approach.
https://gist.github.com/indented-automation/aeb14825e39dd8849beee44f681fbab3