Skip to content

Commit

Permalink
Replace broken PlatformFact() constructs
Browse files Browse the repository at this point in the history
We just upgraded XUnit to a newer version, which unfortunately no longer
works with the `PlatformFact()` constructs of `Xunit.SkippableFact` even
though we updated to the latest version, v1.4.13. It might have
something to do with the fact that that package has not been updated
since July 9th, 2024.

Happily, XUnit has grown equivalent features in the meantime that we can
use instead. So let's use those XUnit-native constructs instead.

Note that we still cannot drop the `SkippableFact` dependency
altogether because we need it in the `MacOSKeychain_ReadWriteDelete`
test case. It is needed to work around a flaky test that is caused by
semi-random broken states of macOS' key-chain, and that can only be
detected while the test case is running (and hence _needs_
`AssertEx.Skip()`, which in turn requires `Xunit.Skip.If()` that is
provided only via the `SkippableFact` package and there is no equivalent
native XUnit functionality).

Helped-by: Matthew Cheetham <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Sep 30, 2024
1 parent 8bfe765 commit 1a774c1
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 101 deletions.
22 changes: 11 additions & 11 deletions src/shared/Core.Tests/EnvironmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EnvironmentTests
private const string PosixPathVar = "/home/john.doe/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
private const string PosixExecName = "foo";

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void WindowsEnvironment_TryLocateExecutable_NotExists_ReturnFalse()
{
var fs = new TestFileSystem();
Expand All @@ -28,7 +28,7 @@ public void WindowsEnvironment_TryLocateExecutable_NotExists_ReturnFalse()
Assert.Null(actualPath);
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void WindowsEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath()
{
string expectedPath = @"C:\Windows\system32\foo.exe";
Expand All @@ -48,7 +48,7 @@ public void WindowsEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath()
Assert.Equal(expectedPath, actualPath);
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void WindowsEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFirstPath()
{
string expectedPath = @"C:\Users\john.doe\bin\foo.exe";
Expand All @@ -70,7 +70,7 @@ public void WindowsEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndF
Assert.Equal(expectedPath, actualPath);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void PosixEnvironment_TryLocateExecutable_NotExists_ReturnFalse()
{
var fs = new TestFileSystem();
Expand All @@ -83,7 +83,7 @@ public void PosixEnvironment_TryLocateExecutable_NotExists_ReturnFalse()
Assert.Null(actualPath);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void PosixEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath()
{
string expectedPath = "/usr/local/bin/foo";
Expand All @@ -103,7 +103,7 @@ public void PosixEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath()
Assert.Equal(expectedPath, actualPath);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void PosixEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFirstPath()
{
string expectedPath = "/home/john.doe/bin/foo";
Expand All @@ -125,7 +125,7 @@ public void PosixEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFir
Assert.Equal(expectedPath, actualPath);
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public void MacOSEnvironment_TryLocateExecutable_Paths_Are_Ignored()
{
List<string> pathsToIgnore = new List<string>()
Expand All @@ -150,8 +150,8 @@ public void MacOSEnvironment_TryLocateExecutable_Paths_Are_Ignored()
Assert.True(actualResult);
Assert.Equal(expectedPath, actualPath);
}
[PlatformFact(Platforms.Posix)]

[PosixFact]
public void PosixEnvironment_SetEnvironmentVariable_Sets_Expected_Value()
{
var variable = "FOO_BAR";
Expand All @@ -166,8 +166,8 @@ public void PosixEnvironment_SetEnvironmentVariable_Sets_Expected_Value()
Assert.Contains(env.Variables, item
=> item.Key.Equals(variable) && item.Value.Equals(value));
}
[PlatformFact(Platforms.Windows)]

[WindowsFact]
public void WindowsEnvironment_SetEnvironmentVariable_Sets_Expected_Value()
{
var variable = "FOO_BAR";
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Core.Tests/GenericHostProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ public async Task GenericHostProvider_CreateCredentialAsync_NonHttpProtocol_Retu
basicAuthMock.Verify(x => x.GetCredentialsAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public async Task GenericHostProvider_CreateCredentialAsync_NonWindows_WiaSupported_ReturnsBasicCredential()
{
await TestCreateCredentialAsync_ReturnsBasicCredential(wiaSupported: true);
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public async Task GenericHostProvider_CreateCredentialAsync_Windows_WiaSupported_ReturnsEmptyCredential()
{
await TestCreateCredentialAsync_ReturnsEmptyCredential(wiaSupported: true);
Expand Down
12 changes: 6 additions & 6 deletions src/shared/Core.Tests/Interop/Linux/LinuxFileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitCredentialManager.Tests.Interop.Linux
{
public class LinuxFileSystemTests
{
[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_SamePath_ReturnsTrue()
{
var fs = new LinuxFileSystem();
Expand All @@ -18,7 +18,7 @@ public static void LinuxFileSystem_IsSamePath_SamePath_ReturnsTrue()
Assert.True(fs.IsSamePath(fileA, fileA));
}

[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_DifferentFile_ReturnsFalse()
{
var fs = new LinuxFileSystem();
Expand All @@ -31,7 +31,7 @@ public static void LinuxFileSystem_IsSamePath_DifferentFile_ReturnsFalse()
Assert.False(fs.IsSamePath(fileB, fileA));
}

[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_SameFileDifferentCase_ReturnsFalse()
{
var fs = new LinuxFileSystem();
Expand All @@ -44,7 +44,7 @@ public static void LinuxFileSystem_IsSamePath_SameFileDifferentCase_ReturnsFalse
Assert.False(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_SameFileDifferentPathNormalization_ReturnsTrue()
{
var fs = new LinuxFileSystem();
Expand All @@ -58,7 +58,7 @@ public static void LinuxFileSystem_IsSamePath_SameFileDifferentPathNormalization
Assert.True(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_SameFileViaSymlink_ReturnsTrue()
{
var fs = new LinuxFileSystem();
Expand All @@ -71,7 +71,7 @@ public static void LinuxFileSystem_IsSamePath_SameFileViaSymlink_ReturnsTrue()
Assert.True(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.Linux)]
[LinuxFact]
public static void LinuxFileSystem_IsSamePath_SameFileRelativePath_ReturnsTrue()
{
var fs = new LinuxFileSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SecretServiceCollectionTests
{
private const string TestNamespace = "git-test";

[PlatformFact(Platforms.Linux, Skip = "Cannot run headless")]
[LinuxFact(Skip = "Cannot run headless")]
public void SecretServiceCollection_ReadWriteDelete()
{
var collection = new SecretServiceCollection(TestNamespace);
Expand Down Expand Up @@ -37,7 +37,7 @@ public void SecretServiceCollection_ReadWriteDelete()
}
}

[PlatformFact(Platforms.Linux, Skip = "Cannot run headless")]
[LinuxFact(Skip = "Cannot run headless")]
public void SecretServiceCollection_Get_NotFound_ReturnsNull()
{
var collection = new SecretServiceCollection(TestNamespace);
Expand All @@ -49,7 +49,7 @@ public void SecretServiceCollection_Get_NotFound_ReturnsNull()
Assert.Null(credential);
}

[PlatformFact(Platforms.Linux, Skip = "Cannot run headless")]
[LinuxFact(Skip = "Cannot run headless")]
public void SecretServiceCollection_Remove_NotFound_ReturnsFalse()
{
var collection = new SecretServiceCollection(TestNamespace);
Expand Down
12 changes: 6 additions & 6 deletions src/shared/Core.Tests/Interop/MacOS/MacOSFileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitCredentialManager.Tests.Interop.MacOS
{
public class MacOSFileSystemTests
{
[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_SamePath_ReturnsTrue()
{
var fs = new MacOSFileSystem();
Expand All @@ -18,7 +18,7 @@ public static void MacOSFileSystem_IsSamePath_SamePath_ReturnsTrue()
Assert.True(fs.IsSamePath(fileA, fileA));
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_DifferentFile_ReturnsFalse()
{
var fs = new MacOSFileSystem();
Expand All @@ -31,7 +31,7 @@ public static void MacOSFileSystem_IsSamePath_DifferentFile_ReturnsFalse()
Assert.False(fs.IsSamePath(fileB, fileA));
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_SameFileDifferentCase_ReturnsTrue()
{
var fs = new MacOSFileSystem();
Expand All @@ -44,7 +44,7 @@ public static void MacOSFileSystem_IsSamePath_SameFileDifferentCase_ReturnsTrue(
Assert.True(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_SameFileDifferentPathNormalization_ReturnsTrue()
{
var fs = new MacOSFileSystem();
Expand All @@ -58,7 +58,7 @@ public static void MacOSFileSystem_IsSamePath_SameFileDifferentPathNormalization
Assert.True(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_SameFileViaSymlink_ReturnsTrue()
{
var fs = new MacOSFileSystem();
Expand All @@ -71,7 +71,7 @@ public static void MacOSFileSystem_IsSamePath_SameFileViaSymlink_ReturnsTrue()
Assert.True(fs.IsSamePath(fileA2, fileA1));
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public static void MacOSFileSystem_IsSamePath_SameFileRelativePath_ReturnsTrue()
{
var fs = new MacOSFileSystem();
Expand Down
6 changes: 3 additions & 3 deletions src/shared/Core.Tests/Interop/MacOS/MacOSKeychainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MacOSKeychainTests
{
private const string TestNamespace = "git-test";

[SkippablePlatformFact(Platforms.MacOS)]
[MacOSFact]
public void MacOSKeychain_ReadWriteDelete()
{
var keychain = new MacOSKeychain(TestNamespace);
Expand Down Expand Up @@ -52,7 +52,7 @@ public void MacOSKeychain_ReadWriteDelete()
}
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public void MacOSKeychain_Get_NotFound_ReturnsNull()
{
var keychain = new MacOSKeychain(TestNamespace);
Expand All @@ -64,7 +64,7 @@ public void MacOSKeychain_Get_NotFound_ReturnsNull()
Assert.Null(credential);
}

[PlatformFact(Platforms.MacOS)]
[MacOSFact]
public void MacOSKeychain_Remove_NotFound_ReturnsFalse()
{
var keychain = new MacOSKeychain(TestNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GnuPassCredentialStoreTests
{
private const string TestNamespace = "git-test";

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void GnuPassCredentialStore_ReadWriteDelete()
{
var fs = new TestFileSystem();
Expand Down Expand Up @@ -54,7 +54,7 @@ public void GnuPassCredentialStore_ReadWriteDelete()
}
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void GnuPassCredentialStore_Get_NotFound_ReturnsNull()
{
var fs = new TestFileSystem();
Expand All @@ -70,7 +70,7 @@ public void GnuPassCredentialStore_Get_NotFound_ReturnsNull()
Assert.Null(credential);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void GnuPassCredentialStore_Remove_NotFound_ReturnsFalse()
{
var fs = new TestFileSystem();
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Core.Tests/Interop/Posix/PosixFileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitCredentialManager.Tests.Interop.Posix
{
public class PosixFileSystemTests
{
[PlatformFact(Platforms.Posix)]
[PosixFact]
public void PosixFileSystem_ResolveSymlinks_FileLinks()
{
string baseDir = GetTempDirectory();
Expand All @@ -19,7 +19,7 @@ public void PosixFileSystem_ResolveSymlinks_FileLinks()
Assert.Equal(realPath, actual);
}

[PlatformFact(Platforms.Posix)]
[PosixFact]
public void PosixFileSystem_ResolveSymlinks_DirectoryLinks()
{
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DpapiCredentialStoreTests
private const string TestStoreRoot = @"C:\dpapi_store";
private const string TestNamespace = "git-test";

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void DpapiCredentialStore_AddOrUpdate_CreatesUTF8ProtectedFile()
{
var fs = new TestFileSystem();
Expand Down Expand Up @@ -49,7 +49,7 @@ public void DpapiCredentialStore_AddOrUpdate_CreatesUTF8ProtectedFile()
Assert.True(string.IsNullOrWhiteSpace(lines[3]));
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void DpapiCredentialStore_Get_KeyNotFound_ReturnsNull()
{
var fs = new TestFileSystem();
Expand All @@ -62,7 +62,7 @@ public void DpapiCredentialStore_Get_KeyNotFound_ReturnsNull()
Assert.Null(credential);
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void DpapiCredentialStore_Get_ReadProtectedFile()
{
var fs = new TestFileSystem();
Expand Down Expand Up @@ -97,7 +97,7 @@ public void DpapiCredentialStore_Get_ReadProtectedFile()
Assert.Equal(userName, credential.Account);
}

[PlatformFact(Platforms.Windows)]
[WindowsFact]
public void DpapiCredentialStore_Remove_KeyNotFound_ReturnsFalse()
{
var fs = new TestFileSystem();
Expand Down
Loading

0 comments on commit 1a774c1

Please sign in to comment.