Skip to content

Commit

Permalink
Fix VerifyTests#388: Normalize IL to ensure consistent outcome.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Nov 13, 2022
1 parent 640678b commit 496bae9
Show file tree
Hide file tree
Showing 13 changed files with 3,114 additions and 191 deletions.
128 changes: 69 additions & 59 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,46 +97,28 @@ Result:
01 00 00 00 00
)
// Fields
.field private string 'property'
.field private class [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler PropertyChanged
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = (
01 00 00 00 00 00 00 00
)
.field private string 'property'

// Methods
.method private hidebysig
instance void OnPropertyChanged (
[opt] string propertyName
) cil managed
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.param [1] = nullref
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CallerMemberNameAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x20b8
// Header size: 1
// Code size: 26 (0x1a)
// Code size: 8 (0x8)
.maxstack 8

IL_0000: ldarg.0
IL_0001: ldfld class [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler Target::PropertyChanged
IL_0006: dup
IL_0007: brtrue.s IL_000c

IL_0009: pop
IL_000a: br.s IL_0019

IL_000c: ldarg.0
IL_000d: ldarg.1
IL_000e: newobj instance void [System.ObjectModel]System.ComponentModel.PropertyChangedEventArgs::.ctor(string)
IL_0013: callvirt instance void [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler::Invoke(object, class [System.ObjectModel]System.ComponentModel.PropertyChangedEventArgs)
IL_0018: nop

IL_0019: ret
} // end of method Target::OnPropertyChanged
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Target::.ctor
.method public final hidebysig specialname newslot virtual
instance void add_PropertyChanged (
Expand All @@ -146,7 +128,6 @@ Result:
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x20d4
// Header size: 12
// Code size: 41 (0x29)
.maxstack 3
Expand Down Expand Up @@ -180,6 +161,48 @@ Result:
IL_0028: ret
} // end of method Target::add_PropertyChanged
.method public hidebysig specialname
instance string get_Property () cil managed
{
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: ldfld string Target::'property'
IL_0006: ret
} // end of method Target::get_Property
.method private hidebysig
instance void OnPropertyChanged (
[opt] string propertyName
) cil managed
{
.param [1] = nullref
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CallerMemberNameAttribute::.ctor() = (
01 00 00 00
)
// Header size: 1
// Code size: 26 (0x1a)
.maxstack 8

IL_0000: ldarg.0
IL_0001: ldfld class [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler Target::PropertyChanged
IL_0006: dup
IL_0007: brtrue.s IL_000c

IL_0009: pop
IL_000a: br.s IL_0019

IL_000c: ldarg.0
IL_000d: ldarg.1
IL_000e: newobj instance void [System.ObjectModel]System.ComponentModel.PropertyChangedEventArgs::.ctor(string)
IL_0013: callvirt instance void [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler::Invoke(object, class [System.ObjectModel]System.ComponentModel.PropertyChangedEventArgs)
IL_0018: nop

IL_0019: ret
} // end of method Target::OnPropertyChanged
.method public final hidebysig specialname newslot virtual
instance void remove_PropertyChanged (
class [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler 'value'
Expand All @@ -188,7 +211,6 @@ Result:
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x210c
// Header size: 12
// Code size: 41 (0x29)
.maxstack 3
Expand Down Expand Up @@ -222,25 +244,11 @@ Result:
IL_0028: ret
} // end of method Target::remove_PropertyChanged
.method public hidebysig specialname
instance string get_Property () cil managed
{
// Method begins at RVA 0x2141
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8

IL_0000: ldarg.0
IL_0001: ldfld string Target::'property'
IL_0006: ret
} // end of method Target::get_Property
.method public hidebysig specialname
instance void set_Property (
string 'value'
) cil managed
{
// Method begins at RVA 0x2149
// Header size: 1
// Code size: 21 (0x15)
.maxstack 8
Expand All @@ -256,20 +264,6 @@ Result:
IL_0014: ret
} // end of method Target::set_Property
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x215f
// Header size: 1
// Code size: 8 (0x8)
.maxstack 8

IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Target::.ctor
// Events
.event [System.ObjectModel]System.ComponentModel.PropertyChangedEventHandler PropertyChanged
{
Expand All @@ -287,7 +281,7 @@ Result:

} // end of class Target
```
<sup><a href='/src/Tests/Tests.TypeDefinitionUsage.verified.txt#L1-L203' title='Snippet source file'>snippet source</a> | <a href='#snippet-Tests.TypeDefinitionUsage.verified.txt' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.TypeDefinitionUsage.verified.txt#L1-L197' title='Snippet source file'>snippet source</a> | <a href='#snippet-Tests.TypeDefinitionUsage.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

A string for the type name can also be used:
Expand Down Expand Up @@ -339,7 +333,6 @@ Result:
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CallerMemberNameAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x20b8
// Header size: 1
// Code size: 26 (0x1a)
.maxstack 8
Expand All @@ -361,10 +354,27 @@ Result:
IL_0019: ret
} // end of method Target::OnPropertyChanged
```
<sup><a href='/src/Tests/Tests.MethodNameUsage.verified.txt#L1-L30' title='Snippet source file'>snippet source</a> | <a href='#snippet-Tests.MethodNameUsage.verified.txt' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.MethodNameUsage.verified.txt#L1-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-Tests.MethodNameUsage.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Settings

Starting with version 4.0 the generated IL is normalized by default, i.e. types and members are sorted by name, and RVA adress comments are stripped, to avoid failed tests only because the binary layout has changed.

To get backward compatible behavior, use the `DontNormalizeIL` setting:

<!-- snippet: BackwardCompatibility -->
<a id='snippet-backwardcompatibility'></a>
```cs
[Test]
public Task BackwardCompatibility()
{
using var file = new PEFile(assemblyPath);
return Verify(new TypeToDisassemble(file, "Target")).DontNormalizeIL();
}
```
<sup><a href='/src/Tests/Tests.cs#L96-L103' title='Snippet source file'>snippet source</a> | <a href='#snippet-backwardcompatibility' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Icon

Expand Down
Loading

0 comments on commit 496bae9

Please sign in to comment.