From a0eb11522fb8a5b6cdfd385675034cce1d377021 Mon Sep 17 00:00:00 2001 From: Dave Glick Date: Fri, 22 Dec 2023 09:15:02 -0500 Subject: [PATCH] Cleaned up an edge case in AnalyzeCSharp where the full base path is just a slash. Also fixed some edge cases with root pathing in the test file provider. --- Directory.Build.props | 1 + src/core/Statiq.Testing/IO/TestDirectory.cs | 8 ++++++-- src/core/Statiq.Testing/IO/TestFileProvider.cs | 2 +- src/extensions/Statiq.CodeAnalysis/AnalyzeCSharp.cs | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 600689f14..3d207d2be 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -22,6 +22,7 @@ true netcoreapp3.1 true + NU1901;NU1902;NU1903;NU1904;CA1724 diff --git a/src/core/Statiq.Testing/IO/TestDirectory.cs b/src/core/Statiq.Testing/IO/TestDirectory.cs index 998767429..fdd3a9cd3 100644 --- a/src/core/Statiq.Testing/IO/TestDirectory.cs +++ b/src/core/Statiq.Testing/IO/TestDirectory.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Threading.Tasks; using Statiq.Common; @@ -16,14 +17,17 @@ public TestDirectory(IReadOnlyFileSystem fileSystem, TestFileProvider fileProvid { _fileSystem = fileSystem; _fileProvider = fileProvider; - Path = path; + + // Use a slash for an empty path (can't compare to NormalizePath.Empty since this might be absolute + // in the case of a ".." from the globber, and that's always relative, so compare against FullPath) + Path = path.FullPath == string.Empty ? NormalizedPath.Slash : path; } public NormalizedPath Path { get; } NormalizedPath IFileSystemEntry.Path => Path; - public bool Exists => _fileProvider.Directories.Contains(Path); + public bool Exists => Path == NormalizedPath.Slash || _fileProvider.Directories.Contains(Path); public DateTime LastWriteTime { get; set; } diff --git a/src/core/Statiq.Testing/IO/TestFileProvider.cs b/src/core/Statiq.Testing/IO/TestFileProvider.cs index cc7dc5feb..89c58500d 100644 --- a/src/core/Statiq.Testing/IO/TestFileProvider.cs +++ b/src/core/Statiq.Testing/IO/TestFileProvider.cs @@ -71,4 +71,4 @@ public void AddFile(NormalizedPath path, string content = "") IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } -} +} \ No newline at end of file diff --git a/src/extensions/Statiq.CodeAnalysis/AnalyzeCSharp.cs b/src/extensions/Statiq.CodeAnalysis/AnalyzeCSharp.cs index 5fe121ffe..c6c9ef83c 100644 --- a/src/extensions/Statiq.CodeAnalysis/AnalyzeCSharp.cs +++ b/src/extensions/Statiq.CodeAnalysis/AnalyzeCSharp.cs @@ -462,7 +462,8 @@ protected override async Task> ExecuteContextAsync(IExecu .WithReferences(mscorlib) .WithOptions(new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, - xmlReferenceResolver: new XmlFileResolver(context.FileSystem.RootPath.FullPath))); + xmlReferenceResolver: new XmlFileResolver( + context.FileSystem.RootPath.FullPath == NormalizedPath.Slash ? null : context.FileSystem.RootPath.FullPath))); // Add the input source and references List symbols = new List();