From 04dc707036142002230dfa399edfec6d0d9bcd69 Mon Sep 17 00:00:00 2001 From: Coen van den Munckhof Date: Tue, 22 Oct 2024 21:21:28 +0200 Subject: [PATCH] Fixing find_files #209 --- src/Directory.Build.props | 3 + .../ActionMenu/Context/FileFunctions.cs | 4 +- .../ActionMenu/Context/FileFunctionsTests.cs | 57 +++++++++++++++++++ tests/SystemTests/SystemTests.csproj | 5 ++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/SystemTests/ProjectRepoM.ActionMenu.Core/ActionMenu/Context/FileFunctionsTests.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 41e526bf..0042c48c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,6 +19,9 @@ <_Parameter1>RepoM.ActionMenu.CodeGen + + <_Parameter1>SystemTests + <_Parameter1>Tests diff --git a/src/RepoM.ActionMenu.Core/ActionMenu/Context/FileFunctions.cs b/src/RepoM.ActionMenu.Core/ActionMenu/Context/FileFunctions.cs index 2cef4c09..fe20b686 100644 --- a/src/RepoM.ActionMenu.Core/ActionMenu/Context/FileFunctions.cs +++ b/src/RepoM.ActionMenu.Core/ActionMenu/Context/FileFunctions.cs @@ -21,7 +21,7 @@ internal partial class FileFunctions : ScribanModuleWithFunctions private static readonly EnumerationOptions _findFilesOptions = new() { RecurseSubdirectories = true, - AttributesToSkip = FileAttributes.Hidden | FileAttributes.System | FileAttributes.Device | FileAttributes.Directory, + AttributesToSkip = FileAttributes.Hidden | FileAttributes.System | FileAttributes.Device, IgnoreInaccessible = true, MatchType = MatchType.Simple, ReturnSpecialDirectories = false, @@ -47,7 +47,7 @@ public FileFunctions() /// solution_files = file.find_files('C:\Project\', '*.sln'); /// /// - /// As a result, the variable `solution_files` is an enumerable of strings, for example: + /// As a result, the variable `solution_files` is an ennumerable of strings, for example: /// /// /// diff --git a/tests/SystemTests/ProjectRepoM.ActionMenu.Core/ActionMenu/Context/FileFunctionsTests.cs b/tests/SystemTests/ProjectRepoM.ActionMenu.Core/ActionMenu/Context/FileFunctionsTests.cs new file mode 100644 index 00000000..a3ff078d --- /dev/null +++ b/tests/SystemTests/ProjectRepoM.ActionMenu.Core/ActionMenu/Context/FileFunctionsTests.cs @@ -0,0 +1,57 @@ +namespace SystemTests.ProjectRepoM.ActionMenu.Core.ActionMenu.Context; + +using System; +using System.IO; +using System.IO.Abstractions; +using FakeItEasy; +using FluentAssertions; +using RepoM.ActionMenu.Core.ActionMenu.Context; +using RepoM.ActionMenu.Interface.ActionMenuFactory; +using Scriban.Parsing; + +public class FileFunctionsTests +{ + private readonly IFileSystem _fileSystem = new FileSystem(); + private readonly IMenuContext _context; + private readonly SourceSpan _span; + private readonly string _rootPath; + private readonly string _rootPathSubDir; + + public FileFunctionsTests() + { + _context = A.Fake(); + A.CallTo(() => _context.FileSystem).Returns(_fileSystem); + _span = new SourceSpan("fileName", new TextPosition(1, 1, 1), new TextPosition(1, 1, 1)); + _rootPath = Path.Combine(Path.GetTempPath(), $"RepoM_Test_Repositories_{Guid.NewGuid().ToString()}"); + _rootPathSubDir = Path.Combine(_rootPath, "subDir"); + } + + [Before(Test)] + public void Setup() + { + _fileSystem.Directory.CreateDirectory(_rootPath); + using var _ = _fileSystem.File.Create(Path.Combine(_rootPath, "root.sln")); + _fileSystem.Directory.CreateDirectory(_rootPathSubDir); + using var __ = _fileSystem.File.Create(Path.Combine(_rootPathSubDir, "sub.sln")); + } + + [After(Test)] + public void Cleanup() + { + _fileSystem.Directory.Delete(_rootPath, true); + } + + [Test] + public void FindFiles_ShouldReturnRootAndSubDirFile() + { + // arrange + + // act + var result = FileFunctions.FindFilesInner(_context, _span, _rootPath, "*.sln"); + + // assert + result.Should().BeEquivalentTo( + $@"{_rootPath}\root.sln", + $@"{_rootPathSubDir}\sub.sln"); + } +} \ No newline at end of file diff --git a/tests/SystemTests/SystemTests.csproj b/tests/SystemTests/SystemTests.csproj index 0c266e07..3fbfe3d0 100644 --- a/tests/SystemTests/SystemTests.csproj +++ b/tests/SystemTests/SystemTests.csproj @@ -4,6 +4,7 @@ + @@ -26,4 +27,8 @@ + + + +