Skip to content

Commit 5bfbc15

Browse files
committed
Fix unit tests (again)
1 parent e9fccc0 commit 5bfbc15

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

NativeInvoke.Tests/Integration/CompileTimeOnlyTests.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,40 @@ public void LocalNuGetBuild_ShouldNotContainNativeInvokeDll()
6161
// This test runs the actual LocalNuGet build process and verifies that
6262
// NativeInvoke.dll is not present in the output folder, proving it's compile-time only
6363

64-
// Try multiple paths to find the Example directory
64+
// Try multiple paths to find the Example directory (cross-platform compatible)
6565
var possiblePaths = new[]
6666
{
67+
// From test directory, go up to repository root and find Example
6768
Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "..", "Example"),
6869
Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "Example"),
70+
// From app domain base directory, go up to repository root and find Example
6971
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", "Example"),
7072
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Example"),
71-
@"X:\Projects\NativeInvoke\Example"
73+
// Try current working directory (common in CI environments)
74+
Path.Combine(Directory.GetCurrentDirectory(), "..", "Example"),
75+
Path.Combine(Directory.GetCurrentDirectory(), "Example"),
76+
// Try repository root + Example (most reliable for CI)
77+
Path.Combine(GetRepositoryRoot(), "Example")
7278
};
7379

7480
string? exampleFullPath = null;
7581
foreach (var path in possiblePaths)
7682
{
7783
var fullPath = Path.GetFullPath(path);
84+
Console.WriteLine($"Checking path: {fullPath}");
7885
if (Directory.Exists(fullPath))
7986
{
8087
exampleFullPath = fullPath;
88+
Console.WriteLine($"✅ Found Example directory at: {exampleFullPath}");
8189
break;
8290
}
8391
}
8492

85-
Assert.That(exampleFullPath, Is.Not.Null, $"Example directory not found. Tried: {string.Join(", ", possiblePaths)}");
93+
Assert.That(exampleFullPath, Is.Not.Null,
94+
$"Example directory not found. Tried: {string.Join(", ", possiblePaths.Select(Path.GetFullPath))}" +
95+
$"\nCurrent directory: {Directory.GetCurrentDirectory()}" +
96+
$"\nTest directory: {TestContext.CurrentContext.TestDirectory}" +
97+
$"\nApp domain base: {AppDomain.CurrentDomain.BaseDirectory}");
8698

8799
// Clean the build output first
88100
var binPath = Path.Combine(exampleFullPath, "bin");
@@ -249,6 +261,26 @@ public interface IComplexKernel
249261
"Should implement all interface methods");
250262
}
251263

264+
private static string GetRepositoryRoot()
265+
{
266+
var currentDir = Directory.GetCurrentDirectory();
267+
268+
// Look for .git directory to find repository root
269+
var dir = new DirectoryInfo(currentDir);
270+
while (dir != null)
271+
{
272+
if (Directory.Exists(Path.Combine(dir.FullName, ".git")))
273+
{
274+
return dir.FullName;
275+
}
276+
dir = dir.Parent;
277+
}
278+
279+
// Fallback: try going up from current directory
280+
var fallbackRoot = Path.GetFullPath(Path.Combine(currentDir, "..", ".."));
281+
return fallbackRoot;
282+
}
283+
252284
private static Assembly CompileAsConsumer(string sourceCode)
253285
{
254286
// Create a compilation that simulates a consumer project

0 commit comments

Comments
 (0)