Skip to content

Commit

Permalink
Path tests for Linux OS
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-martinsmith committed Aug 21, 2024
1 parent a3f5d08 commit 26773a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ run-name: CIBuild_${{ github.event_name }}_${{ github.ref_name }}_${{ github.run

env:
PKG_MAJOR_VERSION: 1.2
PROJECT_NAME: 'DNX.Extensions'
PROJECT_NAME: DNX.Extensions
DOTNET_VERSION: 8.0.x
NUGET_VERSION: 5.x
BUILD_CONFIG: Release
Expand Down
9 changes: 9 additions & 0 deletions tests/DNX.Extensions.Tests/Configuration/EnvironmentConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using DNX.Extensions.Linq;

namespace DNX.Extensions.Tests.Configuration;
public class EnvironmentConfig
{
public static bool IsLinuxStyleFileSystem => Environment.OSVersion.Platform.IsOneOf(PlatformID.Unix, PlatformID.MacOSX);

public static bool IsWindowsStyleFileSystem => Environment.OSVersion.Platform.ToString().StartsWith("Win");
}
6 changes: 3 additions & 3 deletions tests/DNX.Extensions.Tests/IO/DirectoryInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ public static TheoryData<string, string, string> GetRelativePath_Data()
{ Path.Combine(Path.GetTempPath(), "folder1"), Path.Combine(Path.GetTempPath(), "folder2"), Path.Combine("..", "folder1") },
};

if (Environment.OSVersion.Platform.ToString().StartsWith("Win"))
if (Configuration.EnvironmentConfig.IsWindowsStyleFileSystem)
{
data.Add(Path.Combine(Path.GetTempPath(), "folder1"), Path.Combine("D:", "folder2"), Path.Combine(Path.GetTempPath(), "folder1"));
}
else if (Environment.OSVersion.Platform.IsOneOf(PlatformID.Unix, PlatformID.MacOSX))
else if (Configuration.EnvironmentConfig.IsLinuxStyleFileSystem)
{
data.Add(Path.Combine(Path.GetTempPath(), "folder1"), Path.Combine("/etc", "folder2"), Path.Combine(Path.GetTempPath(), "folder1"));
data.Add(Path.Combine(Path.GetTempPath(), "folder1"), Path.Combine("/etc", "folder2"), Path.Combine("..", "..", Path.GetTempPath(), "folder1"));
}

return data;
Expand Down
10 changes: 7 additions & 3 deletions tests/DNX.Extensions.Tests/IO/FileInfoExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private static string DriveRoot1
{
get
{
return Environment.OSVersion.Platform.IsOneOf(PlatformID.Unix, PlatformID.MacOSX)
return Configuration.EnvironmentConfig.IsLinuxStyleFileSystem
? "/root1"
: "C:";
}
Expand All @@ -22,7 +22,7 @@ private static string DriveRoot2
{
get
{
return Environment.OSVersion.Platform.IsOneOf(PlatformID.Unix, PlatformID.MacOSX)
return Configuration.EnvironmentConfig.IsLinuxStyleFileSystem
? "/root2"
: "D:";
}
Expand Down Expand Up @@ -142,7 +142,11 @@ public static TheoryData<string, string, string> GetRelativeFilePath_Data()
{ Path.Combine(DriveRoot1, "Temp", "abcdefg", "dir3", "file1.tf"), Path.Combine(DriveRoot1, "Temp", "abcdefg"), "dir3" },
{ Path.Combine(DriveRoot1, "Temp", "abcdefg", "dir3", "file1.tf"), Path.Combine(DriveRoot1, "Temp", "abcdefg", "dir3"), "" },
{ Path.Combine(DriveRoot1, "Temp", "folder1", "file.txt"), Path.Combine(DriveRoot1, "Temp", "folder2"), Path.Combine("..", "folder1") },
{ Path.Combine(DriveRoot1, "Temp", "folder1", "file.txt"), Path.Combine(DriveRoot2, "folder2"), Path.Combine(DriveRoot1, "Temp", "folder1") },
{ Path.Combine(DriveRoot1, "Temp", "folder1", "file.txt"), Path.Combine(DriveRoot2, "folder2"),
Configuration.EnvironmentConfig.IsLinuxStyleFileSystem
? Path.Combine("..", "..", DriveRoot1, "Temp", "folder1")
: Path.Combine(DriveRoot1, "Temp", "folder1")
},
};
}
}
Expand Down

0 comments on commit 26773a0

Please sign in to comment.