From 5ea4bd0d858a88437288a58e1c54fad3027a5277 Mon Sep 17 00:00:00 2001 From: Michael Fanning Date: Thu, 15 Oct 2020 08:50:37 -0700 Subject: [PATCH] Fix up test break. Mark doc comment warnings as silent for now. --- src/.editorconfig | 14 +++++++------- src/Sarif/FileSearcherHelper.cs | 13 +++++++++---- src/Sarif/GitHelper.cs | 8 ++++---- src/Test.UnitTests.Sarif/GitHelperTests.cs | 10 ++++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/.editorconfig b/src/.editorconfig index d96d944b1..1ebd304f9 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -196,10 +196,10 @@ dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case -dotnet_diagnostic.CS1570.severity = warning -dotnet_diagnostic.CS1572.severity = warning -dotnet_diagnostic.CS1573.severity = warning -dotnet_diagnostic.CS1574.severity = warning -dotnet_diagnostic.CS1591.severity = warning -dotnet_diagnostic.CS1712.severity = warning -dotnet_diagnostic.CS1734.severity = warning +dotnet_diagnostic.CS1570.severity = silent +dotnet_diagnostic.CS1572.severity = silent +dotnet_diagnostic.CS1573.severity = silent +dotnet_diagnostic.CS1574.severity = silent +dotnet_diagnostic.CS1591.severity = silent +dotnet_diagnostic.CS1712.severity = silent +dotnet_diagnostic.CS1734.severity = silent diff --git a/src/Sarif/FileSearcherHelper.cs b/src/Sarif/FileSearcherHelper.cs index 71d6cac64..8329a9be4 100644 --- a/src/Sarif/FileSearcherHelper.cs +++ b/src/Sarif/FileSearcherHelper.cs @@ -14,9 +14,12 @@ internal static class FileSearcherHelper /// /// Environment variable that we will look for /// Name of the file that we will look for in the environment variable + /// An object that provides access to the file system. /// Path to the file name or empty string. - public static string SearchForFileInEnvironmentVariable(string environmentVariable, string fileName) + public static string SearchForFileInEnvironmentVariable(string environmentVariable, string fileName, IFileSystem fileSystem = null) { + fileSystem ??= new FileSystem(); + string variable = Environment.GetEnvironmentVariable(environmentVariable); if (string.IsNullOrEmpty(variable)) { @@ -26,7 +29,7 @@ public static string SearchForFileInEnvironmentVariable(string environmentVariab string[] paths = variable.Split(';'); foreach (string path in paths) { - string returnedPath = SearchForFileNameInPath(path, fileName); + string returnedPath = SearchForFileNameInPath(path, fileName, fileSystem); if (!string.IsNullOrEmpty(returnedPath)) { return returnedPath; @@ -41,11 +44,13 @@ public static string SearchForFileInEnvironmentVariable(string environmentVariab /// /// Path where it will search. /// Name of the file that it will search + /// An object that provides access to the file system. /// Path to the file name or empty string. - public static string SearchForFileNameInPath(string path, string fileName) + public static string SearchForFileNameInPath(string path, string fileName, IFileSystem fileSystem = null) { + fileSystem ??= new FileSystem(); string filePath = $@"{path}\{fileName}"; - return File.Exists(filePath) ? filePath : null; + return fileSystem.FileExists(filePath) ? filePath : null; } } } diff --git a/src/Sarif/GitHelper.cs b/src/Sarif/GitHelper.cs index 648e5eb0d..99358701e 100644 --- a/src/Sarif/GitHelper.cs +++ b/src/Sarif/GitHelper.cs @@ -43,7 +43,7 @@ public GitHelper(IFileSystem fileSystem = null, ProcessRunner processRunner = nu this.fileSystem = fileSystem ?? new FileSystem(); this.processRunner = processRunner ?? DefaultProcessRunner; - GitExePath = GetGitExePath(); + GitExePath = GetGitExePath(this.fileSystem); } public string GitExePath { get; set; } @@ -73,14 +73,14 @@ public void Checkout(string repoPath, string commitSha) args: $"checkout {commitSha}"); } - internal string GetGitExePath() + internal static string GetGitExePath(IFileSystem fileSystem) { - if (this.fileSystem.FileExists(s_expectedGitExePath)) + if (fileSystem.FileExists(s_expectedGitExePath)) { return s_expectedGitExePath; } - return FileSearcherHelper.SearchForFileInEnvironmentVariable("PATH", "git.exe"); + return FileSearcherHelper.SearchForFileInEnvironmentVariable("PATH", "git.exe", fileSystem); } public string GetCurrentBranch(string repoPath) diff --git a/src/Test.UnitTests.Sarif/GitHelperTests.cs b/src/Test.UnitTests.Sarif/GitHelperTests.cs index d01181a8f..b0f951650 100644 --- a/src/Test.UnitTests.Sarif/GitHelperTests.cs +++ b/src/Test.UnitTests.Sarif/GitHelperTests.cs @@ -127,7 +127,8 @@ public void GetGitExePath_WhenPathExistsInProgramFiles() var gitHelper = new GitHelper(mockFileSystem.Object); - gitHelper.GetGitExePath().Should().NotBeNullOrEmpty(); + gitHelper.GitExePath.Should().NotBeNullOrEmpty(); + GitHelper.GetGitExePath(mockFileSystem.Object).Should().NotBeNullOrEmpty(); } [Fact] @@ -139,7 +140,8 @@ public void GetGitExePath_WhenPathDoesNotExistInProgramFiles() var gitHelper = new GitHelper(mockFileSystem.Object); - gitHelper.GetGitExePath().Should().NotBeNull(); + gitHelper.GitExePath.Should().BeNull(); + GitHelper.GetGitExePath(mockFileSystem.Object).Should().BeNull(); } [Fact] @@ -149,7 +151,7 @@ public void SearchForFileInEnvironmentVariable_WhenVariableDoesNotExist() } [Fact] - public void SearchForFileInEnvironmentVariable_WhenVariableExistsButFileDoesnt() + public void SearchForFileInEnvironmentVariable_WhenVariableExistsButFileDoesNot() { // The error in the ntdll name here is intentional. FileSearcherHelper.SearchForFileInEnvironmentVariable("PATH", "ntdll.dlll").Should().BeNull(); @@ -162,7 +164,7 @@ public void SearchForFileInEnvironmentVariable_WhenVariableAndFileExists() } [Fact] - public void GitExePath_WhenPathDoesntExist_SettingManuallyShouldWork() + public void GitExePath_WhenPathDoesNotExist_SettingManuallyShouldWork() { var mockFileSystem = new Mock();