Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Apr 4, 2024
1 parent d3f6ab3 commit ac56542
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/StaticSettingsTests/VirtualizedRunHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ class TestEnv(Func<string, bool> exists, string currentDirectory, char directory
{
public string CurrentDirectory { get; } = currentDirectory;
public char DirectorySeparatorChar { get; } = directorySeparatorChar;

public char AltDirectorySeparatorChar
{
get
{
if (DirectorySeparatorChar == '/')
{
return '\\';
}

return '/';
}
}

public bool PathExists(string path) => exists(path);

// Make sure Path.Combine behaves as on Unix, even when executed on Windows
Expand Down
1 change: 1 addition & 0 deletions src/Verify/IEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interface IEnvironment
{
string CurrentDirectory { get; }
char DirectorySeparatorChar { get; }
char AltDirectorySeparatorChar { get; }
bool PathExists(string path);
string CombinePaths(string path1, string path2);
}
1 change: 1 addition & 0 deletions src/Verify/PhysicalEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class PhysicalEnvironment : IEnvironment

public string CurrentDirectory => Environment.CurrentDirectory;
public char DirectorySeparatorChar => Path.DirectorySeparatorChar;
public char AltDirectorySeparatorChar => Path.AltDirectorySeparatorChar;
public bool PathExists(string path) => File.Exists(path) || Directory.Exists(path);
public string CombinePaths(string path1, string path2) => Path.Combine(path1, path2);
}
9 changes: 5 additions & 4 deletions src/Verify/VirtualizedRunHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ static bool TryFindByCrossSectionOfBuildRunPath(
return false;
}

var currentDirRelativeToAppRoot = Env.CurrentDirectory.TrimStart(separators);
var currentDirectory = Env.CurrentDirectory;
var currentDirRelativeToAppRoot = currentDirectory.TrimStart(separators);
//remove the drive info from the code root
var mappedCodeBaseRootRelative = originalCodeBaseRoot.Replace('\\', '/');
while (TryRemoveDirFromStartOfPath(ref currentDirRelativeToAppRoot))
Expand All @@ -167,7 +168,7 @@ static bool TryFindByCrossSectionOfBuildRunPath(
continue;
}

mappedCodeBaseRootAbsolute = Env.CurrentDirectory[..^currentDirRelativeToAppRoot.Length];
mappedCodeBaseRootAbsolute = currentDirectory[..^currentDirRelativeToAppRoot.Length];

// the start of paths to be mapped

Expand Down Expand Up @@ -198,7 +199,7 @@ static string GetBuildTimePathRelative(string? originalCodeBaseRoot, string buil
{
buildTimePathRelative = buildTimePathRelative[originalCodeBaseRoot.Length..];
buildTimePathRelative = buildTimePathRelative.TrimStart(separators);
if (buildTimePathRelative.Trim(separators) == string.Empty)
if (buildTimePathRelative == string.Empty)
{
buildTimePathRelative = buildTimePath;
}
Expand All @@ -215,7 +216,7 @@ static string GetBuildTimePathRelative(string? originalCodeBaseRoot, string buil

static bool AppearsBuiltOnCurrentPlatform(string buildTimePath) =>
buildTimePath.Contains(Env.DirectorySeparatorChar) &&
!buildTimePath.Contains(separators.First(_ => _ != Env.DirectorySeparatorChar));
!buildTimePath.Contains(Env.AltDirectorySeparatorChar);

static bool TryRemoveDirFromStartOfPath(ref string path)
{
Expand Down

0 comments on commit ac56542

Please sign in to comment.