|
5 | 5 |
|
6 | 6 | namespace StyleCop.Analyzers.Test.DocumentationRules
|
7 | 7 | {
|
| 8 | + using System.IO; |
8 | 9 | using System.Threading;
|
9 | 10 | using System.Threading.Tasks;
|
10 | 11 | using Microsoft.CodeAnalysis.Testing;
|
@@ -487,6 +488,59 @@ public class Class2
|
487 | 488 | await VerifyCSharpDiagnosticAsync("Class1.cs", testCode, testSettings: null, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
|
488 | 489 | }
|
489 | 490 |
|
| 491 | + [Fact] |
| 492 | + [WorkItem(1693, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1693")] |
| 493 | + [WorkItem(1665, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1665")] |
| 494 | + public async Task VerifyWithLinkedFileAsync() |
| 495 | + { |
| 496 | + var dirName = "0"; |
| 497 | + var testCode = "public class [|Type1|] { }"; |
| 498 | + |
| 499 | + await new StyleCopCodeFixVerifier<SA1649FileNameMustMatchTypeName, SA1649CodeFixProvider>.CSharpTest() |
| 500 | + { |
| 501 | + TestState = |
| 502 | + { |
| 503 | + Sources = |
| 504 | + { |
| 505 | + (BuildPath(dirName, "TestFile.cs"), testCode), |
| 506 | + }, |
| 507 | + AdditionalProjects = |
| 508 | + { |
| 509 | + ["Project2"] = |
| 510 | + { |
| 511 | + Sources = |
| 512 | + { |
| 513 | + (BuildPath(dirName, "TestFile.cs"), testCode), |
| 514 | + }, |
| 515 | + }, |
| 516 | + }, |
| 517 | + }, |
| 518 | + FixedState = |
| 519 | + { |
| 520 | + Sources = |
| 521 | + { |
| 522 | + (BuildPath(dirName, "Type1.cs"), testCode), |
| 523 | + }, |
| 524 | + AdditionalProjects = |
| 525 | + { |
| 526 | + ["Project2"] = |
| 527 | + { |
| 528 | + Sources = |
| 529 | + { |
| 530 | + (BuildPath(dirName, "Type1.cs"), testCode), |
| 531 | + }, |
| 532 | + }, |
| 533 | + }, |
| 534 | + }, |
| 535 | + |
| 536 | + // Fails without this. Hard to be sure why this is needed, but one guess could be |
| 537 | + // that the test framework does not respect the fact that both projects point to |
| 538 | + // the same file, and only inserts '#pragma warning disable' in the primary project's file. |
| 539 | + // Then we would still get a diagnostic in the additional project. |
| 540 | + TestBehaviors = TestBehaviors.SkipSuppressionCheck, |
| 541 | + }.RunAsync().ConfigureAwait(false); |
| 542 | + } |
| 543 | + |
490 | 544 | protected static string GetTypeDeclaration(string typeKind, string typeName, int? diagnosticKey = null)
|
491 | 545 | {
|
492 | 546 | if (diagnosticKey is not null)
|
@@ -550,5 +604,14 @@ protected static Task VerifyCSharpFixAsync(string oldFileName, string source, st
|
550 | 604 | test.ExpectedDiagnostics.AddRange(expected);
|
551 | 605 | return test.RunAsync(cancellationToken);
|
552 | 606 | }
|
| 607 | + |
| 608 | + // NOTE: Added to simplify the tests. After the fix has executed, |
| 609 | + // the file paths will contain backslashes when running tests on Windows. |
| 610 | + // Not really needed when setting up the test state, but handy in the fixed state. |
| 611 | + // Might make tests pass on Linux if anyone is developing there. |
| 612 | + private static string BuildPath(string part1, string part2) |
| 613 | + { |
| 614 | + return Path.Combine(part1, part2); |
| 615 | + } |
553 | 616 | }
|
554 | 617 | }
|
0 commit comments