Skip to content

Commit b5223d5

Browse files
author
J Wyman
committed
Enable custom unit test location with standard location fallback
1 parent 16aaf6c commit b5223d5

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34

45
namespace LibGit2Sharp.Tests.TestHelpers
@@ -34,7 +35,7 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
3435

3536
public static string BuildPath()
3637
{
37-
string tempPath;
38+
string tempPath = null;
3839

3940
var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
4041

@@ -48,11 +49,24 @@ public static string BuildPath()
4849
}
4950
else
5051
{
52+
const string LibGit2TestPath = "LibGit2TestPath";
5153
// We're running on .Net/Windows
52-
tempPath = Path.GetTempPath();
54+
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
55+
{
56+
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
57+
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
58+
}
59+
60+
if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
61+
{
62+
Trace.TraceInformation("Using default test path value");
63+
tempPath = Path.GetTempPath();
64+
}
5365
}
5466

55-
return Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
67+
string testWorkingDirectory = Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
68+
Trace.TraceInformation("Test working directory set to '{0}'", testWorkingDirectory);
69+
return testWorkingDirectory;
5670
}
5771
}
5872
}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ More thorough information available in the [wiki][wiki].
5757

5858
[wiki]: https://github.com/libgit2/libgit2sharp/wiki
5959

60+
## Optimizing unit testing
61+
LibGit2Sharp strives to have comprehensive and robust unit test suite to insure the quality of the software and to assist new contributors and users who can use the tests as sample to jump start development. There are over one-thousand unit-tests for LibGit2Sharp, this number will only grow as functionality is added.
62+
63+
You can do a few things to optimize running unit-tests on Windows:
64+
65+
1. Set the `LibGit2TestPath` environment variable to a path in your development environment.
66+
* If the unit-test framework cannot find the specified folder at runtime, it will fall back to the default location.
67+
2. Configure your anti-virus software to ignore the `LibGit2TestPath` path.
68+
3. Install a RAM disk like [IMDisk](http://www.ltr-data.se/opencode.html/#ImDisk) and set `LibGit2TestPath` to use it.
69+
* Use `imdisk.exe -a -s 256M -m X: -p "/fs:fat /q /v:ramdisk /y"` to create a RAM disk. This command requires elevated privileges and can be placed into a scheduled task or run manually before you begin unit-testing.
70+
6071
## Authors
6172

6273
- **Code:** The LibGit2Sharp [contributors][committers]

0 commit comments

Comments
 (0)