From dc9b80443633c4b6837d10d65801868fc75af17c Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Thu, 20 Jul 2023 03:55:38 +0600 Subject: [PATCH] Fix regression in parsing arguments with spaces Closes #2373 (#2375) * Fix regression in parsing arguments with spaces Closes #2373 * Add test for filtering by parameters * Update tests/BenchmarkDotNet.Tests/TypeFilterTests.cs Co-authored-by: Tim Cassell <35501420+timcassell@users.noreply.github.com> --------- Co-authored-by: Tim Cassell <35501420+timcassell@users.noreply.github.com> --- .../ConsoleArguments/ConfigParser.cs | 10 +------ .../ConfigParserTests.cs | 17 +++++++++++- .../BenchmarkDotNet.Tests/TypeFilterTests.cs | 26 +++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs index c98480ebea..c2ad926c3f 100644 --- a/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs +++ b/src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs @@ -126,15 +126,7 @@ private static (bool Success, string[] ExpandedTokens) ExpandResponseFile(string } else { - if (arg.Contains(' ')) - { - // Workaround for CommandLine library issue with parsing these kind of args. - result.Add(" " + arg); - } - else - { - result.Add(arg); - } + result.Add(arg); } } diff --git a/tests/BenchmarkDotNet.Tests/ConfigParserTests.cs b/tests/BenchmarkDotNet.Tests/ConfigParserTests.cs index 9d012a468f..9a07f0511d 100644 --- a/tests/BenchmarkDotNet.Tests/ConfigParserTests.cs +++ b/tests/BenchmarkDotNet.Tests/ConfigParserTests.cs @@ -587,7 +587,7 @@ public void UsersCanSpecifyWithoutOverheadEvalution() } } - [Fact] + [Fact(Skip = "This should be handled somehow at CommandLineParser level. See https://github.com/commandlineparser/commandline/pull/892")] public void UserCanSpecifyWasmArgs() { var parsedConfiguration = ConfigParser.Parse(new[] { "--runtimes", "wasm", "--wasmArgs", "--expose_wasm --module" }, new OutputLogger(Output)); @@ -600,6 +600,19 @@ public void UserCanSpecifyWasmArgs() } } + [Fact] + public void UserCanSpecifyWasmArgsUsingEquals() + { + var parsedConfiguration = ConfigParser.Parse(new[] { "--runtimes", "wasm", "--wasmArgs=--expose_wasm --module" }, new OutputLogger(Output)); + Assert.True(parsedConfiguration.isSuccess); + var jobs = parsedConfiguration.config.GetJobs(); + foreach (var job in parsedConfiguration.config.GetJobs()) + { + var wasmRuntime = Assert.IsType(job.Environment.Runtime); + Assert.Equal("--expose_wasm --module", wasmRuntime.JavaScriptEngineArguments); + } + } + [Fact] public void UserCanSpecifyWasmArgsViaResponseFile() { @@ -615,6 +628,8 @@ public void UserCanSpecifyWasmArgsViaResponseFile() foreach (var job in parsedConfiguration.config.GetJobs()) { var wasmRuntime = Assert.IsType(job.Environment.Runtime); + // We may need change assertion to just "--expose_wasm --module" + // if https://github.com/commandlineparser/commandline/pull/892 lands Assert.Equal(" --expose_wasm --module", wasmRuntime.JavaScriptEngineArguments); } } diff --git a/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs b/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs index c54d0d9eec..9ec2c63ffc 100644 --- a/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs +++ b/tests/BenchmarkDotNet.Tests/TypeFilterTests.cs @@ -191,6 +191,17 @@ public void ClassAndMethodsCanCombined() Assert.Contains("ClassA.Method2", benchmarks); } + [Fact] + public void MethodCanBeFilteredByParameters() + { + var benchmarks = Filter( + new[] { typeof(ClassA), typeof(ClassB), typeof(ClassE), typeof(NOTTests.ClassD) }, + new[] { "--filter", "BenchmarkDotNet.Tests.ClassE.Method1(value: 0)" }); + + Assert.Single(benchmarks); + Assert.Contains("ClassE.Method1", benchmarks); + } + [Fact] public void GenericTypesCanBeFilteredByDisplayName() { @@ -266,6 +277,21 @@ public class SomeGeneric [Benchmark] public T Create() => Activator.CreateInstance(); } + + [Run] + public class ClassE + { + public static IEnumerable Values => new object[] + { + uint.MinValue, + (uint)12345, // same value used by other tests to compare the perf + uint.MaxValue, + }; + + [Benchmark] + [ArgumentsSource(nameof(Values))] + public string Method1(uint value) => value.ToString(); + } } namespace BenchmarkDotNet.NOTTests