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

code fix test fails without showing any "visible" difference in diff output #876

Closed
Youssef1313 opened this issue Jun 28, 2021 · 4 comments · Fixed by #878
Closed

code fix test fails without showing any "visible" difference in diff output #876

Youssef1313 opened this issue Jun 28, 2021 · 4 comments · Fixed by #878
Labels

Comments

@Youssef1313
Copy link
Member

See build here (PR: Youssef1313/YAnalyzers#38).

It passes on Windows, but not Linux or macOS, which makes me feel like there is a line ending issue.

  Failed TestAddUsing [329 ms]
  Error Message:
   Assert.Fail failed. Context: Iterative code fix application
content of '/0/Test0.cs' did not match. Diff shown with expected as baseline:
 
 using System.Collections.Generic;
 using System.Linq;
 
 class C
 {
     public void M(string[] s)
     {
         List<string> x = s.ToList();
     }
 }
 

  Stack Trace:
     at Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier.Fail(String message) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Testing.Verifiers.MSTest/MSTestVerifier.cs:line 78
   at Microsoft.CodeAnalysis.Testing.IVerifierExtensions.EqualOrDiff(IVerifier verifier, String expected, String actual, String message) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/Extensions/IVerifierExtensions.cs:line 56
   at Microsoft.CodeAnalysis.Testing.CodeFixTest`1.VerifyFixAsync(String language, ImmutableArray`1 analyzers, ImmutableArray`1 codeFixProviders, SolutionState oldState, SolutionState newState, Int32 numberOfIterations, Func`10 getFixedProject, IVerifier verifier, CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs:line 415
   at Microsoft.CodeAnalysis.Testing.CodeFixTest`1.VerifyFixAsync(SolutionState testState, SolutionState fixedState, SolutionState batchFixedState, IVerifier verifier, CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs:line 372
   at Microsoft.CodeAnalysis.Testing.CodeFixTest`1.RunImplAsync(CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs:line 248
   at Microsoft.CodeAnalysis.Testing.AnalyzerTest`1.RunAsync(CancellationToken cancellationToken) in /_/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs:line 180
   at YAnalyzers.Test.CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult[] expected, String fixedSource) in /home/runner/work/YAnalyzers/YAnalyzers/src/UnitTests/Verifiers/CSharpCodeFixVerifier`2.cs:line 58
   at YAnalyzers.Test.CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult expected, String fixedSource) in /home/runner/work/YAnalyzers/YAnalyzers/src/UnitTests/Verifiers/CSharpCodeFixVerifier`2.cs:line 46
   at YAnalyzers.Test.UseImplicitOrExplicitTypeAnalyzerTests.TestAddUsing() in /home/runner/work/YAnalyzers/YAnalyzers/src/UnitTests/UseImplicitOrExplicitTypeAnalyzerTests.cs:line 482
   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

@sharwell Can you help here? Thanks!

@sharwell
Copy link
Member

sharwell commented Jun 28, 2021

Yes, this is a line ending issue. For dotnet/roslyn-sdk, we really just need to update EqualOrDiff to have special rendering for lines that differ by line ending, but I'm not sure what the best way to implement this is. Questions:

  • If all lines differ by line ending, should we show a diff with all lines changed or just a separate line saying the EOL changed?
  • If one (or both) files have mixed lines endings and only a subset of lines changed, should we show just those lines as changed?
  • How should we render an EOL difference?

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jun 28, 2021

I think in the case of line ending difference, it's easiest to print the expected and the actual results as a single line containing \r\n or \ns.

I can't think of a good way to render the EOL differences as a diff.

In case there are other changes than only line endings, I'd prefer the current behavior (showing a diff), i.e, only show the full expected and full actual strings if there is only EOL differences. What do you think?

@sharwell
Copy link
Member

Beyond Compare renders CRLF as ¤ and LF as . I've also seen cases where CR is rendered as <CR> and LF is rendered as <LF> (with both showing as <CR><LF>). Either of these approaches would be visible for the mixed line endings case, but I'm guessing the noise would only be desired if the only changes present are EOL changes.

@Youssef1313
Copy link
Member Author

Thanks for the very quick fix @sharwell!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants