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

Better detect equivalence in our strong name provider #74151

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,56 @@ public void RespectNullTempPath()
Assert.Null(provider.FileSystem.GetSigningTempPath());
}

[Fact]
public void EqualityUsingPath()
{
var tempDir = Temp.CreateDirectory();
var provider1 = new DesktopStrongNameProvider(tempPath: tempDir.Path);
var provider2 = new DesktopStrongNameProvider(tempPath: tempDir.Path);

Assert.Equal(provider1, provider2);
}

[Fact]
public void EqualityUsingKeyFileSearchPaths()
{
var tempDir = Temp.CreateDirectory();
var provider1 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path]);
var provider2 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path]);

Assert.Equal(provider1, provider2);
}

[Fact]
public void InequalityUsingPath()
{
var tempDir = Temp.CreateDirectory();
var provider1 = new DesktopStrongNameProvider(tempPath: tempDir.Path);
var provider2 = new DesktopStrongNameProvider(tempPath: tempDir.Path + "2");

Assert.NotEqual(provider1, provider2);
}

[Fact]
public void InequalityUsingKeyFileSearchPaths()
{
var tempDir = Temp.CreateDirectory();
var provider1 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path]);
var provider2 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path + "2"]);

Assert.NotEqual(provider1, provider2);
}

[Fact]
public void InequalityUsingKeyFileSearchPathsDueToCaseSensitivity()
{
var tempDir = Temp.CreateDirectory();
var provider1 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path]);
var provider2 = new DesktopStrongNameProvider(keyFileSearchPaths: [tempDir.Path.ToUpper()]);

Assert.NotEqual(provider1, provider2);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to add one more test for case sensitivity also counting as unequal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


[Fact]
public void EmitWithCustomTempPath()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public override bool Equals(object? obj)
}

var other = (DesktopStrongNameProvider)obj;
if (FileSystem != other.FileSystem)
if (!FileSystem.Equals(other.FileSystem))
{
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions src/Compilers/Core/Portable/StrongName/StrongNameFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,19 @@ internal virtual bool FileExists(string? fullPath)
}

internal string? GetSigningTempPath() => _signingTempPath;

public override int GetHashCode()
=> _signingTempPath != null ? StringComparer.Ordinal.GetHashCode(_signingTempPath) : 0;

public override bool Equals(object? obj)
=> Equals(obj as StrongNameFileSystem);

private bool Equals(StrongNameFileSystem? other)
{
if (this == other)
return true;

return this.GetType() == other?.GetType() && StringComparer.Ordinal.Equals(_signingTempPath, other?._signingTempPath);
}
}
}