From 29fb4097e4f2587f963d05959560db90ee53fcc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 20 Aug 2024 00:05:54 +0200 Subject: [PATCH] build result feedback --- src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs | 2 +- .../CLI/LoggedDotnetCli.cs | 1 + .../Diagnostics/BuildResult.cs | 42 +++++++++++++++++++ .../Diagnostics/CommandResult.cs | 2 +- .../Diagnostics/TextResult.cs | 1 - .../Utility/NewLineIgnoreEncoder.cs | 2 +- ...ser=gitUser_author=authorname.verified.txt | 26 ++++++------ ...ser=gitUser_author=authorname.verified.txt | 26 ++++++------ .../Tests/ScaffoldingTests.cs | 2 +- ...ResultTests.VerifyBuildResult.verified.txt | 12 ++++++ .../Tests/CommandResultTests.cs | 11 +++++ 11 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 src/Amusoft.DotnetNew.Tests/Diagnostics/BuildResult.cs create mode 100644 tests/Amusoft.DotnetNew.Tests.UnitTests/Snapshots/CommandResultTests.VerifyBuildResult.verified.txt diff --git a/src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs b/src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs index a54d64c..29d097a 100644 --- a/src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs +++ b/src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs @@ -76,7 +76,7 @@ async Task IDotnetCli.BuildAsync(string fullPath, string? arguments, Verbosity v { if (await LoggedDotnetCli.RunDotnetCommandAsync(fullArgs, cancellationToken, [])) { - loggingScope.ParentScope?.AddResult(new TextResult($"success: {fullArgs}")); + loggingScope.ParentScope?.AddResult(new BuildResult(fullArgs, loggingScope.ToFullString(PrintKind.Responses))); } else { diff --git a/src/Amusoft.DotnetNew.Tests/CLI/LoggedDotnetCli.cs b/src/Amusoft.DotnetNew.Tests/CLI/LoggedDotnetCli.cs index a7d7ee1..2ee9e32 100644 --- a/src/Amusoft.DotnetNew.Tests/CLI/LoggedDotnetCli.cs +++ b/src/Amusoft.DotnetNew.Tests/CLI/LoggedDotnetCli.cs @@ -22,6 +22,7 @@ internal static class LoggedDotnetCli internal static async Task RunDotnetCommandAsync(string arguments, CancellationToken cancellationToken, int[] acceptAsSuccess) { var runner = new LocalProcessRunner(); + // var runner = new CliWrapRunner(); return await runner.RunAsync(arguments, cancellationToken, acceptAsSuccess).ConfigureAwait(false); } } diff --git a/src/Amusoft.DotnetNew.Tests/Diagnostics/BuildResult.cs b/src/Amusoft.DotnetNew.Tests/Diagnostics/BuildResult.cs new file mode 100644 index 0000000..7f8cd9c --- /dev/null +++ b/src/Amusoft.DotnetNew.Tests/Diagnostics/BuildResult.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; +using Amusoft.DotnetNew.Tests.Interfaces; +using Amusoft.DotnetNew.Tests.Templating; + +namespace Amusoft.DotnetNew.Tests.Diagnostics; + +internal class BuildResult( + string command, + string content +) : ICommandResult +{ + private static readonly Regex Regex = new("-> (?.+?\\.dll)", RegexOptions.Compiled); + + private IEnumerable GetDlls() + { + var replace = content.Replace("/u003E",">"); + var matchCollection = Regex.Matches(replace); + return matchCollection + .Select(d => d.Groups["dll"].Value.Replace("//","/")) + .OrderBy(d => d); + } + + public void Print(StringBuilder stringBuilder) + { + var serializeContent = new + { + Command = command, + Files = GetDlls(), + }; + var serialized = JsonSerializer.Serialize(serializeContent,new JsonSerializerOptions() + { + WriteIndented = true + } + ); + + stringBuilder.Append(TemplatingDefaults.Instance.PrintPattern("BuildResult", serialized)); + } +} \ No newline at end of file diff --git a/src/Amusoft.DotnetNew.Tests/Diagnostics/CommandResult.cs b/src/Amusoft.DotnetNew.Tests/Diagnostics/CommandResult.cs index 677e9b1..e03c706 100644 --- a/src/Amusoft.DotnetNew.Tests/Diagnostics/CommandResult.cs +++ b/src/Amusoft.DotnetNew.Tests/Diagnostics/CommandResult.cs @@ -33,7 +33,7 @@ public void Print(StringBuilder stringBuilder) new JsonSerializerOptions() { WriteIndented = true, - Encoder = NewLineIgnoreEncoder.Instance + // Encoder = NewLineIgnoreEncoder.Instance } ); diff --git a/src/Amusoft.DotnetNew.Tests/Diagnostics/TextResult.cs b/src/Amusoft.DotnetNew.Tests/Diagnostics/TextResult.cs index fb27b68..fa5dad9 100644 --- a/src/Amusoft.DotnetNew.Tests/Diagnostics/TextResult.cs +++ b/src/Amusoft.DotnetNew.Tests/Diagnostics/TextResult.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Text; using Amusoft.DotnetNew.Tests.Interfaces; using Amusoft.DotnetNew.Tests.Templating; diff --git a/src/Amusoft.DotnetNew.Tests/Utility/NewLineIgnoreEncoder.cs b/src/Amusoft.DotnetNew.Tests/Utility/NewLineIgnoreEncoder.cs index b22b616..ffba94b 100644 --- a/src/Amusoft.DotnetNew.Tests/Utility/NewLineIgnoreEncoder.cs +++ b/src/Amusoft.DotnetNew.Tests/Utility/NewLineIgnoreEncoder.cs @@ -19,7 +19,7 @@ public override unsafe bool TryEncodeUnicodeScalar(int unicodeScalar, char* buff return Default.TryEncodeUnicodeScalar(unicodeScalar, buffer, bufferLength, out numberOfCharactersWritten); } - private static readonly HashSet Ignores = ['\r', '\n', '\\']; + private static readonly HashSet Ignores = ['\r', '\n', '\\', '<', '>']; public override bool WillEncode(int unicodeScalar) { diff --git a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project1_gitUser=gitUser_author=authorname.verified.txt b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project1_gitUser=gitUser_author=authorname.verified.txt index b05989d..569ee0e 100644 --- a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project1_gitUser=gitUser_author=authorname.verified.txt +++ b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project1_gitUser=gitUser_author=authorname.verified.txt @@ -6,29 +6,31 @@ Install for {ProjectDir:dotnet-library-repo} succeded ---Result--- -Created temp directory at {Scaffold} +Install for {ProjectDir:dotnet-template} succeded ----Command--- +---Result--- -dotnet new dotnet-library-repo -o "{Scaffold}" -n "Project1" --GitProjectName "Project1" --NugetPackageId "Project1" --ProductName "Project1" --GitUser "gitUser" --Author "authorname" +Created temp directory at {Scaffold} ---Result--- -{ - "ExitCode": 0, - "Output": "The template /u0022nuget library repository/u0022 was created successfully.", - "Errors": "", - "Success": true, - "Runtime": "00:00:00" -} +success: new dotnet-library-repo -o "{Scaffold}" -n "Project1" --GitProjectName "Project1" --NugetPackageId "Project1" --ProductName "Project1" --GitUser "gitUser" --Author "authorname" ---Result--- success: restore "{Scaffold}/src/Project1.sln" -v m --ignore-failed-sources ----Result--- +---BuildResult--- -success: build {Scaffold}/src/Project1.sln --no-restore -v m +{ + "Command": "build {Scaffold}/src/Project1.sln --no-restore -v m", + "Files": [ + "{Scaffold}/src/Project1/bin/Debug/net6.0/Project1.dll", + "{Scaffold}/src/Project1/bin/Debug/netstandard2.0/Project1.dll", + "{Scaffold}/tests/Project1.IntegrationTests/bin/Debug/net6.0/Project1.IntegrationTests.dll", + "{Scaffold}/tests/Project1.UnitTests/bin/Debug/net6.0/Project1.UnitTests.dll" + ] +} , files: [ diff --git a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project2_gitUser=gitUser_author=authorname.verified.txt b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project2_gitUser=gitUser_author=authorname.verified.txt index b1e748c..d7ae709 100644 --- a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project2_gitUser=gitUser_author=authorname.verified.txt +++ b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Snapshots/ScaffoldingTests.BuildRepositoryTemplate_projectName=Project2_gitUser=gitUser_author=authorname.verified.txt @@ -6,29 +6,31 @@ Install for {ProjectDir:dotnet-library-repo} succeded ---Result--- -Created temp directory at {Scaffold} +Install for {ProjectDir:dotnet-template} succeded ----Command--- +---Result--- -dotnet new dotnet-library-repo -o "{Scaffold}" -n "Project2" --GitProjectName "Project2" --NugetPackageId "Project2" --ProductName "Project2" --GitUser "gitUser" --Author "authorname" +Created temp directory at {Scaffold} ---Result--- -{ - "ExitCode": 0, - "Output": "The template /u0022nuget library repository/u0022 was created successfully.", - "Errors": "", - "Success": true, - "Runtime": "00:00:00" -} +success: new dotnet-library-repo -o "{Scaffold}" -n "Project2" --GitProjectName "Project2" --NugetPackageId "Project2" --ProductName "Project2" --GitUser "gitUser" --Author "authorname" ---Result--- success: restore "{Scaffold}/src/Project2.sln" -v m --ignore-failed-sources ----Result--- +---BuildResult--- -success: build {Scaffold}/src/Project2.sln --no-restore -v m +{ + "Command": "build {Scaffold}/src/Project2.sln --no-restore -v m", + "Files": [ + "{Scaffold}/src/Project2/bin/Debug/net6.0/Project2.dll", + "{Scaffold}/src/Project2/bin/Debug/netstandard2.0/Project2.dll", + "{Scaffold}/tests/Project2.IntegrationTests/bin/Debug/net6.0/Project2.IntegrationTests.dll", + "{Scaffold}/tests/Project2.UnitTests/bin/Debug/net6.0/Project2.UnitTests.dll" + ] +} , files: [ diff --git a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Tests/ScaffoldingTests.cs b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Tests/ScaffoldingTests.cs index d4cb2e9..d701080 100644 --- a/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Tests/ScaffoldingTests.cs +++ b/tests/Amusoft.DotnetNew.Tests.IntegrationTests/Tests/ScaffoldingTests.cs @@ -45,7 +45,7 @@ await Verifier.Verify(new ) .UseParameters(projectName, gitUser, author); - installations.Installations.Count.ShouldBe(1); + installations.Installations.Count.ShouldBe(2); } } } diff --git a/tests/Amusoft.DotnetNew.Tests.UnitTests/Snapshots/CommandResultTests.VerifyBuildResult.verified.txt b/tests/Amusoft.DotnetNew.Tests.UnitTests/Snapshots/CommandResultTests.VerifyBuildResult.verified.txt new file mode 100644 index 0000000..7cf75f9 --- /dev/null +++ b/tests/Amusoft.DotnetNew.Tests.UnitTests/Snapshots/CommandResultTests.VerifyBuildResult.verified.txt @@ -0,0 +1,12 @@ +---BuildResult--- + +{ + "Command": "cli args", + "Files": [ + "C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\bin\\Debug\\net6.0\\Project1.dll", + "C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\bin\\Debug\\netstandard2.0\\Project1.dll", + "C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\tests\\Project1.IntegrationTests\\bin\\Debug\\net6.0\\Project1.IntegrationTests.dll", + "C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\tests\\Project1.UnitTests\\bin\\Debug\\net6.0\\Project1.UnitTests.dll" + ] +} + diff --git a/tests/Amusoft.DotnetNew.Tests.UnitTests/Tests/CommandResultTests.cs b/tests/Amusoft.DotnetNew.Tests.UnitTests/Tests/CommandResultTests.cs index 3e37e62..92681c4 100644 --- a/tests/Amusoft.DotnetNew.Tests.UnitTests/Tests/CommandResultTests.cs +++ b/tests/Amusoft.DotnetNew.Tests.UnitTests/Tests/CommandResultTests.cs @@ -26,4 +26,15 @@ private async Task VerifyDotnetCommand() dotnetCommand.Print(sb); await Verifier.Verify(sb.ToString()); } + + [Fact] + private async Task VerifyBuildResult() + { + var content + = "C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0]C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0]C:\\Users\\A\\.nuget\\packages\\microsoft.sourcelink.common\\1.0.0\\build\\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0] Project1 -> C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\bin\\Debug\\netstandard2.0\\Project1.dll Project1.IntegrationTests -> C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\tests\\Project1.IntegrationTests\\bin\\Debug\\net6.0\\Project1.IntegrationTests.dllC:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0]C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0]C:\\Users\\A\\.nuget\\packages\\microsoft.sourcelink.common\\1.0.0\\build\\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0] Project1 -> C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\bin\\Debug\\net6.0\\Project1.dll Project1.UnitTests -> C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\tests\\Project1.UnitTests\\bin\\Debug\\net6.0\\Project1.UnitTests.dllBuild succeeded.C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0]C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0]C:\\Users\\A\\.nuget\\packages\\microsoft.sourcelink.common\\1.0.0\\build\\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=netstandard2.0]C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0]C:\\Users\\A\\.nuget\\packages\\microsoft.build.tasks.git\\1.0.0\\build\\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1'. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0]C:\\Users\\A\\.nuget\\packages\\microsoft.sourcelink.common\\1.0.0\\build\\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [C:\\Users\\A\\AppData\\Local\\Temp\\6e95ba419fa843259d960d2c4f9c4d18\\src\\Project1\\Project1.csproj::TargetFramework=net6.0] 6 Warning(s) 0 Error(s)Time Elapsed 00:00:01.07"; + var dotnetCommand = new BuildResult("cli args", content); + var sb = new StringBuilder(); + dotnetCommand.Print(sb); + await Verifier.Verify(sb.ToString()); + } } \ No newline at end of file