Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions TUnit.Analyzers/GlobalTestHooksAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,20 @@ private static HookParameterStatus CheckHookParameters(IMethodSymbol methodSymbo
return HookParameterStatus.Valid;
}

// Single CancellationToken parameter is valid (though context is recommended)
if (parameters.Length == 1 &&
// Single CancellationToken parameter is valid (though context is recommended).
// Note: A default value is NOT required on the CancellationToken parameter because the
// framework always provides one. In source-gen mode, the generated hook body delegate always
// passes cancellationToken. In reflection mode, CreateHookDelegate/CreateInstanceHookDelegate
// always passes the CancellationToken via method.Invoke args.
if (parameters.Length == 1 &&
parameters[0].Type.GloballyQualifiedNonGeneric() == "global::System.Threading.CancellationToken")
{
return HookParameterStatus.Valid;
}

// Context + CancellationToken is valid
if (parameters.Length == 2 &&

// Context + CancellationToken is valid (default value not required on CancellationToken;
// the framework always provides one at invocation time).
if (parameters.Length == 2 &&
parameters[0].Type.GloballyQualifiedNonGeneric() == contextType &&
parameters[1].Type.GloballyQualifiedNonGeneric() == "global::System.Threading.CancellationToken")
{
Expand Down
Loading