Create a test help for writing simpler metadata tests#54891
Create a test help for writing simpler metadata tests#54891davidwengier merged 12 commits intodotnet:mainfrom
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.
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.
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.
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"); |
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 toreader2ormd2and get weird test failures 😛