From c4f2e2843a749860534dd06bda23c2a204d8bb00 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 9 Sep 2024 13:11:18 +1000 Subject: [PATCH] fix path rendering in InnerVerifyChecks --- src/Directory.Build.props | 2 +- src/Verify.sln | 1 + src/Verify/InnerVerifyChecks.cs | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9fe2abd2d..53fd6de43 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget - 26.4.1 + 26.4.2 enable preview 1.0.0 diff --git a/src/Verify.sln b/src/Verify.sln index 2c9d15db4..0b26ef19b 100644 --- a/src/Verify.sln +++ b/src/Verify.sln @@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution testenvironments.json = testenvironments.json Directory.Packages.props = Directory.Packages.props nuget.config = nuget.config + ..\.gitattributes = ..\.gitattributes EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Verify", "Verify\Verify.csproj", "{A017D3FD-7DA5-4DF4-A169-72DE4AF76048}" diff --git a/src/Verify/InnerVerifyChecks.cs b/src/Verify/InnerVerifyChecks.cs index 2ca2a1a03..906113142 100644 --- a/src/Verify/InnerVerifyChecks.cs +++ b/src/Verify/InnerVerifyChecks.cs @@ -29,7 +29,7 @@ static async Task CheckIncorrectlyImportedSnapshots(string solutionDirectory) builder.AppendLine( $""" - Project: file:///{project.Replace('\\', '/')} + Project: {GetPath(project)} Line: {line.TrimStart()} """); } @@ -47,7 +47,7 @@ Found incorrectly imported verified file. This occurs when a test file is copied in the IDE and the IDE incorrectly duplicates the dynamically imported verified file nestings. """); - throw new(builder.ToString()); + throw new CheckException(builder.ToString()); } static async Task CheckEditorConfig(string solutionDirectory) @@ -66,10 +66,10 @@ static async Task CheckEditorConfig(string solutionDirectory) return; } - throw new( + throw new CheckException( $$""" Expected .editorconfig to contain settings for Verify. - Path: {{path}} + Path: {{GetPath(path)}} Recommended settings: # Verify @@ -106,10 +106,10 @@ static async Task CheckGitAttributes(string solutionDirectory) return; } - throw new( + throw new CheckException( $""" Expected .gitattributes to contain settings for Verify. - Path: {path} + Path: {GetPath(path)} Recommended settings: # Verify @@ -120,6 +120,9 @@ static async Task CheckGitAttributes(string solutionDirectory) """); } + static string GetPath(string path) => + $"file:///{path.Replace('\\', '/')}"; + static async Task CheckGitIgnore(string solutionDirectory) { var path = Path.Combine(solutionDirectory, ".gitIgnore"); @@ -142,10 +145,10 @@ static async Task CheckGitIgnore(string solutionDirectory) return; } - throw new( + throw new CheckException( $""" Expected .gitIgnore to contain settings for Verify. - Path: {path} + Path: {GetPath(path)} Recommended settings: # Verify @@ -167,4 +170,15 @@ static Task ReadLines(string path) => #else Task.FromResult(File.ReadAllLines(path)); #endif + class CheckException : Exception + { + public CheckException(string message) : + base(message) + { + } + + public override string ToString() => Message; + + public override string StackTrace => ""; + } } \ No newline at end of file