Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 29, 2023
1 parent a8b1dab commit b30e38a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Verify/DerivePaths/AttributeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static bool TryGetValue(Assembly assembly, string key, [NotNullWhen(true)] out s
{
value = value == null ? null : IoHelpers.GetMappedBuildPath(value, assembly);
}

return value is not null;
}

Expand Down
27 changes: 16 additions & 11 deletions src/Verify/VirtualizedRunHelper.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
class VirtualizedRunHelper
{
// e.g. WSL or docker run (https://github.com/VerifyTests/Verify#unit-testing-inside-virtualized-environment)
readonly bool appearsToBeLocalVirtualizedRun;
readonly string originalCodeBaseRootAbsolute = string.Empty;
readonly string mappedCodeBaseRootAbsolute = string.Empty;
static readonly char[] Separators = { '\\', '/' };
bool appearsToBeLocalVirtualizedRun;
string originalCodeBaseRootAbsolute = string.Empty;
string mappedCodeBaseRootAbsolute = string.Empty;

static readonly char[] separators =
{
'\\',
'/'
};

public VirtualizedRunHelper(Assembly userAssembly)
{
var originalCodeBaseRoot = AttributeReader.TryGetSolutionDirectory(userAssembly, false, out var solutionDir)
? solutionDir
: AttributeReader.GetProjectDirectory(userAssembly);
var appearsToBeBuiltOnDifferentPlatform =
var appearsBuiltOnDifferentPlatform =
!string.IsNullOrEmpty(originalCodeBaseRoot) &&
!originalCodeBaseRoot.Contains(Path.DirectorySeparatorChar) &&
originalCodeBaseRoot.Contains("\\");

if (!appearsToBeBuiltOnDifferentPlatform)
if (!appearsBuiltOnDifferentPlatform)
{
return;
}

string currentDir = Environment.CurrentDirectory;
string currentDirRelativeToAppRoot = currentDir.TrimStart(Separators);
var currentDir = Environment.CurrentDirectory;
var currentDirRelativeToAppRoot = currentDir.TrimStart(separators);

// WSL paths mount to /mnt/<drive>/...
// docker testing mounts to /mnt/approot/...
Expand Down Expand Up @@ -97,9 +102,9 @@ static bool TryRemoveDirFromStartOfPath(ref string path)
return false;
}

path = path.TrimStart(Separators);
path = path.TrimStart(separators);

int nextSeparatorIdx = path.IndexOfAny(Separators);
int nextSeparatorIdx = path.IndexOfAny(separators);
if (nextSeparatorIdx <= 0 || nextSeparatorIdx == path.Length - 1)
{
return false;
Expand All @@ -112,4 +117,4 @@ static bool TryRemoveDirFromStartOfPath(ref string path)

static bool PathExists(string path) =>
File.Exists(path) || Directory.Exists(path);
}
}

0 comments on commit b30e38a

Please sign in to comment.