Skip to content

Commit 12176a6

Browse files
committed
Fix test.
1 parent 82e9d49 commit 12176a6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/BenchmarkDotNet.Tests/Running/RunningEmptyBenchmarkTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using BenchmarkDotNet.Loggers;
1010
using BenchmarkDotNet.Reports;
1111
using System.Runtime.InteropServices;
12+
using System.Runtime.CompilerServices;
1213

1314
namespace BenchmarkDotNet.Tests.Running
1415
{
@@ -278,12 +279,13 @@ public void AssemblyWithBenchmarks_RunsSuccessfully_WhenBenchmarkAttributePresen
278279
var ilGenerator = benchmarkMethod.GetILGenerator();
279280
ilGenerator.Emit(OpCodes.Ret); // Just return from the method
280281

281-
var benchmarkAttributeCtor = typeof(BenchmarkAttribute).GetConstructor(new[] { typeof(int), typeof(string) });
282-
if (benchmarkAttributeCtor == null)
283-
throw new InvalidOperationException("Could not find BenchmarkAttribute constructor");
284282
benchmarkMethod.SetCustomAttribute(new CustomAttributeBuilder(
285-
benchmarkAttributeCtor,
286-
new object[] { 0, "" }));
283+
typeof(BenchmarkAttribute).GetConstructor([typeof(int), typeof(string)]),
284+
[0, ""]));
285+
// Assembly weaver does not run on assemblies created with AssemblyBuilder, so we need to apply NoInlining manually.
286+
benchmarkMethod.SetCustomAttribute(new CustomAttributeBuilder(
287+
typeof(MethodImplAttribute).GetConstructor([typeof(MethodImplOptions)]),
288+
[MethodImplOptions.NoInlining]));
287289
benchmarkTypeBuilder.CreateType();
288290

289291
Summary[] summaries = null;

0 commit comments

Comments
 (0)