dotnet / BenchmarkDotNet

Powerful .NET library for benchmarking
https://benchmarkdotnet.org
MIT License
10.52k stars 968 forks source link

Params string containing characters like quotes is not being escaped properly #738

Closed ahsonkhan closed 6 years ago

ahsonkhan commented 6 years ago
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;

namespace Benchmarks.SystemTextJson
{
    public class JsonReaderPerf
    {
        //[ParamsSource(nameof(ValuesForJsonString))]
        [Params("{ \"message\": \"Hello, World!\" }")]
        public string JsonString;

        // JsonStrings.HelloWorld => { "message": "Hello, World!" }
        // JsonStrings.HelloWorld => { \"message\": \"Hello, World!\" }
        public static IEnumerable<string> ValuesForJsonString() => new[] { JsonStrings.HelloWorld };

        [Benchmark]
        public void SomeTest() => SomeTest(JsonString);

        private static void SomeTest(string data)
        {
        }
    }
}
Build FAILED.

bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,39): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,46): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,50): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,55): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,55): error CS1513: } expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683.notcs(93,62): error CS1002: ; expected [D:\GitHub\Fork\corefxlab\tests\Benchmarks\bin\Release\netcoreapp2.1\bb8d0e6f-34f0-4651-8ca9-1db0ef7f4683\BenchmarkDotNet.Autogenerated.csproj]
    0 Warning(s)
    6 Error(s)

Example snippet from DefaultJob.not.cs (notice the un-escaped string):

        // the type name must be in sync with WindowsDisassembler.BuildArguments
    public class Runnable_0 : global::Benchmarks.SystemTextJson.JsonReaderPerf
    {
        public static void Run(IHost host)
        {
            Runnable_0 instance = new Runnable_0();
            instance.JsonString = "{ "message": "Hello, World!" }";

            host.WriteLine();
            foreach (var infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
            {
                host.WriteLine("// {0}", infoLine);
            }
            var job = new Job();

The issue occurs if we use Params with string directly or ParamSource with string coming from a resource file (even if we escape the string explicitly).

cc @adamsitnik, @KrzysztofCwalina

adamsitnik commented 6 years ago

@ahsonkhan fixed

ahsonkhan commented 6 years ago

Verified the fix in 0.10.14.534

adamsitnik commented 6 years ago

@ahsonkhan thanks!