Skip to content

Commit

Permalink
Add type IL to verify attribute is actually emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
chsienki committed Feb 11, 2022
1 parent 1c26df5 commit 4650f06
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5061,7 +5061,46 @@ public class MyAttribute : Attribute { public MyAttribute(string name) {} }
attribute.VerifyValue(0, TypedConstantKind.Primitive, "one");
Assert.Equal(@"MyAttribute(""one"")", attribute.ToString());

CompileAndVerify(source, expectedOutput: "Hello World");
CompileAndVerify(source, expectedOutput: "Hello World")
.VerifyTypeIL("Program", @"

This comment has been minimized.

Copy link
@jcouv

jcouv Feb 11, 2022

Member

Look at this PR for a more focused way to check presence of attributes: #58507
VerifyTypeIL doesn't get to the point (captures much irrelevant content compared to what you're trying to validate).

.class private auto ansi beforefieldinit Program
extends [netstandard]System.Object
{
.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Methods
.method private hidebysig static
void '<Main>$' (
string[] args
) cil managed
{
.custom instance void MyAttribute::.ctor(string) = (
01 00 03 6f 6e 65 00 00
)
// Method begins at RVA 0x2050
// Code size 11 (0xb)
.maxstack 8
.entrypoint
IL_0000: ldstr ""Hello World""
IL_0005: call void[netstandard]System.Console::WriteLine(string)
IL_000a: ret
} // end of method Program::'<Main>$'
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Method begins at RVA 0x205c
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [netstandard] System.Object::.ctor()
IL_0006: ret
} // end of method Program::.ctor
} // end of class Program
");
}

[Fact]
Expand Down

0 comments on commit 4650f06

Please sign in to comment.