From 1a774c1c2bf637bc3589b24c78fe58103499b0db Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Sep 2024 13:12:29 +0200 Subject: [PATCH] Replace broken `PlatformFact()` constructs 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 Signed-off-by: Johannes Schindelin --- src/shared/Core.Tests/EnvironmentTests.cs | 22 ++--- .../Core.Tests/GenericHostProviderTests.cs | 4 +- .../Interop/Linux/LinuxFileSystemTests.cs | 12 +-- .../Linux/SecretServiceCollectionTests.cs | 6 +- .../Interop/MacOS/MacOSFileSystemTests.cs | 12 +-- .../Interop/MacOS/MacOSKeychainTests.cs | 6 +- .../Posix/GnuPassCredentialStoreTests.cs | 6 +- .../Interop/Posix/PosixFileSystemTests.cs | 4 +- .../Windows/DpapiCredentialStoreTests.cs | 8 +- .../Windows/WindowsCredentialManagerTests.cs | 26 +++--- .../Interop/Windows/WindowsFileSystemTests.cs | 10 +-- src/shared/Core.Tests/Trace2Tests.cs | 4 +- src/shared/Core.Tests/WslUtilsTests.cs | 4 +- .../AzureReposHostProviderTests.cs | 10 +-- .../TestInfrastructure/PlatformAttributes.cs | 87 +++++++++++-------- 15 files changed, 120 insertions(+), 101 deletions(-) diff --git a/src/shared/Core.Tests/EnvironmentTests.cs b/src/shared/Core.Tests/EnvironmentTests.cs index bd7a8c99b..d9b7cb67c 100644 --- a/src/shared/Core.Tests/EnvironmentTests.cs +++ b/src/shared/Core.Tests/EnvironmentTests.cs @@ -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(); @@ -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"; @@ -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"; @@ -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(); @@ -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"; @@ -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"; @@ -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 pathsToIgnore = new List() @@ -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"; @@ -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"; diff --git a/src/shared/Core.Tests/GenericHostProviderTests.cs b/src/shared/Core.Tests/GenericHostProviderTests.cs index 39ed85cfe..8f9594b06 100644 --- a/src/shared/Core.Tests/GenericHostProviderTests.cs +++ b/src/shared/Core.Tests/GenericHostProviderTests.cs @@ -169,13 +169,13 @@ public async Task GenericHostProvider_CreateCredentialAsync_NonHttpProtocol_Retu basicAuthMock.Verify(x => x.GetCredentialsAsync(It.IsAny(), It.IsAny()), 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); diff --git a/src/shared/Core.Tests/Interop/Linux/LinuxFileSystemTests.cs b/src/shared/Core.Tests/Interop/Linux/LinuxFileSystemTests.cs index 4f283294c..2cd6d3cc1 100644 --- a/src/shared/Core.Tests/Interop/Linux/LinuxFileSystemTests.cs +++ b/src/shared/Core.Tests/Interop/Linux/LinuxFileSystemTests.cs @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/src/shared/Core.Tests/Interop/Linux/SecretServiceCollectionTests.cs b/src/shared/Core.Tests/Interop/Linux/SecretServiceCollectionTests.cs index 1237e2907..8cc6c7272 100644 --- a/src/shared/Core.Tests/Interop/Linux/SecretServiceCollectionTests.cs +++ b/src/shared/Core.Tests/Interop/Linux/SecretServiceCollectionTests.cs @@ -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); @@ -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); @@ -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); diff --git a/src/shared/Core.Tests/Interop/MacOS/MacOSFileSystemTests.cs b/src/shared/Core.Tests/Interop/MacOS/MacOSFileSystemTests.cs index 54916103a..85643f8fd 100644 --- a/src/shared/Core.Tests/Interop/MacOS/MacOSFileSystemTests.cs +++ b/src/shared/Core.Tests/Interop/MacOS/MacOSFileSystemTests.cs @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/src/shared/Core.Tests/Interop/MacOS/MacOSKeychainTests.cs b/src/shared/Core.Tests/Interop/MacOS/MacOSKeychainTests.cs index 8ad1caead..e9c517d88 100644 --- a/src/shared/Core.Tests/Interop/MacOS/MacOSKeychainTests.cs +++ b/src/shared/Core.Tests/Interop/MacOS/MacOSKeychainTests.cs @@ -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); @@ -52,7 +52,7 @@ public void MacOSKeychain_ReadWriteDelete() } } - [PlatformFact(Platforms.MacOS)] + [MacOSFact] public void MacOSKeychain_Get_NotFound_ReturnsNull() { var keychain = new MacOSKeychain(TestNamespace); @@ -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); diff --git a/src/shared/Core.Tests/Interop/Posix/GnuPassCredentialStoreTests.cs b/src/shared/Core.Tests/Interop/Posix/GnuPassCredentialStoreTests.cs index 423868bd7..7ff80f03d 100644 --- a/src/shared/Core.Tests/Interop/Posix/GnuPassCredentialStoreTests.cs +++ b/src/shared/Core.Tests/Interop/Posix/GnuPassCredentialStoreTests.cs @@ -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(); @@ -54,7 +54,7 @@ public void GnuPassCredentialStore_ReadWriteDelete() } } - [PlatformFact(Platforms.Posix)] + [PosixFact] public void GnuPassCredentialStore_Get_NotFound_ReturnsNull() { var fs = new TestFileSystem(); @@ -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(); diff --git a/src/shared/Core.Tests/Interop/Posix/PosixFileSystemTests.cs b/src/shared/Core.Tests/Interop/Posix/PosixFileSystemTests.cs index 56dc3a4e3..607eb2e66 100644 --- a/src/shared/Core.Tests/Interop/Posix/PosixFileSystemTests.cs +++ b/src/shared/Core.Tests/Interop/Posix/PosixFileSystemTests.cs @@ -7,7 +7,7 @@ namespace GitCredentialManager.Tests.Interop.Posix { public class PosixFileSystemTests { - [PlatformFact(Platforms.Posix)] + [PosixFact] public void PosixFileSystem_ResolveSymlinks_FileLinks() { string baseDir = GetTempDirectory(); @@ -19,7 +19,7 @@ public void PosixFileSystem_ResolveSymlinks_FileLinks() Assert.Equal(realPath, actual); } - [PlatformFact(Platforms.Posix)] + [PosixFact] public void PosixFileSystem_ResolveSymlinks_DirectoryLinks() { // diff --git a/src/shared/Core.Tests/Interop/Windows/DpapiCredentialStoreTests.cs b/src/shared/Core.Tests/Interop/Windows/DpapiCredentialStoreTests.cs index 202924f69..bb7026903 100644 --- a/src/shared/Core.Tests/Interop/Windows/DpapiCredentialStoreTests.cs +++ b/src/shared/Core.Tests/Interop/Windows/DpapiCredentialStoreTests.cs @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/src/shared/Core.Tests/Interop/Windows/WindowsCredentialManagerTests.cs b/src/shared/Core.Tests/Interop/Windows/WindowsCredentialManagerTests.cs index b7b5cef62..ba4659ec0 100644 --- a/src/shared/Core.Tests/Interop/Windows/WindowsCredentialManagerTests.cs +++ b/src/shared/Core.Tests/Interop/Windows/WindowsCredentialManagerTests.cs @@ -9,7 +9,7 @@ public class WindowsCredentialManagerTests { private const string TestNamespace = "git-test"; - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_ReadWriteDelete() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -45,7 +45,7 @@ public void WindowsCredentialManager_ReadWriteDelete() } } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_AddOrUpdate_UsernameWithAtCharacter() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -81,7 +81,7 @@ public void WindowsCredentialManager_AddOrUpdate_UsernameWithAtCharacter() } } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_Get_KeyNotFound_ReturnsNull() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -93,7 +93,7 @@ public void WindowsCredentialManager_Get_KeyNotFound_ReturnsNull() Assert.Null(credential); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_Remove_KeyNotFound_ReturnsFalse() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -105,7 +105,7 @@ public void WindowsCredentialManager_Remove_KeyNotFound_ReturnsFalse() Assert.False(result); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_AddOrUpdate_TargetNameAlreadyExists_CreatesWithUserInTargetName() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -155,7 +155,7 @@ public void WindowsCredentialManager_AddOrUpdate_TargetNameAlreadyExists_Creates } } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_AddOrUpdate_TargetNameAlreadyExistsAndUserWithAtCharacter_CreatesWithEscapedUserInTargetName() { var credManager = new WindowsCredentialManager(TestNamespace); @@ -235,7 +235,7 @@ public void WindowsCredentialManager_RemoveUriUserInfo(string input, string expe Assert.Equal(expected, actual); } - [PlatformTheory(Platforms.Windows)] + [WindowsTheory] [InlineData("https://example.com", null, "https://example.com", "alice", true)] [InlineData("https://example.com", "alice", "https://example.com", "alice", true)] [InlineData("https://example.com", null, "https://example.com:443", "alice", true)] @@ -270,7 +270,7 @@ public void WindowsCredentialManager_IsMatch( Assert.Equal(expected, actual); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_IsMatch_NoNamespace_NotMatched() { var win32Cred = new Win32Credential @@ -286,7 +286,7 @@ public void WindowsCredentialManager_IsMatch_NoNamespace_NotMatched() Assert.False(result); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_IsMatch_DifferentNamespace_NotMatched() { var win32Cred = new Win32Credential @@ -302,7 +302,7 @@ public void WindowsCredentialManager_IsMatch_DifferentNamespace_NotMatched() Assert.False(result); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_IsMatch_CaseSensitiveNamespace_NotMatched() { var win32Cred = new Win32Credential @@ -318,7 +318,7 @@ public void WindowsCredentialManager_IsMatch_CaseSensitiveNamespace_NotMatched() Assert.False(result); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WindowsCredentialManager_IsMatch_NoNamespaceInQuery_IsMatched() { var win32Cred = new Win32Credential @@ -334,7 +334,7 @@ public void WindowsCredentialManager_IsMatch_NoNamespaceInQuery_IsMatched() Assert.True(result); } - [PlatformTheory(Platforms.Windows)] + [WindowsTheory] [InlineData("https://example.com", null, "https://example.com")] [InlineData("https://example.com", "bob", "https://bob@example.com")] [InlineData("https://example.com", "bob@id.example.com", "https://bob_id.example.com@example.com")] // @ in user @@ -355,7 +355,7 @@ public void WindowsCredentialManager_CreateTargetName(string service, string acc Assert.Equal(fullExpected, actual); } - [PlatformTheory(Platforms.Windows)] + [WindowsTheory] [InlineData(TestNamespace, "https://example.com", null, $"{TestNamespace}:https://example.com")] [InlineData(null, "https://example.com", null, "https://example.com")] [InlineData("", "https://example.com", null, "https://example.com")] diff --git a/src/shared/Core.Tests/Interop/Windows/WindowsFileSystemTests.cs b/src/shared/Core.Tests/Interop/Windows/WindowsFileSystemTests.cs index a94a76597..be89bc1fc 100644 --- a/src/shared/Core.Tests/Interop/Windows/WindowsFileSystemTests.cs +++ b/src/shared/Core.Tests/Interop/Windows/WindowsFileSystemTests.cs @@ -7,7 +7,7 @@ namespace GitCredentialManager.Tests.Interop.Windows { public class WindowsFileSystemTests { - [PlatformFact(Platforms.Windows)] + [WindowsFact] public static void WindowsFileSystem_IsSamePath_SamePath_ReturnsTrue() { var fs = new WindowsFileSystem(); @@ -18,7 +18,7 @@ public static void WindowsFileSystem_IsSamePath_SamePath_ReturnsTrue() Assert.True(fs.IsSamePath(fileA, fileA)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public static void WindowsFileSystem_IsSamePath_DifferentFile_ReturnsFalse() { var fs = new WindowsFileSystem(); @@ -31,7 +31,7 @@ public static void WindowsFileSystem_IsSamePath_DifferentFile_ReturnsFalse() Assert.False(fs.IsSamePath(fileB, fileA)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public static void WindowsFileSystem_IsSamePath_SameFileDifferentCase_ReturnsTrue() { var fs = new WindowsFileSystem(); @@ -44,7 +44,7 @@ public static void WindowsFileSystem_IsSamePath_SameFileDifferentCase_ReturnsTru Assert.True(fs.IsSamePath(fileA2, fileA1)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public static void WindowsFileSystem_IsSamePath_SameFileDifferentPathNormalization_ReturnsTrue() { var fs = new WindowsFileSystem(); @@ -58,7 +58,7 @@ public static void WindowsFileSystem_IsSamePath_SameFileDifferentPathNormalizati Assert.True(fs.IsSamePath(fileA2, fileA1)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public static void WindowsFileSystem_IsSamePath_SameFileRelativePath_ReturnsTrue() { var fs = new WindowsFileSystem(); diff --git a/src/shared/Core.Tests/Trace2Tests.cs b/src/shared/Core.Tests/Trace2Tests.cs index 60d89ac2f..26df5ab98 100644 --- a/src/shared/Core.Tests/Trace2Tests.cs +++ b/src/shared/Core.Tests/Trace2Tests.cs @@ -4,7 +4,7 @@ namespace GitCredentialManager.Tests; public class Trace2Tests { - [PlatformTheory(Platforms.Posix)] + [PosixTheory] [InlineData("af_unix:foo", "foo")] [InlineData("af_unix:stream:foo-bar", "foo-bar")] [InlineData("af_unix:dgram:foo-bar-baz", "foo-bar-baz")] @@ -16,7 +16,7 @@ public void TryGetPipeName_Posix_Returns_Expected_Value(string input, string exp Assert.Matches(actual, expected); } - [PlatformTheory(Platforms.Windows)] + [WindowsTheory] [InlineData("\\\\.\\pipe\\git-foo", "git-foo")] [InlineData("\\\\.\\pipe\\git-foo-bar", "git-foo-bar")] [InlineData("\\\\.\\pipe\\foo\\git-bar", "git-bar")] diff --git a/src/shared/Core.Tests/WslUtilsTests.cs b/src/shared/Core.Tests/WslUtilsTests.cs index 722a8654d..330e42c84 100644 --- a/src/shared/Core.Tests/WslUtilsTests.cs +++ b/src/shared/Core.Tests/WslUtilsTests.cs @@ -92,7 +92,7 @@ public void WslUtils_ConvertToDistroPath_Invalid_ThrowsException(string path) Assert.Throws(() => WslUtils.ConvertToDistroPath(path, out _)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WslUtils_CreateWslProcess() { const string distribution = "ubuntu"; @@ -112,7 +112,7 @@ public void WslUtils_CreateWslProcess() Assert.False(process.StartInfo.UseShellExecute); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public void WslUtils_CreateWslProcess_WorkingDirectory() { const string distribution = "ubuntu"; diff --git a/src/shared/Microsoft.AzureRepos.Tests/AzureReposHostProviderTests.cs b/src/shared/Microsoft.AzureRepos.Tests/AzureReposHostProviderTests.cs index e8da8d79c..e379aaa3b 100644 --- a/src/shared/Microsoft.AzureRepos.Tests/AzureReposHostProviderTests.cs +++ b/src/shared/Microsoft.AzureRepos.Tests/AzureReposHostProviderTests.cs @@ -705,7 +705,7 @@ public async Task AzureReposHostProvider_UnconfigureAsync_UseHttpPathSet_Removes Assert.Empty(context.Git.Configuration.Global); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttpPathSetAndManagerHelper_DoesNotRemoveEntry() { var context = new TestCommandContext(); @@ -721,7 +721,7 @@ public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttp Assert.Equal("true", actualValues[0]); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttpPathSetAndManagerCoreHelper_DoesNotRemoveEntry() { var context = new TestCommandContext(); @@ -737,7 +737,7 @@ public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttp Assert.Equal("true", actualValues[0]); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttpPathSetNoManagerCoreHelper_RemovesEntry() { var context = new TestCommandContext(); @@ -750,7 +750,7 @@ public async Task AzureReposHostProvider_UnconfigureAsync_System_Windows_UseHttp Assert.Empty(context.Git.Configuration.System); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public async Task AzureReposHostProvider_UnconfigureAsync_User_Windows_UseHttpPathSetAndManagerHelper_RemovesEntry() { var context = new TestCommandContext(); @@ -764,7 +764,7 @@ public async Task AzureReposHostProvider_UnconfigureAsync_User_Windows_UseHttpPa Assert.False(context.Git.Configuration.Global.TryGetValue(AzDevUseHttpPathKey, out _)); } - [PlatformFact(Platforms.Windows)] + [WindowsFact] public async Task AzureReposHostProvider_UnconfigureAsync_User_Windows_UseHttpPathSetAndManagerCoreHelper_RemovesEntry() { var context = new TestCommandContext(); diff --git a/src/shared/TestInfrastructure/PlatformAttributes.cs b/src/shared/TestInfrastructure/PlatformAttributes.cs index 24217602d..50d9d6c34 100644 --- a/src/shared/TestInfrastructure/PlatformAttributes.cs +++ b/src/shared/TestInfrastructure/PlatformAttributes.cs @@ -1,76 +1,95 @@ -using System; using System.Runtime.InteropServices; using Xunit; namespace GitCredentialManager.Tests { - public class PlatformFactAttribute : FactAttribute + public class WindowsFactAttribute : FactAttribute { - public PlatformFactAttribute(Platforms platforms) + public WindowsFactAttribute() { - if (!XunitHelpers.IsSupportedPlatform(platforms)) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Skip = "Test not supported on this platform."; } } } - public class PlatformTheoryAttribute : TheoryAttribute + public class MacOSFactAttribute : FactAttribute { - public PlatformTheoryAttribute(Platforms platforms) + public MacOSFactAttribute() { - if (!XunitHelpers.IsSupportedPlatform(platforms)) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Skip = "Test not supported on this platform."; } } } - public class SkippablePlatformFactAttribute : SkippableFactAttribute + public class LinuxFactAttribute : FactAttribute { - public SkippablePlatformFactAttribute(Platforms platforms) + public LinuxFactAttribute() { - Xunit.Skip.IfNot( - XunitHelpers.IsSupportedPlatform(platforms), - "Test not supported on this platform." - ); + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Skip = "Test not supported on this platform."; + } } } - public class SkippablePlatformTheoryAttribute : SkippableTheoryAttribute + public class PosixFactAttribute : FactAttribute { - public SkippablePlatformTheoryAttribute(Platforms platforms) + public PosixFactAttribute() { - Xunit.Skip.IfNot( - XunitHelpers.IsSupportedPlatform(platforms), - "Test not supported on this platform." - ); + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && + !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Skip = "Test not supported on this platform."; + } } } - internal static class XunitHelpers + public class WindowsTheoryAttribute : TheoryAttribute { - public static bool IsSupportedPlatform(Platforms platforms) + public WindowsTheoryAttribute() { - if (platforms.HasFlag(Platforms.Windows) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || - platforms.HasFlag(Platforms.MacOS) && RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || - platforms.HasFlag(Platforms.Linux) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return true; + Skip = "Test not supported on this platform."; } + } + } - return false; + public class MacOSTheoryAttribute : TheoryAttribute + { + public MacOSTheoryAttribute() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Skip = "Test not supported on this platform."; + } } } - [Flags] - public enum Platforms + public class LinuxTheoryAttribute : TheoryAttribute { - None = 0, - Windows = 1 << 0, - MacOS = 1 << 2, - Linux = 1 << 3, - Posix = MacOS | Linux, - All = Windows | Posix + public LinuxTheoryAttribute() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Skip = "Test not supported on this platform."; + } + } + } + + public class PosixTheoryAttribute : TheoryAttribute + { + public PosixTheoryAttribute() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && + !RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Skip = "Test not supported on this platform."; + } + } } }