Skip to content

Commit

Permalink
add test to ensure all wrapper methods have the last "int opCode" par…
Browse files Browse the repository at this point in the history
…ameter
  • Loading branch information
lucaspimentel committed Jun 3, 2019
1 parent 2f28ef3 commit ba059d4
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Xunit;

namespace Datadog.Trace.ClrProfiler.Managed.Tests
{
public class IntegrationSignatureTests
{
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "Reviewed.")]
public static IEnumerable<object[]> GetWrapperMethods()
{
var integrationsAssembly = typeof(Instrumentation).Assembly;

// find all methods in Datadog.Trace.ClrProfiler.Managed.dll with [InterceptMethod]
var integrations = from wrapperType in integrationsAssembly.GetTypes()
from wrapperMethod in wrapperType.GetRuntimeMethods()
let attributes = wrapperMethod.GetCustomAttributes<InterceptMethodAttribute>(inherit: false)
where attributes.Any()
select new object[] { wrapperMethod };

return integrations;
}

[Theory]
[MemberData(nameof(GetWrapperMethods))]
public void WrapperMethodHasOpCodeArgument(MethodInfo wrapperMethod)

This comment has been minimized.

Copy link
@colin-higgins

colin-higgins Jun 3, 2019

Member

Beautiful!

This comment has been minimized.

Copy link
@zacharycmontoya

zacharycmontoya Jun 3, 2019

Contributor

💯

{
// all wrapper methods should have an additional Int32
// parameter for the original method call's opcode
ParameterInfo lastParameter = wrapperMethod.GetParameters().Last();
Assert.Equal(typeof(int), lastParameter.ParameterType);
Assert.Equal("opCode", lastParameter.Name);
}
}
}

0 comments on commit ba059d4

Please sign in to comment.