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
Assemblyassembly=type.Assembly;
1818

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

2323
varsetup=newAppDomainSetup
@@ -51,11 +51,6 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
5151

5252
// ...but are currently loaded from different locations...
5353
stringcachedAssemblyLocation=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
usingSystem;
2+
usingSystem.IO;
23

34
namespaceLibGit2Sharp.Tests.TestHelpers
45
{
56
publicstaticclassConstants
67
{
7-
publicconststringTemporaryReposPath="TestRepos";
8+
publicstaticreadonlystringTemporaryReposPath=BuildPath();
89
publicconststringUnknownSha="deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
910
publicstaticreadonlyIdentityIdentity=newIdentity("A. U. Thor","[email protected]");
1011
publicstaticreadonlySignatureSignature=newSignature(Identity,newDateTimeOffset(2011,06,16,10,58,27,TimeSpan.FromHours(2)));
@@ -30,5 +31,28 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
3031
{
3132
returnnull;
3233
}
34+
35+
publicstaticstringBuildPath()
36+
{
37+
stringtempPath;
38+
39+
varunixPath=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,newobject[]{Path.GetTempPath()});
48+
}
49+
else
50+
{
51+
// We're running on .Net/Windows
52+
tempPath=Path.GetTempPath();
53+
}
54+
55+
returnPath.Combine(tempPath,"LibGit2Sharp-TestRepos");
56+
}
3357
}
3458
}

0 commit comments

Comments
(0)