Skip to content

Commit

Permalink
Fix regression in parsing arguments with spaces Closes #2373 (#2375)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kant2002 and timcassell authored Jul 19, 2023
1 parent 6f471cc commit dc9b804
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
10 changes: 1 addition & 9 deletions src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
17 changes: 16 additions & 1 deletion tests/BenchmarkDotNet.Tests/ConfigParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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<WasmRuntime>(job.Environment.Runtime);
Assert.Equal("--expose_wasm --module", wasmRuntime.JavaScriptEngineArguments);
}
}

[Fact]
public void UserCanSpecifyWasmArgsViaResponseFile()
{
Expand All @@ -615,6 +628,8 @@ public void UserCanSpecifyWasmArgsViaResponseFile()
foreach (var job in parsedConfiguration.config.GetJobs())
{
var wasmRuntime = Assert.IsType<WasmRuntime>(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);
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/BenchmarkDotNet.Tests/TypeFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -266,6 +277,21 @@ public class SomeGeneric<T>
[Benchmark]
public T Create() => Activator.CreateInstance<T>();
}

[Run]
public class ClassE
{
public static IEnumerable<object> 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
Expand Down

0 comments on commit dc9b804

Please sign in to comment.