-
Notifications
You must be signed in to change notification settings - Fork 853
ILVerify: soft comparison ignoring IL byte offset drift #19553
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
Open
techiedesu
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
techiedesu:ilverify-soft-comparison
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−12
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Pester tests for ILVerify helper functions defined in ilverify.ps1. | ||
| # Compatible with Pester 3.x+ (ships with Windows PowerShell). | ||
| # Run with: Invoke-Pester ./tests/ILVerify/ilverify.Tests.ps1 | ||
|
|
||
| # Extract and load only the function definitions from ilverify.ps1 | ||
| # without executing the build/verification logic. | ||
| $scriptContent = Get-Content "$PSScriptRoot/ilverify.ps1" -Raw | ||
| $ast = [System.Management.Automation.Language.Parser]::ParseInput($scriptContent, [ref]$null, [ref]$null) | ||
| $functions = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false) | ||
| foreach ($fn in $functions) { | ||
| Invoke-Expression $fn.Extent.Text | ||
| } | ||
|
|
||
| Describe "Normalize-IlverifyOutputLine" { | ||
| It "removes closure suffixes" { | ||
| Normalize-IlverifyOutputLine 'Foo+clo@924-516::Invoke()' | Should Be 'Foo+clo::Invoke()' | ||
| } | ||
|
|
||
| It "removes function suffixes with line numbers" { | ||
| Normalize-IlverifyOutputLine 'parseOption@269::Bar()' | Should Be 'parseOption::Bar()' | ||
| } | ||
|
|
||
| It "removes 'at line NNNN'" { | ||
| Normalize-IlverifyOutputLine 'something at line 1234 rest' | Should Be 'something rest' | ||
| } | ||
|
|
||
| It "removes pipe stage patterns" { | ||
| Normalize-IlverifyOutputLine 'Foo+Pipe #1 stage #1 at line 1782@1782::Invoke()' | Should Be 'Foo+::Invoke()' | ||
| } | ||
|
|
||
| It "collapses multiple spaces" { | ||
| Normalize-IlverifyOutputLine 'a b c' | Should Be 'a b c' | ||
| } | ||
|
|
||
| It "trims leading and trailing whitespace" { | ||
| Normalize-IlverifyOutputLine ' hello world ' | Should Be 'hello world' | ||
| } | ||
| } | ||
|
|
||
| Describe "Remove-IlverifyOffsets" { | ||
| It "strips a single offset from an error line" { | ||
| $line = "[IL]: Error [StackByRef]: : Foo::Bar(int32)][offset 0x0000001E][found Native Int] Expected ByRef." | ||
| $result = Remove-IlverifyOffsets @($line) | ||
| $result | Should Be "[IL]: Error [StackByRef]: : Foo::Bar(int32)][found Native Int] Expected ByRef." | ||
| } | ||
|
|
||
| It "handles uppercase and lowercase hex digits" { | ||
| $result = Remove-IlverifyOffsets @("prefix [offset 0xABcd0012] suffix") | ||
| $result | Should Be "prefix suffix" | ||
| } | ||
|
|
||
| It "trims trailing whitespace" { | ||
| $result = Remove-IlverifyOffsets @("some text ") | ||
| $result | Should Be "some text" | ||
| } | ||
|
|
||
| It "returns empty array for empty input" { | ||
| $result = @(Remove-IlverifyOffsets @()) | ||
| $result.Count | Should Be 0 | ||
| } | ||
|
|
||
| It "processes multiple lines" { | ||
| $lines = @( | ||
| "[IL]: Error [X]: : A::M()][offset 0x00000011][found Y] Msg1.", | ||
| "[IL]: Error [X]: : B::N()][offset 0x00000022][found Z] Msg2." | ||
| ) | ||
| $result = Remove-IlverifyOffsets $lines | ||
| $result.Count | Should Be 2 | ||
| $result[0] | Should Be "[IL]: Error [X]: : A::M()][found Y] Msg1." | ||
| $result[1] | Should Be "[IL]: Error [X]: : B::N()][found Z] Msg2." | ||
| } | ||
|
|
||
| It "passes through lines without offsets unchanged" { | ||
| $result = Remove-IlverifyOffsets @("no offsets here") | ||
| $result | Should Be "no offsets here" | ||
| } | ||
| } | ||
|
|
||
| Describe "Soft comparison (offset-tolerant)" { | ||
| It "matches when only IL offsets differ" { | ||
| $output = @( | ||
| "[IL]: Error [StackByRef]: : Foo::Bar()][offset 0x0000001E][found Native Int] Expected ByRef.", | ||
| "[IL]: Error [ReturnPtrToStack]: : Baz::Qux()][offset 0x00000070] Return type is ByRef." | ||
| ) | ||
| $baseline = @( | ||
| "[IL]: Error [StackByRef]: : Foo::Bar()][offset 0x0000001A][found Native Int] Expected ByRef.", | ||
| "[IL]: Error [ReturnPtrToStack]: : Baz::Qux()][offset 0x00000064] Return type is ByRef." | ||
| ) | ||
| $cmp = Compare-Object (Remove-IlverifyOffsets $output) (Remove-IlverifyOffsets $baseline) | ||
| $cmp | Should BeNullOrEmpty | ||
| } | ||
|
|
||
| It "detects real differences even when offsets also differ" { | ||
| $output = @( | ||
| "[IL]: Error [StackByRef]: : Foo::Bar()][offset 0x0000001E][found Native Int] Expected ByRef.", | ||
| "[IL]: Error [NEW_ERROR]: : New::Method()][offset 0x00000099][found X] New error." | ||
| ) | ||
| $baseline = @( | ||
| "[IL]: Error [StackByRef]: : Foo::Bar()][offset 0x0000001A][found Native Int] Expected ByRef.", | ||
| "[IL]: Error [ReturnPtrToStack]: : Baz::Qux()][offset 0x00000064] Return type is ByRef." | ||
| ) | ||
| $cmp = Compare-Object (Remove-IlverifyOffsets $output) (Remove-IlverifyOffsets $baseline) | ||
| $cmp | Should Not BeNullOrEmpty | ||
| } | ||
|
|
||
| It "detects added errors" { | ||
| $output = @( | ||
| "[IL]: Error [X]: : Foo::A()][offset 0x00000011] Msg.", | ||
| "[IL]: Error [X]: : Foo::B()][offset 0x00000022] Msg.", | ||
| "[IL]: Error [X]: : Foo::C()][offset 0x00000033] New." | ||
| ) | ||
| $baseline = @( | ||
| "[IL]: Error [X]: : Foo::A()][offset 0x00000011] Msg.", | ||
| "[IL]: Error [X]: : Foo::B()][offset 0x00000022] Msg." | ||
| ) | ||
| $cmp = Compare-Object (Remove-IlverifyOffsets $output) (Remove-IlverifyOffsets $baseline) | ||
| $cmp | Should Not BeNullOrEmpty | ||
| } | ||
|
|
||
| It "detects removed errors" { | ||
| $output = @( | ||
| "[IL]: Error [X]: : Foo::A()][offset 0x00000011] Msg." | ||
| ) | ||
| $baseline = @( | ||
| "[IL]: Error [X]: : Foo::A()][offset 0x00000011] Msg.", | ||
| "[IL]: Error [X]: : Foo::B()][offset 0x00000022] Msg." | ||
| ) | ||
| $cmp = Compare-Object (Remove-IlverifyOffsets $output) (Remove-IlverifyOffsets $baseline) | ||
| $cmp | Should Not BeNullOrEmpty | ||
| } | ||
|
|
||
| It "handles trailing whitespace differences between output and baseline" { | ||
| $output = @("[IL]: Error [X]: : Foo::A()][offset 0x00000011] Msg. ") | ||
| $baseline = @("[IL]: Error [X]: : Foo::A()][offset 0x000000FF] Msg.") | ||
| $cmp = Compare-Object (Remove-IlverifyOffsets $output) (Remove-IlverifyOffsets $baseline) | ||
| $cmp | Should BeNullOrEmpty | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice!
This definitely sets the bar higher for future powershell code changes in this repo 👍