Skip to content

Commit 7d26a9d

Browse files
committed
Fix resources path computation in test setup
The resources path is set based on the path of the current assembly. The problem is that the assembly directory has a different number of components, depending on whether the Configuration environment variable is set or not. Therefore, the previous code, that depended on the number of subdirs, would fail if there is no value for the Configuration environment variable. The new code looks for the occurrence of a well-known string in the path and bases the path of the test resources off that position. It is still pretty sub-optimal, but I think it's a bit less sub-optimal than it was. Tested in the following ways: - run dotnet test on one test from the command line on Windows; - click on "Run Test" from Visual Studio Code. Fixes libgit2#1629.
1 parent 970328f commit 7d26a9d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ private static void SetUpTestEnvironment()
6464
if (resourcesPath == null)
6565
{
6666
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);
67+
int pos = initialAssemblyParentFolder.IndexOf("LibGit2Sharp.Tests");
68+
resourcesPath = Path.Combine(initialAssemblyParentFolder.Substring(0, pos), "../LibGit2Sharp.Tests/Resources");
7069
}
7170

7271
ResourcesDirectory = new DirectoryInfo(resourcesPath);

0 commit comments

Comments
 (0)