Skip to content

Commit

Permalink
fix for unix
Browse files Browse the repository at this point in the history
  • Loading branch information
taori committed Aug 16, 2024
1 parent ad95742 commit e2b4cec
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Amusoft.DotnetNew.Tests/Internals/PathHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

using System.IO;

namespace Amusoft.DotnetNew.Tests.Internals;

internal static class PathHelper
{
public static string AbsoluteTrimPathEnd(string input, int count)
{
for (int i = 0; i < count; i++)
{
input = Path.GetDirectoryName(input);

Check warning on line 12 in src/Amusoft.DotnetNew.Tests/Internals/PathHelper.cs

View workflow job for this annotation

GitHub Actions / package / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 12 in src/Amusoft.DotnetNew.Tests/Internals/PathHelper.cs

View workflow job for this annotation

GitHub Actions / package / build

Converting null literal or possible null value to non-nullable type.
}

return input;

Check warning on line 15 in src/Amusoft.DotnetNew.Tests/Internals/PathHelper.cs

View workflow job for this annotation

GitHub Actions / package / build

Possible null reference return.

Check warning on line 15 in src/Amusoft.DotnetNew.Tests/Internals/PathHelper.cs

View workflow job for this annotation

GitHub Actions / package / build

Possible null reference return.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Amusoft.DotnetNew.Tests.CLI;
using Amusoft.DotnetNew.Tests.Diagnostics;
using Amusoft.DotnetNew.Tests.Internals;
using Amusoft.DotnetNew.Tests.Rewriters;
using Amusoft.DotnetNew.Tests.Scopes;
using Amusoft.DotnetNew.Tests.Utility;
Expand Down Expand Up @@ -101,7 +103,7 @@ public CrossPlatformPath[] DiscoverTemplates(string searchFolder)
var templateFiles = Directory.EnumerateFiles(folder.OriginalPath, "template.json", SearchOption.AllDirectories);

return templateFiles
.Select(path => Path.Combine(path.Split(Path.DirectorySeparatorChar)[..^2]))
.Select(path => PathHelper.AbsoluteTrimPathEnd(path, 2))
.Select(path => Solution.PathTranslator.GetRelativePath(path))
.ToArray();
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Amusoft.DotnetNew.Tests.UnitTests/Tests/PathHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using Amusoft.DotnetNew.Tests.Internals;
using Amusoft.DotnetNew.Tests.Utility;
using Shouldly;
using Xunit;

namespace Amusoft.DotnetNew.Tests.UnitTests.Tests;

public class PathHelperTests
{
[Theory]
[InlineData("/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/tests/Resources/dotnet-library-repo/.template.config/template.json"
, 2, "/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/tests/Resources/dotnet-library-repo")]
[InlineData("/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/tests/Resources/dotnet-library-repo/.template.config/template.json"
, 3, "/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/tests/Resources")]
public void PathTrimming(string input, int trim, string expected)
{
var o = PathHelper.AbsoluteTrimPathEnd(input, trim);
var r = new CrossPlatformPath(o);
r.ShouldBe(new CrossPlatformPath(expected));
}
}

0 comments on commit e2b4cec

Please sign in to comment.