Skip to content

Commit 5e8f6ab

Browse files
carlosmnnulltoken
authored andcommitted
Sandbox test repositories in TMP
1 parent 3de74b0 commit 5e8f6ab

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

LibGit2Sharp.Tests/ShadowCopyFixture.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
1717
Assembly assembly = type.Assembly;
1818

1919
// Build a new domain which will shadow copy assemblies
20-
string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
20+
string cachePath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
2121
Directory.CreateDirectory(cachePath);
2222

2323
var setup = new AppDomainSetup
@@ -51,11 +51,6 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
5151

5252
// ...but are currently loaded from different locations...
5353
string cachedAssemblyLocation = wrapper.AssemblyLocation;
54-
if (cachedAssemblyLocation.StartsWith("/private"))
55-
{
56-
// On OS X, sometimes you get /private/var/… instead of /var/…, but they map to the same place.
57-
cachedAssemblyLocation = cachedAssemblyLocation.Substring("/private".Length);
58-
}
5954
Assert.NotEqual(sourceAssembly.Location, cachedAssemblyLocation);
6055

6156
// ...that the assembly in the other domain is stored in the shadow copy cache...

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.IO;
23

34
namespace LibGit2Sharp.Tests.TestHelpers
45
{
56
public static class Constants
67
{
7-
public const string TemporaryReposPath = "TestRepos";
8+
public static readonly string TemporaryReposPath = BuildPath();
89
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
910
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
1011
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
@@ -30,5 +31,28 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
3031
{
3132
return null;
3233
}
34+
35+
public static string BuildPath()
36+
{
37+
string tempPath;
38+
39+
var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
40+
41+
if (unixPath != null)
42+
{
43+
// We're running on Mono/*nix. Let's unwrap the path
44+
tempPath = (string)unixPath.InvokeMember("GetCompleteRealPath",
45+
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy |
46+
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
47+
null, unixPath, new object[] { Path.GetTempPath() });
48+
}
49+
else
50+
{
51+
// We're running on .Net/Windows
52+
tempPath = Path.GetTempPath();
53+
}
54+
55+
return Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
56+
}
3357
}
3458
}

0 commit comments

Comments
 (0)