Skip to content

Commit

Permalink
build result feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
taori committed Aug 19, 2024
1 parent 6385381 commit 29fb409
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Amusoft.DotnetNew.Tests/CLI/Dotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions src/Amusoft.DotnetNew.Tests/CLI/LoggedDotnetCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class LoggedDotnetCli
internal static async Task<bool> RunDotnetCommandAsync(string arguments, CancellationToken cancellationToken, int[] acceptAsSuccess)
{
var runner = new LocalProcessRunner();
// var runner = new CliWrapRunner();
return await runner.RunAsync(arguments, cancellationToken, acceptAsSuccess).ConfigureAwait(false);
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/Amusoft.DotnetNew.Tests/Diagnostics/BuildResult.cs
Original file line number Diff line number Diff line change
@@ -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>.+?\\.dll)", RegexOptions.Compiled);

private IEnumerable<string> 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));
}
}
2 changes: 1 addition & 1 deletion src/Amusoft.DotnetNew.Tests/Diagnostics/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Print(StringBuilder stringBuilder)
new JsonSerializerOptions()
{
WriteIndented = true,
Encoder = NewLineIgnoreEncoder.Instance
// Encoder = NewLineIgnoreEncoder.Instance
}
);

Expand Down
1 change: 0 additions & 1 deletion src/Amusoft.DotnetNew.Tests/Diagnostics/TextResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Text;
using Amusoft.DotnetNew.Tests.Interfaces;
using Amusoft.DotnetNew.Tests.Templating;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> Ignores = ['\r', '\n', '\\'];
private static readonly HashSet<int> Ignores = ['\r', '\n', '\\', '<', '>'];

public override bool WillEncode(int unicodeScalar)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ await Verifier.Verify(new
)
.UseParameters(projectName, gitUser, author);

installations.Installations.Count.ShouldBe(1);
installations.Installations.Count.ShouldBe(2);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 29fb409

Please sign in to comment.