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

Add diagnostic verification extensibility. #584

Merged
merged 4 commits into from
Aug 13, 2020
Merged

Add diagnostic verification extensibility. #584

merged 4 commits into from
Aug 13, 2020

Conversation

nschuessler
Copy link
Contributor

A small extensibility point to allows verification of generated diagnostics for things not yet supported natively by the test library.
In my case, this is the Properties dictionary of the diagnostic.

This small change would allow me to remove custom testing frameworks from my projects.

@nschuessler nschuessler requested a review from a team as a code owner August 10, 2020 19:53
@dnfadmin
Copy link

dnfadmin commented Aug 10, 2020

CLA assistant check
All CLA requirements met.

@nschuessler
Copy link
Contributor Author

Tagging @sharwell as he has some context for the change.

/// The action compares actual <see cref="Diagnostic"/> and the expected
/// <see cref="DiagnosticResult"/> based on custom test requirements not yet supported by the test framework.
/// </summary>
public Action<ImmutableArray<DiagnosticAnalyzer>, Diagnostic, DiagnosticResult, IVerifier>? DiagnosticVerifier { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the analyzer portion?

Suggested change
public Action<ImmutableArray<DiagnosticAnalyzer>, Diagnostic, DiagnosticResult, IVerifier>? DiagnosticVerifier { get; set; }
public Action<Diagnostic, DiagnosticResult, IVerifier>? DiagnosticVerifier { get; set; }

💭 I'm tempted to go as far as removing the DiagnosticResult portion as well.

Copy link
Contributor Author

@nschuessler nschuessler Aug 11, 2020

Choose a reason for hiding this comment

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

That means implementors can't use the following method for consistency:

     protected string FormatVerifierMessage(ImmutableArray<DiagnosticAnalyzer> analyzers, Diagnostic actual, DiagnosticResult expected, string message)

Is that ok?

Copy link
Contributor Author

@nschuessler nschuessler Aug 11, 2020

Choose a reason for hiding this comment

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

re: DiagnosticResult for expected. I'd like to keep it so that it can be a key to a dictionary containing expected data.

I.e. I would use DiagnosticResult.Location.Span as the key and Dictionary<string, string> for expected properties I'm validating in the Test class.

Copy link
Member

Choose a reason for hiding this comment

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

That means implementors can't use the following method for consistency

The helper wouldn't produce an actionable error message for this case, so I'm not sure how much it helps.

I'd like to keep it so that it can be a key to a dictionary containing expected data.

📝 This is already not supported. DiagnosticResult is a value type which is not equatable.

Let me think about this a bit. If I can't find an "obviously better" option then the one here seems reasonable.

Copy link
Contributor Author

@nschuessler nschuessler Aug 11, 2020

Choose a reason for hiding this comment

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

I do use TextSpan as keys / comparisons in some of my analyzers to determine if I'm matching up the same piece of code.

Choose a reason for hiding this comment

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

@sharwell are we okay to go ahead with Niko's contribution?

Copy link
Member

@sharwell sharwell Aug 13, 2020

Choose a reason for hiding this comment

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

We are

@sharwell sharwell merged commit 6e4a9e4 into dotnet:master Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants