diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6d590f..c2e22e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: run: dotnet tool update -g dotnet-retest --prerelease --add-source . - name: 🧪 test - run: dotnet retest -- ./src/Sample/ + run: dotnet retest -- ./src/Sample/ --filter "FullyQualifiedName!=Sample.UnitTest1.FailsAlways" - name: 🐛 logs uses: actions/upload-artifact@v4 diff --git a/src/Sample/UnitTest1.cs b/src/Sample/UnitTest1.cs index 107071d..d89b93f 100644 --- a/src/Sample/UnitTest1.cs +++ b/src/Sample/UnitTest1.cs @@ -2,6 +2,12 @@ namespace Sample; public class UnitTest1 { + [Fact] + public void FailsAlways() + { + throw new InvalidOperationException("Always fails"); + } + [Theory] [InlineData(1)] [InlineData(2)] diff --git a/src/dotnet-retest/Properties/launchSettings.json b/src/dotnet-retest/Properties/launchSettings.json index a890715..9d45612 100644 --- a/src/dotnet-retest/Properties/launchSettings.json +++ b/src/dotnet-retest/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "dotnet-retest": { "commandName": "Project", - "commandLineArgs": "", + "commandLineArgs": "-- --filter \"FullyQualifiedName!=Sample.UnitTest1.FailsAlways\"", "workingDirectory": "..\\Sample" } } diff --git a/src/dotnet-retest/RetestCommand.cs b/src/dotnet-retest/RetestCommand.cs index ff6c7f7..2428580 100644 --- a/src/dotnet-retest/RetestCommand.cs +++ b/src/dotnet-retest/RetestCommand.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.CommandLine; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -147,7 +148,7 @@ public override async Task ExecuteAsync(CommandContext context, RetestSetti ctx.Refresh(); } - var exit = await RunTestsAsync(DotnetMuxer.Path.FullName, new List(args), failed, new Progress(line => + var exit = await RunTestsAsync(DotnetMuxer.Path.FullName, [.. args], failed, new Progress(line => { if (ci) { @@ -247,14 +248,26 @@ Dictionary GetTestResults(string path) return outcomes; } + static readonly RootCommand command = new() + { + Options = + { + new Option("--filter") + } + }; + async Task RunTestsAsync(string dotnet, List args, IEnumerable failed, IProgress progress) { - var testArgs = string.Join(" ", args); var finalArgs = args; var filter = string.Join('|', failed.Select(failed => $"FullyQualifiedName~{failed}")); if (filter.Length > 0) { - testArgs = $"--filter \"{filter}\" {testArgs}"; + var parsed = command.Parse(args); + if (parsed.GetValue("--filter") is { } existing) + { + finalArgs = [.. parsed.UnmatchedTokens]; + filter = $"({existing})&({filter})"; + } finalArgs.InsertRange(0, ["--filter", filter]); } diff --git a/src/dotnet-retest/dotnet-retest.csproj b/src/dotnet-retest/dotnet-retest.csproj index ff7f495..3adc3df 100644 --- a/src/dotnet-retest/dotnet-retest.csproj +++ b/src/dotnet-retest/dotnet-retest.csproj @@ -31,6 +31,7 @@ + @@ -47,8 +48,7 @@ - +