Skip to content

Commit 645d89e

Browse files
committed
Merge pull request #1040 from libgit2/ntk/issue_1040
All unit tests fail because of Mono.Unix.UnixPath in BuildPath
2 parents abdc1c5 + 130d7bc commit 645d89e

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
222222

223223
private static void SkipIfNotSupported(string autocrlf)
224224
{
225-
InconclusiveIf(() => autocrlf == "true" && IsRunningOnUnix(), "Non-Windows does not support core.autocrlf = true");
225+
InconclusiveIf(() => autocrlf == "true" && Constants.IsRunningOnUnix, "Non-Windows does not support core.autocrlf = true");
226226
}
227227
}
228228
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<Compile Include="..\LibGit2Sharp\Core\Epoch.cs">
5353
<Link>TestHelpers\Epoch.cs</Link>
5454
</Compile>
55+
<Compile Include="..\LibGit2Sharp\Core\Platform.cs">
56+
<Link>TestHelpers\Platform.cs</Link>
57+
</Compile>
5558
<Compile Include="BlameFixture.cs" />
5659
<Compile Include="ArchiveTarFixture.cs" />
5760
<Compile Include="CheckoutFixture.cs" />

LibGit2Sharp.Tests/ShadowCopyFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
5757
string cachedAssembliesPath = Path.Combine(setup.CachePath, setup.ApplicationName);
5858
Assert.True(cachedAssemblyLocation.StartsWith(cachedAssembliesPath));
5959

60-
if (!IsRunningOnUnix())
60+
if (!Constants.IsRunningOnUnix)
6161
{
6262
// ...that this cache doesn't contain the `NativeBinaries` folder
6363
string cachedAssemblyParentPath = Path.GetDirectoryName(cachedAssemblyLocation);

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ private static bool IsFileSystemCaseSensitiveInternal()
106106
return !isInsensitive;
107107
}
108108

109-
// Should match LibGit2Sharp.Core.NativeMethods.IsRunningOnUnix()
110-
protected static bool IsRunningOnUnix()
111-
{
112-
// see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms
113-
var p = (int)Environment.OSVersion.Platform;
114-
return (p == 4) || (p == 6) || (p == 128);
115-
}
116-
117109
protected void CreateCorruptedDeadBeefHead(string repoPath)
118110
{
119111
const string deadbeef = "deadbeef";

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Reflection;
5+
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp.Tests.TestHelpers
68
{
@@ -30,6 +32,15 @@ public static class Constants
3032

3133
public const string PrivateRepoUrl = "";
3234

35+
public static bool IsRunningOnUnix
36+
{
37+
get
38+
{
39+
return Platform.OperatingSystem == OperatingSystemType.MacOSX ||
40+
Platform.OperatingSystem == OperatingSystemType.Unix;
41+
}
42+
}
43+
3344
public static Credentials PrivateRepoCredentials(string url, string usernameFromUrl,
3445
SupportedCredentialTypes types)
3546
{
@@ -40,19 +51,15 @@ public static string BuildPath()
4051
{
4152
string tempPath = null;
4253

43-
var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
44-
45-
if (unixPath != null)
54+
if (IsRunningOnUnix)
4655
{
4756
// We're running on Mono/*nix. Let's unwrap the path
48-
tempPath = (string)unixPath.InvokeMember("GetCompleteRealPath",
49-
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy |
50-
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
51-
null, unixPath, new object[] { Path.GetTempPath() });
57+
tempPath = UnwrapUnixTempPath();
5258
}
5359
else
5460
{
5561
const string LibGit2TestPath = "LibGit2TestPath";
62+
5663
// We're running on .Net/Windows
5764
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
5865
{
@@ -72,6 +79,16 @@ public static string BuildPath()
7279
return testWorkingDirectory;
7380
}
7481

82+
private static string UnwrapUnixTempPath()
83+
{
84+
var type = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
85+
86+
return (string)type.InvokeMember("GetCompleteRealPath",
87+
BindingFlags.Static | BindingFlags.FlattenHierarchy |
88+
BindingFlags.InvokeMethod | BindingFlags.Public,
89+
null, type, new object[] { Path.GetTempPath() });
90+
}
91+
7592
// To help with creating secure strings to test with.
7693
private static System.Security.SecureString StringToSecureString(string str)
7794
{

0 commit comments

Comments
 (0)