diff --git a/assets/img/demo.png b/assets/img/demo.png index 0872f00..df13793 100644 Binary files a/assets/img/demo.png and b/assets/img/demo.png differ diff --git a/dotnet-trx.sln b/dotnet-trx.sln index b273a71..0de0214 100644 --- a/dotnet-trx.sln +++ b/dotnet-trx.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 17.11.35005.142 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-trx", "src\dotnet-trx\dotnet-trx.csproj", "{CB303249-74AB-468D-BD69-E443081C4690}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "src\Demo\Demo.csproj", "{106AB77F-E544-4BC1-99F9-FE82E62DC44A}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {CB303249-74AB-468D-BD69-E443081C4690}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB303249-74AB-468D-BD69-E443081C4690}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB303249-74AB-468D-BD69-E443081C4690}.Release|Any CPU.Build.0 = Release|Any CPU - {106AB77F-E544-4BC1-99F9-FE82E62DC44A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {106AB77F-E544-4BC1-99F9-FE82E62DC44A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {106AB77F-E544-4BC1-99F9-FE82E62DC44A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {106AB77F-E544-4BC1-99F9-FE82E62DC44A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/readme.md b/readme.md index d1d71e7..08eb05e 100644 --- a/readme.md +++ b/readme.md @@ -13,14 +13,13 @@ Pretty-print test results in TRX format. ```shell USAGE: - trx [PATH] [OPTIONS] - -ARGUMENTS: - [PATH] Optional base directory for *.trx files discovery. Defaults to current directory + trx [OPTIONS] OPTIONS: DEFAULT -h, --help Prints help information + -p, --path Optional base directory for *.trx files discovery. Defaults to current directory + -o, --output Include test output -r, --recursive True Recursively search for *.trx files --version Show version information ``` diff --git a/src/Demo/Tests.cs b/src/Demo/Tests.cs index bd14077..ef26c55 100644 --- a/src/Demo/Tests.cs +++ b/src/Demo/Tests.cs @@ -1,10 +1,14 @@ using System; using System.Threading.Tasks; +using Xunit.Abstractions; namespace Demo; -public class Tests +public class Tests(ITestOutputHelper output) { + [Fact] + public void ICanHasOutput() => output.WriteLine("Hello, world from xunit ITestOutputHelper!"); + [Fact(Skip = "Shouldn't run for now :)")] public void SampleSkipped() { } @@ -13,8 +17,22 @@ public void SampleSkipped() { } [InlineData("fr")] [InlineData("de")] [InlineData("es")] +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters public async Task Parameterized(string culture) => await Task.Delay(Random.Shared.Next(100, 2000)); +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters + + [Fact] + public void OhNoh() => Assert.Equal(42, 22); [Fact] - public void OhNoh() => Assert.Fail(); + public void CleanStackTrace() + { + Action runner = () => Run(); + + runner(); + } + + void Run() => Unexpected(); + + void Unexpected() => throw new InvalidOperationException("This should not happen!"); } \ No newline at end of file diff --git a/src/dotnet-trx/Properties/.gitignore b/src/dotnet-trx/Properties/.gitignore new file mode 100644 index 0000000..8392c90 --- /dev/null +++ b/src/dotnet-trx/Properties/.gitignore @@ -0,0 +1 @@ +launchSettings.json \ No newline at end of file diff --git a/src/dotnet-trx/TrxCommand.cs b/src/dotnet-trx/TrxCommand.cs index ed5c750..98a031a 100644 --- a/src/dotnet-trx/TrxCommand.cs +++ b/src/dotnet-trx/TrxCommand.cs @@ -4,6 +4,7 @@ using System.Linq; using Devlooped.Web; using Humanizer; +using Spectre.Console; using Spectre.Console.Cli; using static Spectre.Console.AnsiConsole; @@ -17,12 +18,16 @@ public class TrxSettings : CommandSettings [CommandOption("-p|--path")] public string? Path { get; init; } - [Description("Recursively search for *.trx files.")] + [Description("Include test output")] + [CommandOption("-o|--output")] + public bool? Output { get; init; } + + [Description("Recursively search for *.trx files")] [CommandOption("-r|--recursive")] [DefaultValue(true)] public bool Recursive { get; init; } = true; - [Description("Show version information.")] + [Description("Show version information")] [CommandOption("--version")] public bool? Version { get; init; } } @@ -50,6 +55,14 @@ public override int Execute(CommandContext context, TrxSettings settings) break; case "Failed": MarkupLine($":cross_mark: {test}"); + var error = new Panel( + $""" + [red]{result.CssSelectElement("Message")?.Value.Trim()}[/] + [dim]{result.CssSelectElement("StackTrace")?.Value.ReplaceLineEndings()}[/] + """); + error.Padding = new Padding(5, 0, 0, 0); + error.Border = BoxBorder.None; + Write(error); break; case "NotExecuted": MarkupLine($":fast_forward_button: {test}"); @@ -58,6 +71,13 @@ public override int Execute(CommandContext context, TrxSettings settings) default: break; } + + if (settings.Output == true && result.CssSelectElement("StdOut")?.Value is { } output) + Write(new Panel($"[dim]{output.ReplaceLineEndings()}[/]") + { + Border = BoxBorder.None, + Padding = new Padding(5, 0, 0, 0), + }); } var counters = doc.CssSelectElement("ResultSummary > Counters"); @@ -83,13 +103,15 @@ public override int Execute(CommandContext context, TrxSettings settings) MarkupLine($" :check_mark_button:"); if (passed > 0) - MarkupLine($" :check_mark_button: {passed} passed"); + MarkupLine($" :check_mark_button: {passed} passed"); if (failed > 0) - MarkupLine($" :cross_mark: {failed} failed"); + MarkupLine($" :cross_mark: {failed} failed"); if (skipped > 0) - MarkupLine($" :fast_forward_button: {skipped} skipped"); + MarkupLine($" :fast_forward_button: {skipped} skipped"); + + WriteLine(); } return 0;