Skip to content

Commit 5af6ae4

Browse files
committed
tests: allow override of resources directory
We attempt to determine the test resource directory based on the path of the currently running assembly. If this fails, or if the user is running in a nonstandard environment (perhaps not building out of source) then provide users a mechanism to explicitly specify the path to the resources.
1 parent 3bf4ffb commit 5af6ae4

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,32 @@ private static void SetUpTestEnvironment()
5959
{
6060
IsFileSystemCaseSensitive = IsFileSystemCaseSensitiveInternal();
6161

62-
string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).GetTypeInfo().Assembly.CodeBase).LocalPath).FullName;
62+
var resourcesPath = Environment.GetEnvironmentVariable("LIBGIT2SHARP_RESOURCES");
6363

64-
const string sourceRelativePath = @"../../../../LibGit2Sharp.Tests/Resources";
65-
ResourcesDirectory = new DirectoryInfo(Path.Combine(initialAssemblyParentFolder, sourceRelativePath));
64+
if (resourcesPath == null)
65+
{
66+
string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).GetTypeInfo().Assembly.CodeBase).LocalPath).FullName;
67+
const string sourceRelativePath = @"../../../../LibGit2Sharp.Tests/Resources";
68+
69+
resourcesPath = Path.Combine(initialAssemblyParentFolder, sourceRelativePath);
70+
}
71+
72+
ResourcesDirectory = new DirectoryInfo(resourcesPath);
6673

6774
// Setup standard paths to our test repositories
68-
BareTestRepoPath = Path.Combine(sourceRelativePath, "testrepo.git");
69-
StandardTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "testrepo_wd");
75+
BareTestRepoPath = Path.Combine(ResourcesDirectory.FullName, "testrepo.git");
76+
StandardTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "testrepo_wd");
7077
StandardTestRepoPath = Path.Combine(StandardTestRepoWorkingDirPath, "dot_git");
71-
ShallowTestRepoPath = Path.Combine(sourceRelativePath, "shallow.git");
72-
MergedTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "mergedrepo_wd");
73-
MergeRenamesTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "mergerenames_wd");
74-
MergeTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "merge_testrepo_wd");
75-
RevertTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "revert_testrepo_wd");
76-
SubmoduleTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_wd");
77-
SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_target_wd");
78-
AssumeUnchangedRepoWorkingDirPath = Path.Combine(sourceRelativePath, "assume_unchanged_wd");
79-
SubmoduleSmallTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_small_wd");
80-
PackBuilderTestRepoPath = Path.Combine(sourceRelativePath, "packbuilder_testrepo_wd");
78+
ShallowTestRepoPath = Path.Combine(ResourcesDirectory.FullName, "shallow.git");
79+
MergedTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "mergedrepo_wd");
80+
MergeRenamesTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "mergerenames_wd");
81+
MergeTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "merge_testrepo_wd");
82+
RevertTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "revert_testrepo_wd");
83+
SubmoduleTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "submodule_wd");
84+
SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "submodule_target_wd");
85+
AssumeUnchangedRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "assume_unchanged_wd");
86+
SubmoduleSmallTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "submodule_small_wd");
87+
PackBuilderTestRepoPath = Path.Combine(ResourcesDirectory.FullName, "packbuilder_testrepo_wd");
8188

8289
CleanupTestReposOlderThan(TimeSpan.FromMinutes(15));
8390
}

0 commit comments

Comments
 (0)