Skip to content
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

Merged
merged 12 commits into from
Aug 24, 2021

Conversation

davidwengier
Copy link
Member

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 to reader2 or md2 and get weird test failures 😛

@davidwengier davidwengier requested a review from a team as a code owner July 17, 2021 03:25
@davidwengier davidwengier force-pushed the EnCMetadataTestHelper branch from e6c96fc to 8de0b6b Compare July 17, 2021 03:59
@tmat
Copy link
Member

tmat commented Jul 20, 2021

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.

@davidwengier
Copy link
Member Author

Yeah, that could work, we'd just need AddGeneration to take the edits, and there could be a Verify method that takes a Action<GenerationInfo> that has the methods. Will have a play.

@davidwengier
Copy link
Member Author

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.

internal class GenerationInfo
{
private readonly string _description;
private readonly List<MetadataReader> _readers;
Copy link
Member

@tmat tmat Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List _readers;

This is a bit odd - the class is immutable except for the list of readers. I think we should take a snapshot of the readers list.

Copy link
Member Author

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 :)

Copy link
Member

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.

Copy link
Member Author

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 ¯\_(ツ)_/¯

@davidwengier
Copy link
Member Author

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyMemberRefNames

As a follow up - we should be able to resolve fully qualified names of MemberRefs, MethodDefs and TypeDefs.

@RikkiGibson RikkiGibson self-assigned this Aug 11, 2021
Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@davidwengier davidwengier enabled auto-merge (squash) August 24, 2021 00:24
@davidwengier davidwengier merged commit 7b26597 into dotnet:main Aug 24, 2021
@ghost ghost added this to the Next milestone Aug 24, 2021
@davidwengier davidwengier deleted the EnCMetadataTestHelper branch August 24, 2021 01:38
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants