Skip to content

Commit 2b447a5

Browse files
committed
Resolve temp dir symlink so tests work on macOS
1 parent ff90cf7 commit 2b447a5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,17 @@ public static string GetDirectorySeparatorChar()
416416

417417
return null;
418418
}
419+
420+
#if NET
421+
public static string ResolveDirectoryLinkTarget(string path)
422+
{
423+
var info = new DirectoryInfo(path);
424+
if (info.ResolveLinkTarget(returnFinalTarget: true) is { } linkTarget)
425+
{
426+
return linkTarget.FullName;
427+
}
428+
429+
return info.FullName;
430+
}
431+
#endif
419432
}

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static string GetMessage()
7878
/// Used when we need an out-of-tree base test directory to avoid having implicit build files
7979
/// like Directory.Build.props in scope and negating the optimizations we want to test.
8080
/// </summary>
81-
private static readonly string s_outOfTreeBaseDirectory = Path.Join(Path.GetTempPath(), "dotnetSdkTests");
81+
private static readonly string s_outOfTreeBaseDirectory = Path.Join(PathUtility.ResolveDirectoryLinkTarget(Path.GetTempPath()), "dotnetSdkTests");
8282

8383
private static bool HasCaseInsensitiveFileSystem
8484
{
@@ -1611,7 +1611,6 @@ Hello from {programName}
16111611
""");
16121612

16131613
// Backup the artifacts directory.
1614-
Directory.CreateDirectory(Path.GetDirectoryName(artifactsBackupDir)!);
16151614
Directory.Move(artifactsDir, artifactsBackupDir);
16161615

16171616
// Build using MSBuild.

0 commit comments

Comments
 (0)