Skip to content

Commit 30c7301

Browse files
aelijtimcassell
andauthored
Add test for required properties in InProcess (#2713)
* Add test for required properties in InProcess * Add test * PR comments * Simplify test and add InProcessEmit test. Added todo to use new PersistedAssemblyBuilder in net9.0. --------- Co-authored-by: Tim Cassell <[email protected]>
1 parent c4bc752 commit 30c7301

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs

+22
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private void DiffEmit(Summary summary)
6666
{
6767
// .Net Core does not support assembly saving so far
6868
// SEE https://github.com/dotnet/corefx/issues/4491
69+
// TODO: Use new PersistedAssemblyBuilder when BDN and tests are updated to net9.0 or newer.
6970
if (!Portability.RuntimeInformation.IsFullFramework)
7071
return;
7172

@@ -363,5 +364,26 @@ public void InvokeOnceVoid()
363364
Interlocked.Increment(ref Counters.BenchmarkCounter);
364365
}
365366
}
367+
368+
369+
#if NET8_0_OR_GREATER
370+
[Fact]
371+
public void ParamsSupportRequiredProperty()
372+
{
373+
var config = CreateInProcessConfig(null);
374+
CanExecute<ParamsTestRequiredProperty>(config);
375+
}
376+
377+
public class ParamsTestRequiredProperty
378+
{
379+
private const string Expected = "a";
380+
381+
[Params(Expected)]
382+
public required string ParamProperty { get; set; }
383+
384+
[Benchmark]
385+
public void Benchmark() => Assert.Equal(Expected, ParamProperty);
386+
}
387+
#endif
366388
}
367389
}

tests/BenchmarkDotNet.IntegrationTests/InProcessTest.cs

+21
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,26 @@ public ValueTask<decimal> InvokeOnceValueTaskOfT()
273273
return new ValueTask<decimal>(DecimalResult);
274274
}
275275
}
276+
277+
278+
#if NET8_0_OR_GREATER
279+
[Fact]
280+
public void ParamsSupportRequiredProperty()
281+
{
282+
var config = CreateInProcessConfig();
283+
CanExecute<ParamsTestRequiredProperty>(config);
284+
}
285+
286+
public class ParamsTestRequiredProperty
287+
{
288+
private const string Expected = "a";
289+
290+
[Params(Expected)]
291+
public required string ParamProperty { get; set; }
292+
293+
[Benchmark]
294+
public void Benchmark() => Assert.Equal(Expected, ParamProperty);
295+
}
296+
#endif
276297
}
277298
}

0 commit comments

Comments
 (0)