Skip to content

Commit dc9b804

Browse files
kant2002timcassell
andauthored
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>
1 parent 6f471cc commit dc9b804

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,7 @@ private static (bool Success, string[] ExpandedTokens) ExpandResponseFile(string
126126
}
127127
else
128128
{
129-
if (arg.Contains(' '))
130-
{
131-
// Workaround for CommandLine library issue with parsing these kind of args.
132-
result.Add(" " + arg);
133-
}
134-
else
135-
{
136-
result.Add(arg);
137-
}
129+
result.Add(arg);
138130
}
139131
}
140132

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public void UsersCanSpecifyWithoutOverheadEvalution()
587587
}
588588
}
589589

590-
[Fact]
590+
[Fact(Skip = "This should be handled somehow at CommandLineParser level. See https://github.com/commandlineparser/commandline/pull/892")]
591591
public void UserCanSpecifyWasmArgs()
592592
{
593593
var parsedConfiguration = ConfigParser.Parse(new[] { "--runtimes", "wasm", "--wasmArgs", "--expose_wasm --module" }, new OutputLogger(Output));
@@ -600,6 +600,19 @@ public void UserCanSpecifyWasmArgs()
600600
}
601601
}
602602

603+
[Fact]
604+
public void UserCanSpecifyWasmArgsUsingEquals()
605+
{
606+
var parsedConfiguration = ConfigParser.Parse(new[] { "--runtimes", "wasm", "--wasmArgs=--expose_wasm --module" }, new OutputLogger(Output));
607+
Assert.True(parsedConfiguration.isSuccess);
608+
var jobs = parsedConfiguration.config.GetJobs();
609+
foreach (var job in parsedConfiguration.config.GetJobs())
610+
{
611+
var wasmRuntime = Assert.IsType<WasmRuntime>(job.Environment.Runtime);
612+
Assert.Equal("--expose_wasm --module", wasmRuntime.JavaScriptEngineArguments);
613+
}
614+
}
615+
603616
[Fact]
604617
public void UserCanSpecifyWasmArgsViaResponseFile()
605618
{
@@ -615,6 +628,8 @@ public void UserCanSpecifyWasmArgsViaResponseFile()
615628
foreach (var job in parsedConfiguration.config.GetJobs())
616629
{
617630
var wasmRuntime = Assert.IsType<WasmRuntime>(job.Environment.Runtime);
631+
// We may need change assertion to just "--expose_wasm --module"
632+
// if https://github.com/commandlineparser/commandline/pull/892 lands
618633
Assert.Equal(" --expose_wasm --module", wasmRuntime.JavaScriptEngineArguments);
619634
}
620635
}

tests/BenchmarkDotNet.Tests/TypeFilterTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ public void ClassAndMethodsCanCombined()
191191
Assert.Contains("ClassA.Method2", benchmarks);
192192
}
193193

194+
[Fact]
195+
public void MethodCanBeFilteredByParameters()
196+
{
197+
var benchmarks = Filter(
198+
new[] { typeof(ClassA), typeof(ClassB), typeof(ClassE), typeof(NOTTests.ClassD) },
199+
new[] { "--filter", "BenchmarkDotNet.Tests.ClassE.Method1(value: 0)" });
200+
201+
Assert.Single(benchmarks);
202+
Assert.Contains("ClassE.Method1", benchmarks);
203+
}
204+
194205
[Fact]
195206
public void GenericTypesCanBeFilteredByDisplayName()
196207
{
@@ -266,6 +277,21 @@ public class SomeGeneric<T>
266277
[Benchmark]
267278
public T Create() => Activator.CreateInstance<T>();
268279
}
280+
281+
[Run]
282+
public class ClassE
283+
{
284+
public static IEnumerable<object> Values => new object[]
285+
{
286+
uint.MinValue,
287+
(uint)12345, // same value used by other tests to compare the perf
288+
uint.MaxValue,
289+
};
290+
291+
[Benchmark]
292+
[ArgumentsSource(nameof(Values))]
293+
public string Method1(uint value) => value.ToString();
294+
}
269295
}
270296

271297
namespace BenchmarkDotNet.NOTTests

0 commit comments

Comments
 (0)