Skip to content

Commit

Permalink
fix excludepath
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 18, 2023
1 parent 1df4338 commit bf2f8ba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions OneWare.sln
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneWare.NetListSvgIntegrati
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneWare.NetListSvgIntegration.UnitTests", "tests\OneWare.NetListSvgIntegration.UnitTests\OneWare.NetListSvgIntegration.UnitTests.csproj", "{89668C99-1F29-453B-828C-D89EBA9EA218}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneWare.Shared.UnitTests", "tests\OneWare.Shared.UnitTests\OneWare.Shared.UnitTests.csproj", "{5C6FFAFA-590C-400D-8F90-89C9880864AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -293,6 +295,10 @@ Global
{89668C99-1F29-453B-828C-D89EBA9EA218}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89668C99-1F29-453B-828C-D89EBA9EA218}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89668C99-1F29-453B-828C-D89EBA9EA218}.Release|Any CPU.Build.0 = Release|Any CPU
{5C6FFAFA-590C-400D-8F90-89C9880864AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C6FFAFA-590C-400D-8F90-89C9880864AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C6FFAFA-590C-400D-8F90-89C9880864AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C6FFAFA-590C-400D-8F90-89C9880864AF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F08B36E8-AB80-42CD-BD47-6B05E96DA390} = {0761690C-7DA0-4554-9F6B-211088412DCD}
Expand Down Expand Up @@ -336,5 +342,6 @@ Global
{4E2FD886-862B-4DE9-A69E-AE82E52979B5} = {BD761CED-3D61-4D9E-A2A1-494584F2ED5F}
{C3A5837C-6679-493A-A6FD-F3440AF57FDE} = {BD761CED-3D61-4D9E-A2A1-494584F2ED5F}
{89668C99-1F29-453B-828C-D89EBA9EA218} = {EB783E04-C3C8-45F8-B810-24798DAE2450}
{5C6FFAFA-590C-400D-8F90-89C9880864AF} = {EB783E04-C3C8-45F8-B810-24798DAE2450}
EndGlobalSection
EndGlobal
6 changes: 5 additions & 1 deletion src/OneWare.Shared/Helpers/ProjectHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO.Enumeration;
using OneWare.Shared.Extensions;
using OneWare.Shared.Models;

namespace OneWare.Shared.Helpers;
Expand Down Expand Up @@ -46,6 +47,9 @@ public static void ImportEntries(string source, IProjectFolder destination)
public static bool MatchWildCards(string path, IEnumerable<string> include, IEnumerable<string>? exclude)
{
return include.Any(includePattern => FileSystemName.MatchesSimpleExpression(includePattern, path))
&& (exclude is null || !exclude.Any(excludePattern => FileSystemName.MatchesSimpleExpression(excludePattern, path)));
&& (exclude is null || (!exclude.Any(excludePattern => FileSystemName.MatchesSimpleExpression(excludePattern, path))
&& !path.ToLinuxPath().Split('/', StringSplitOptions.RemoveEmptyEntries)
.SkipLast(1)
.Any(x => exclude.Any(excludePattern => FileSystemName.MatchesSimpleExpression(excludePattern, x)))));
}
}
19 changes: 19 additions & 0 deletions tests/OneWare.Shared.UnitTests/OneWare.Shared.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\build\props\XUnit.props" />

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>False</IsPackable>
<IsTestProject>True</IsTestProject>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OneWare.Shared\OneWare.Shared.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions tests/OneWare.Shared.UnitTests/ProjectHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OneWare.Shared.Helpers;
using Xunit;

namespace OneWare.Shared.UnitTests;

public class ProjectHelperTests
{
[Fact]
public void MathWildCardTests()
{
var include = new[] {"**"};
var exclude = new[] {".git"};

Assert.False(ProjectHelper.MatchWildCards(".git/FETCH_HEAD", include, exclude));
Assert.True(ProjectHelper.MatchWildCards("test.vhd", include, exclude));
Assert.True(ProjectHelper.MatchWildCards("nice/test.vhd", include, exclude));
}
}

0 comments on commit bf2f8ba

Please sign in to comment.