-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Phase 1 analyzer + code fix for parameterless MockFileSystem ctor #6
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Source/Testably.Abstractions.Migration.Analyzers/Common/TestableIoSymbols.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace Testably.Abstractions.Migration.Analyzers.Common; | ||
|
|
||
| /// <summary> | ||
| /// Caches the well-known <c>System.IO.Abstractions.TestingHelpers</c> type symbols for a | ||
| /// <see cref="Compilation" />. Returns <see langword="null" /> when the | ||
| /// <c>System.IO.Abstractions.TestingHelpers</c> assembly is not referenced so the analyzer | ||
| /// can bail out cheaply. | ||
| /// </summary> | ||
| internal sealed class TestableIoSymbols | ||
| { | ||
| public const string TestingHelpersNamespace = "System.IO.Abstractions.TestingHelpers"; | ||
|
|
||
| private TestableIoSymbols( | ||
| INamedTypeSymbol mockFileSystem, | ||
| INamedTypeSymbol mockFileData, | ||
| INamedTypeSymbol mockDriveData, | ||
| INamedTypeSymbol mockFileDataAccessor) | ||
| { | ||
| MockFileSystem = mockFileSystem; | ||
| MockFileData = mockFileData; | ||
| MockDriveData = mockDriveData; | ||
| MockFileDataAccessor = mockFileDataAccessor; | ||
| } | ||
|
|
||
| public INamedTypeSymbol MockFileSystem { get; } | ||
| public INamedTypeSymbol MockFileData { get; } | ||
| public INamedTypeSymbol MockDriveData { get; } | ||
| public INamedTypeSymbol MockFileDataAccessor { get; } | ||
|
|
||
| public static TestableIoSymbols? TryGetFrom(Compilation compilation) | ||
| { | ||
| INamedTypeSymbol? mockFileSystem = | ||
| compilation.GetTypeByMetadataName(TestingHelpersNamespace + ".MockFileSystem"); | ||
| if (mockFileSystem is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| INamedTypeSymbol? mockFileData = | ||
| compilation.GetTypeByMetadataName(TestingHelpersNamespace + ".MockFileData"); | ||
| INamedTypeSymbol? mockDriveData = | ||
| compilation.GetTypeByMetadataName(TestingHelpersNamespace + ".MockDriveData"); | ||
| INamedTypeSymbol? mockFileDataAccessor = | ||
| compilation.GetTypeByMetadataName(TestingHelpersNamespace + ".IMockFileDataAccessor"); | ||
|
|
||
| if (mockFileData is null || mockDriveData is null || mockFileDataAccessor is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return new TestableIoSymbols(mockFileSystem, mockFileData, mockDriveData, mockFileDataAccessor); | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
Source/Testably.Abstractions.Migration.Analyzers/Patterns.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| namespace Testably.Abstractions.Migration.Analyzers; | ||
|
|
||
| /// <summary> | ||
| /// Discriminator values for the <c>pattern</c> property carried by every | ||
| /// <see cref="Rules.SystemIOAbstractionsRule" /> diagnostic. The accompanying code fix | ||
| /// dispatches on this value to pick the appropriate rewrite. | ||
| /// </summary> | ||
| public static class Patterns | ||
| { | ||
| /// <summary> | ||
| /// The key under which the pattern discriminator is stored in | ||
| /// <see cref="Microsoft.CodeAnalysis.Diagnostic.Properties" />. | ||
| /// </summary> | ||
| public const string Key = "pattern"; | ||
|
|
||
| /// <summary>The parameterless <c>new MockFileSystem()</c> constructor.</summary> | ||
| public const string MockFileSystemDefaultConstructor = "MockFileSystem.ctor()"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/UnixPathSmokeTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using System.IO.Abstractions.TestingHelpers; | ||
|
|
||
| namespace Testably.Abstractions.Migration.SystemIOAbstractionsPlayground; | ||
|
|
||
| /// <summary> | ||
| /// Smoke test for the path-semantics divergence risk identified in Phase 1: rooted | ||
| /// Unix-style paths (e.g. <c>/etc/hosts</c>) are accepted by | ||
| /// <see cref="MockFileSystem" /> on Windows but may behave differently under | ||
| /// <see cref="Testably.Abstractions.Testing.MockFileSystem" />. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The class is a runnable executable in the playground. The body deliberately performs | ||
| /// a read after a write so the smoke test surfaces any divergence as a test failure | ||
| /// rather than a silent regression. | ||
| /// </remarks> | ||
| public static class UnixPathSmokeTest | ||
| { | ||
| public const string UnixStylePath = "/etc/hosts"; | ||
| public const string Contents = "127.0.0.1 localhost"; | ||
|
|
||
| public static string RoundTrip() | ||
| { | ||
| MockFileSystem fileSystem = new(); | ||
|
Check warning on line 23 in Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/UnixPathSmokeTest.cs
|
||
| fileSystem.File.WriteAllText(UnixStylePath, Contents); | ||
| return fileSystem.File.ReadAllText(UnixStylePath); | ||
| } | ||
| } | ||
1 change: 0 additions & 1 deletion
1
Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/Usings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.