From 3f6972d7f8920f8fa1c6ae28ab6e24199da40487 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Sat, 4 May 2019 21:15:14 +0200 Subject: [PATCH] (GH-58) Changed path normalizer to handle separators correctly fixes #58 --- .../Services/VersionControlSystems/GitTests.cs | 2 +- Source/Codecov.Tests/Utilities/FileSystemTests.cs | 4 ++-- Source/Codecov/Utilities/FileSystem.cs | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/Codecov.Tests/Services/VersionControlSystems/GitTests.cs b/Source/Codecov.Tests/Services/VersionControlSystems/GitTests.cs index 7fb498c..67f8046 100644 --- a/Source/Codecov.Tests/Services/VersionControlSystems/GitTests.cs +++ b/Source/Codecov.Tests/Services/VersionControlSystems/GitTests.cs @@ -168,7 +168,7 @@ public void RepoRoot_Should_Get_From_Git_If_Options_Are_Not_Set(string optionsDa repoRoot.Should().Be(rootDir); } - [WindowsTheory("Not yet implemented in unix environment"), InlineData(@".\Fake"), InlineData(@"./Fake")] + [Theory, InlineData(@".\Fake"), InlineData(@"./Fake")] public void RepoRoot_Should_Return_Absolute_Path_When_Given_Relative_Path(string repoRootData) { // Given diff --git a/Source/Codecov.Tests/Utilities/FileSystemTests.cs b/Source/Codecov.Tests/Utilities/FileSystemTests.cs index 8950870..a21f2bd 100644 --- a/Source/Codecov.Tests/Utilities/FileSystemTests.cs +++ b/Source/Codecov.Tests/Utilities/FileSystemTests.cs @@ -50,7 +50,7 @@ public void NormalizedPath_Should_Change_Forward_Slashes_To_Backward_Slashes_On_ normalizedPath.Should().Be(@"c:\fake\github"); } - [UnixFact( Skip = "Not yet implemented")] + [UnixFact] public void NormalizedPath_Should_Change_Backward_Slashes_To_Forward_Slashes_On_Unix() { // Given @@ -63,7 +63,7 @@ public void NormalizedPath_Should_Change_Backward_Slashes_To_Forward_Slashes_On_ normalizedPath.Should().Be(@"/home/fake/github"); } - [WindowsFact("Not yet implemented for unix platforms")] + [Fact] public void NormalizedPath_Should_Create_Aboslute_Path_From_Relative_Path() { // Given diff --git a/Source/Codecov/Utilities/FileSystem.cs b/Source/Codecov/Utilities/FileSystem.cs index 5df74d0..9d43e62 100644 --- a/Source/Codecov/Utilities/FileSystem.cs +++ b/Source/Codecov/Utilities/FileSystem.cs @@ -12,9 +12,12 @@ internal static string NormalizedPath(string path) return string.Empty; } - var absolutePath = Path.GetFullPath(path); + // We only need to replace the windows specific seperator, as these do not work on Unix + var absolutePath = Path.GetFullPath(path.Replace('\\', Path.DirectorySeparatorChar)); - return !string.IsNullOrWhiteSpace(absolutePath) ? Path.GetFullPath(new Uri(absolutePath).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) : string.Empty; + return !string.IsNullOrWhiteSpace(absolutePath) + ? Path.GetFullPath(new Uri(absolutePath).LocalPath).TrimEnd('\\', '/') + : string.Empty; } } }