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

Enable FixAll testing by default for all code fix unit tests #1422

Closed
wants to merge 4 commits into from

Conversation

mavasani
Copy link
Contributor

By default, VerifyFix method now tests both iterative code fix application and iterative FixAll application.
We still have the VerifyFixAll helper method for tests that want to verify single FixAll application.
Fixes #1420

This PR is currently expected to fail until dotnet/roslyn#23492 is merged and we move to newer CodeAnalysis package.

By default, VerifyFix method now tests both iterative code fix application and iterative FixAll application.
We still have the VerifyFixAll helper method for tests that want to verify single FixAll application.
Fixes dotnet#1420
@mavasani mavasani requested a review from a team November 30, 2017 18:52
{
string diagnosticIdToFix = triggerDiagnostic.Id;
var diagnosticsToFix = fixableDiagnostics.Where(d => d.Id == diagnosticIdToFix);
document = ApplyFixAll(document, codeAction, codeFixProvider, codeFixProvider.GetFixAllProvider(), diagnosticIdToFix, diagnosticsToFix);
Copy link
Contributor

Choose a reason for hiding this comment

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

document = ApplyFixAll(document, codeAction, codeFixProvider, codeFixProvider.GetFixAllProvider(), diagnosticIdToFix, diagnosticsToFix); [](start = 20, length = 136)

Location of the call means that we will make it within the while loop. And can repeat it again and again.

If we have an error within a fix all algorithm for a given analyzer that fixes, for example, just a single error not all; this fixer would pass all tests because it allows fixing one by one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, as we discussed, I will modify this to do a single iteration. For tests which are relying on iterative fix/diagnostic/fix output, they can be handled specially (call separate API for verification)

Copy link
Member

Choose a reason for hiding this comment

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

Fix All does not always fix all in a single iteration. For StyleCop Analyzers we fail the test if it fails to fix everything in one iteration, but have a parameter which allows you to change the behavior. Most of the work to implement this was here:

DotNetAnalyzers/StyleCopAnalyzers#1989

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Sam. After discussing with Ivan, we do something similar for the default case. We only run one FixAll iteration and fail it doesn't fix everything. Tests which fail this way can turn off default FixAll validation with an optional flag, and have a separate VerifyFixAll invocation with appropriate fixedSource.

var diagnosticProvider = new FixAllDiagnosticProvider(fixableDiagnostics);
IEnumerable<string> fixableDiagnosticIds = new string[] { diagnosticIdToFix };
var fixAllContext = new FixAllContext(document, codeFixProvider, FixAllScope.Document, codeAction.EquivalenceKey, fixableDiagnosticIds, diagnosticProvider, CancellationToken.None);
var fixTask = fixAllProvider.GetFixAsync(fixAllContext);
Copy link
Contributor

@heejaechang heejaechang Nov 30, 2017

Choose a reason for hiding this comment

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

how this can return null? Async method returning null is a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I added that while debugging the nullref due to dotnet/roslyn#23492. Let me revert.

… for the default case. For tests where new diagnostics produced from fixes need to be iteratively fixed, they can turn off default FixAll verification and invoke VerifyFixAll separately
@mavasani
Copy link
Contributor Author

mavasani commented Aug 8, 2018

This is an old PR, which I am closing in favor of #1773

@mavasani mavasani closed this Aug 8, 2018
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.

Enable FixAll testing by default for all code fix unit tests
4 participants