-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Create a test help for writing simpler metadata tests #54891
Create a test help for writing simpler metadata tests #54891
Conversation
e6c96fc
to
8de0b6b
Compare
Good idea. I'd however try to avoid having a single method (AddGeneration) with gazillion parameters that needs to express everything we may want to test. Instead, perhaps let it take a lambda that has access to the data and calls various Verify helpers on them. |
Yeah, that could work, we'd just need AddGeneration to take the edits, and there could be a Verify method that takes a |
Updated with a lambda. I think I like it better, in particular its nice that I can now click the right thing on a stack trace in a test failure and be taken to the right verify call. |
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/MetadataTest.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/MetadataTest.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/MetadataTest.GenerationInfo.cs
Outdated
Show resolved
Hide resolved
internal class GenerationInfo | ||
{ | ||
private readonly string _description; | ||
private readonly List<MetadataReader> _readers; |
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.
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.
Yeah, I knew this was lazy when I did it, I should have fixed it. This should be a field that holds a reference to the test, and the readers should be publically accessible from there. Sometimes I get lazy with test code. Will fix :)
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.
So another thing - we should use the MetadataAggregator - see the helper that I added in my last PR.
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.
Will have to talk to you about this tomorrow. I tried using the CheckNames
method you added, but it gets a different answer in my test for the type defs in the 3rd generation ¯\_(ツ)_/¯
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/MetadataTest.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/MetadataTest.GenerationInfo.cs
Outdated
Show resolved
Hide resolved
Anything left on this @tmat? Can always follow up with more validations as needed of course. |
{ | ||
g.VerifyTypeDefNames("<Module>", "C"); | ||
g.VerifyMethodDefNames("Main", "F", ".ctor"); | ||
g.VerifyMemberRefNames(/*CompilationRelaxationsAttribute.*/".ctor", /*RuntimeCompatibilityAttribute.*/".ctor", /*Object.*/".ctor", /*DebuggableAttribute*/".ctor", /*DescriptionAttribute*/".ctor"); |
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.
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTestBase.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTest.cs
Outdated
Show resolved
Hide resolved
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.
Thoughts @tmat?
I like that it puts the source code near the expected results, but I wonder if you preferred it the other way?
Mainly it just stops me from doing bad copy-and-pastes where I copy from
diff1
, and missing changing one of the things toreader2
ormd2
and get weird test failures 😛