diff --git a/src/Verify/DerivePaths/AttributeReader.cs b/src/Verify/DerivePaths/AttributeReader.cs index f3cc7f8aa9..a31b80d0ae 100644 --- a/src/Verify/DerivePaths/AttributeReader.cs +++ b/src/Verify/DerivePaths/AttributeReader.cs @@ -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; } diff --git a/src/Verify/VirtualizedRunHelper.cs b/src/Verify/VirtualizedRunHelper.cs index 12b78106f4..d9f05a588d 100644 --- a/src/Verify/VirtualizedRunHelper.cs +++ b/src/Verify/VirtualizedRunHelper.cs @@ -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//... // docker testing mounts to /mnt/approot/... @@ -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; @@ -112,4 +117,4 @@ static bool TryRemoveDirFromStartOfPath(ref string path) static bool PathExists(string path) => File.Exists(path) || Directory.Exists(path); -} +} \ No newline at end of file