Skip to content

All unit tests fail because of Mono.Unix.UnixPath in BuildPath #1040

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

Merged
merged 1 commit into from
May 23, 2015
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
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void CanTellIfTheBlobContentLooksLikeBinary()

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");
}
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/ShadowCopyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
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);
Expand Down
8 changes: 0 additions & 8 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ private static bool IsFileSystemCaseSensitiveInternal()
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";
Expand Down
31 changes: 24 additions & 7 deletions LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using LibGit2Sharp.Core;

namespace LibGit2Sharp.Tests.TestHelpers
{
Expand Down Expand Up @@ -30,6 +32,15 @@ public static class Constants

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)
{
Expand All @@ -40,19 +51,15 @@ public static string BuildPath()
{
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))
{
Expand All @@ -72,6 +79,16 @@ public static string BuildPath()
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)
{
Expand Down