Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions PathLib.UnitTest.Posix/PathLib.UnitTest.Posix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more developer-friendly assertions

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -20,8 +21,8 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PathLib\PathLib.csproj" />
<ItemGroup>
<ProjectReference Include="..\PathLib\PathLib.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion PathLib.UnitTest.Posix/PosixPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using FluentAssertions;
using Xunit.Sdk;

namespace PathLib.UnitTest.Posix;
Expand Down Expand Up @@ -47,7 +48,7 @@ public PosixPathTests(PosixPathTestsFixture fixture)
public void Stat_With_MissingFile_GivesError()
{
var path = new PosixPath(Path.Combine(_fixture.TempFolder, "does_not_exist"));
Assert.False(path.Exists());
path.Exists().Should().BeFalse();

Assert.Throws<FileNotFoundException>(() => path.Stat());
}
Expand Down
1 change: 1 addition & 0 deletions PathLib.UnitTest.Windows/PathLib.UnitTest.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
5 changes: 2 additions & 3 deletions PathLib.UnitTest.Windows/WindowsPathTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using FluentAssertions;
using Xunit;
using PathLib;
using Path = System.IO.Path;
Expand Down Expand Up @@ -88,9 +89,7 @@ public void ExpandUser_WithCustomHomeDirString_ExpandsDir()
var path = new WindowsPath("~/tmp");
var expected = homeDir.Join("tmp");

var actual = path.ExpandUser(homeDir);

Assert.Equal(expected, actual);
path.ExpandUser(homeDir).Should().Be(expected);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure FluentAssertions is available in this project

}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions PathLib.UnitTest/PathLib.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
30 changes: 27 additions & 3 deletions PathLib.UnitTest/PathUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.IO;
using System.Linq;
using FluentAssertions;
using Xunit;

namespace PathLib.UnitTest
Expand Down Expand Up @@ -93,7 +94,31 @@ public void Resolve_WithNoSymlinks_KeepsSamePath()
var actual = expected.Resolve();
Assert.Equal(expected, actual);
}


[Fact]
public void ListDir_with_pattern()
{
// Arrange
var tmpDir = Paths.Create(_fixture.TempFolder);
Assert.True(tmpDir.IsDir());

var file1 = tmpDir / "file1";
Assert.False(file1.IsFile());
file1.Open(FileMode.CreateNew).Dispose();
Assert.True(file1.IsFile());

var dir1 = tmpDir / "dir1";
Assert.False(dir1.IsDir());
dir1.Mkdir();
Assert.True(dir1.IsDir());

// Assertions
tmpDir.ListDir("non-existent").Should().BeEmpty();

tmpDir.ListDir("file*").Select(f => f.FileInfo.FullName).Should()
.BeEquivalentTo(file1.FileInfo.FullName);
}

// sym1 => ../../real2
// sym2 => ../real3
// sym3 => /abs/path/real2/absfile.txt
Expand All @@ -103,6 +128,5 @@ public void Resolve_WithNoSymlinks_KeepsSamePath()
// /real2/real4/anotherfile.txt
// /real2/absfile.txt
// /sym3

}
}
}
2 changes: 1 addition & 1 deletion PathLib/ConcretePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public IEnumerable<TPath> ListDir(string pattern, SearchOption scope)
{
throw new ArgumentException("Glob may only be called on directories.");
}
foreach (var dir in DirectoryInfo.GetDirectories())
foreach (var dir in DirectoryInfo.GetDirectories(pattern, scope))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix

{
yield return PathFactory(dir.FullName);
}
Expand Down
Loading