| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using System.Text; |
| | 4 | | using System.Text.Json; |
| | 5 | | using System.Text.RegularExpressions; |
| | 6 | | using Amusoft.DotnetNew.Tests.Interfaces; |
| | 7 | | using Amusoft.DotnetNew.Tests.Templating; |
| | 8 | | using Amusoft.DotnetNew.Tests.Utility; |
| | 9 | |
|
| | 10 | | namespace Amusoft.DotnetNew.Tests.Diagnostics; |
| | 11 | |
|
| 3 | 12 | | internal class TestResult( |
| 3 | 13 | | string command, |
| 3 | 14 | | string content |
| 3 | 15 | | ) : ICommandResult |
| | 16 | | { |
| | 17 | | // old:.A total of 1 test files matched the specified pattern.Passed! - Failed: 0, Passed: 1, Skipped: 0, |
| | 18 | | // new: Test summary: total: 1; failed: 0; succeeded: 1; skipped: 0; duration: 1,2s |
| | 19 | | // new: Amusoft.Toolkit.Mvvm.Wpf.IntegrationTests test net8.0 succeeded (2,7s) |
| 1 | 20 | | private static readonly Regex Xunit2Regex = new(@"Passed!\s*-\s*Failed:\s*(?<failed>\d+),\s*Passed:\s*(?<passed>\d+),\ |
| 1 | 21 | | private static readonly Regex Xunit3Regex = new(@"Test summary: total: [\d]+; failed: [\d]+; succeeded: [\d]+; skipped |
| | 22 | |
|
| | 23 | | private IEnumerable<string> GetTestResultLines() |
| | 24 | | { |
| 3 | 25 | | if (GetXunit2Lines() is { Length: > 0 } xunit2) |
| 2 | 26 | | return xunit2; |
| 1 | 27 | | if (GetXunit3Lines() is { Length: > 0 } xunit3) |
| 1 | 28 | | return xunit3; |
| | 29 | |
|
| 0 | 30 | | return []; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | private string[] GetXunit2Lines() |
| | 34 | | { |
| 3 | 35 | | var matchCollection = Xunit2Regex.Matches(content); |
| 3 | 36 | | return matchCollection |
| 4 | 37 | | .Select(match => (content: match.Value.Replace(match.Groups["duration"].Value, "SCRUBBED"), sort: match.Groups["pr |
| 4 | 38 | | .OrderBy(d => d.sort) |
| 4 | 39 | | .Select(d => d.content.Trim()) |
| 3 | 40 | | .ToArray(); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | private string[] GetXunit3Lines() |
| | 44 | | { |
| 1 | 45 | | var matchCollection = Xunit3Regex.Matches(content); |
| 1 | 46 | | return matchCollection |
| 7 | 47 | | .Select(match => (content: match.Value.Replace(match.Groups["duration"].Value, " SCRUBBED "), sort: match.Groups[" |
| 7 | 48 | | .OrderBy(d => d.sort) |
| 7 | 49 | | .Select(d => d.content.Trim()) |
| 1 | 50 | | .ToArray(); |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public void Print(StringBuilder stringBuilder) |
| | 54 | | { |
| 3 | 55 | | var serializeContent = new |
| 3 | 56 | | { |
| 3 | 57 | | Command = command, |
| 3 | 58 | | Lines = GetTestResultLines(), |
| 3 | 59 | | }; |
| 3 | 60 | | var serialized = JsonSerializer.Serialize(serializeContent,new JsonSerializerOptions() |
| 3 | 61 | | { |
| 3 | 62 | | WriteIndented = true, |
| 3 | 63 | | Encoder = CustomJsonEncoder.Instance |
| 3 | 64 | | } |
| 3 | 65 | | ); |
| | 66 | |
|
| 3 | 67 | | stringBuilder.Append(TemplatingDefaults.Instance.PrintPattern("TestResult", serialized)); |
| 3 | 68 | | } |
| | 69 | | } |