diff options
author | Brandon Ording <bording@gmail.com> | 2015-05-14 19:59:10 +0300 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2015-05-23 14:55:13 +0300 |
commit | 130d7bc263bb2d5bd7479e3b47b486932d480711 (patch) | |
tree | fc89e0cd91be1c628ce8532188785054c25447f9 | |
parent | abdc1c55f045a9e10252c5de5af4ab3e4f9ef9db (diff) |
Refactor unwrapping of temp repository on unix
Fix #1040
-rw-r--r-- | LibGit2Sharp.Tests/BlobFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 3 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/ShadowCopyFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 8 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/TestHelpers/Constants.cs | 31 |
5 files changed, 29 insertions, 17 deletions
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs index 29934f08..4c984bd3 100644 --- a/LibGit2Sharp.Tests/BlobFixture.cs +++ b/LibGit2Sharp.Tests/BlobFixture.cs @@ -222,7 +222,7 @@ namespace LibGit2Sharp.Tests private static void SkipIfNotSupported(string autocrlf) { - InconclusiveIf(() => autocrlf == "true" && IsRunningOnUnix(), "Non-Windows does not support core.autocrlf = true"); + InconclusiveIf(() => autocrlf == "true" && Constants.IsRunningOnUnix, "Non-Windows does not support core.autocrlf = true"); } } } diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 904c427d..f608ab44 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -52,6 +52,9 @@ <Compile Include="..\LibGit2Sharp\Core\Epoch.cs"> <Link>TestHelpers\Epoch.cs</Link> </Compile> + <Compile Include="..\LibGit2Sharp\Core\Platform.cs"> + <Link>TestHelpers\Platform.cs</Link> + </Compile> <Compile Include="BlameFixture.cs" /> <Compile Include="ArchiveTarFixture.cs" /> <Compile Include="CheckoutFixture.cs" /> diff --git a/LibGit2Sharp.Tests/ShadowCopyFixture.cs b/LibGit2Sharp.Tests/ShadowCopyFixture.cs index 5f57a800..f394e987 100644 --- a/LibGit2Sharp.Tests/ShadowCopyFixture.cs +++ b/LibGit2Sharp.Tests/ShadowCopyFixture.cs @@ -57,7 +57,7 @@ namespace LibGit2Sharp.Tests string cachedAssembliesPath = Path.Combine(setup.CachePath, setup.ApplicationName); Assert.True(cachedAssemblyLocation.StartsWith(cachedAssembliesPath)); - if (!IsRunningOnUnix()) + if (!Constants.IsRunningOnUnix) { // ...that this cache doesn't contain the `NativeBinaries` folder string cachedAssemblyParentPath = Path.GetDirectoryName(cachedAssemblyLocation); diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 0ee8a556..01740476 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -106,14 +106,6 @@ namespace LibGit2Sharp.Tests.TestHelpers return !isInsensitive; } - // Should match LibGit2Sharp.Core.NativeMethods.IsRunningOnUnix() - protected static bool IsRunningOnUnix() - { - // see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms - var p = (int)Environment.OSVersion.Platform; - return (p == 4) || (p == 6) || (p == 128); - } - protected void CreateCorruptedDeadBeefHead(string repoPath) { const string deadbeef = "deadbeef"; diff --git a/LibGit2Sharp.Tests/TestHelpers/Constants.cs b/LibGit2Sharp.Tests/TestHelpers/Constants.cs index 5a389136..85f95c0f 100644 --- a/LibGit2Sharp.Tests/TestHelpers/Constants.cs +++ b/LibGit2Sharp.Tests/TestHelpers/Constants.cs @@ -1,6 +1,8 @@ using System; using System.Diagnostics; using System.IO; +using System.Reflection; +using LibGit2Sharp.Core; namespace LibGit2Sharp.Tests.TestHelpers { @@ -30,6 +32,15 @@ namespace LibGit2Sharp.Tests.TestHelpers public const string PrivateRepoUrl = ""; + public static bool IsRunningOnUnix + { + get + { + return Platform.OperatingSystem == OperatingSystemType.MacOSX || + Platform.OperatingSystem == OperatingSystemType.Unix; + } + } + public static Credentials PrivateRepoCredentials(string url, string usernameFromUrl, SupportedCredentialTypes types) { @@ -40,19 +51,15 @@ namespace LibGit2Sharp.Tests.TestHelpers { string tempPath = null; - var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); - - if (unixPath != null) + if (IsRunningOnUnix) { // We're running on Mono/*nix. Let's unwrap the path - tempPath = (string)unixPath.InvokeMember("GetCompleteRealPath", - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy | - System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public, - null, unixPath, new object[] { Path.GetTempPath() }); + tempPath = UnwrapUnixTempPath(); } else { const string LibGit2TestPath = "LibGit2TestPath"; + // We're running on .Net/Windows if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath)) { @@ -72,6 +79,16 @@ namespace LibGit2Sharp.Tests.TestHelpers return testWorkingDirectory; } + private static string UnwrapUnixTempPath() + { + var type = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); + + return (string)type.InvokeMember("GetCompleteRealPath", + BindingFlags.Static | BindingFlags.FlattenHierarchy | + BindingFlags.InvokeMethod | BindingFlags.Public, + null, type, new object[] { Path.GetTempPath() }); + } + // To help with creating secure strings to test with. private static System.Security.SecureString StringToSecureString(string str) { |