You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An access violation occurs in the TBehavior.Match function when the first matcher is not defined. This issue arises because the MatchWithMatchers function attempts to access an undefined matcher, leading to a runtime error.
Steps to Reproduce:
Create a mock object using TMock<IInterfaceToTest>.
Set up the mock to return a value when specific parameters are matched.
Call the method with the specified parameters.
Example Code:
procedureTExample_MatchersTests.Match_parameter_partial();
var
mockCredit: TMock<IInterfaceToTest>;
begin
mockCredit := TMock<IInterfaceToTest>.Create;
mockCredit.Setup.WillReturn(6).When.TakesTwoParams(1, It(1).IsEqualTo<boolean>(true));
Assert.AreEqual(6, mockCredit.Instance.TakesTwoParams(1, true));
end;
Presumed Bug Location:
The bug is likely in the TBehavior.Match function, specifically within the MatchWithMatchers function:
functionTBehavior.Match(const Args: TArray<TValue>): Boolean;
functionMatchWithMatchers: Boolean;
var
i : integer;
begin
result := False;
for i := 0to High(FMatchers) dobegin// Access violation when FMatchers[i] is nilifnot FMatchers[i].Match(Args[i+1]) then
exit;
end;
result := True;
end;
Expected Behavior:
The function should handle cases where matchers are not defined without causing an access violation.
Actual Behavior:
An access violation occurs when the first matcher is not defined.
Environment:
Delphi version: 11.3
Operating System: Windows11
The text was updated successfully, but these errors were encountered:
I beg your pardon for the hustle :)
This issue is a coincidence caused by an incorrect guard exception in the TProxy<T>.DoInvoke method:
procedureTProxy<T>.DoInvoke(Method: TRttiMethod; const Args: TArray<TValue>; out Result: TValue);
...
// Ooops... Someone just defined only the last arguments matcher, others are nils.if Length(matchers) > 0thenif Length(matchers) < Length(Args) - 1then
raise EMockSetupException.Create('Setup called with Matchers but on all parameters : ' + Method.Name); // should say NOT on all parameters
I would suggest
either to fix the Guard,
or make this awesome tool better and allow people to match only some arguments.
An access violation occurs in the
TBehavior.Match
function when the first matcher is not defined. This issue arises because theMatchWithMatchers
function attempts to access an undefined matcher, leading to a runtime error.Steps to Reproduce:
TMock<IInterfaceToTest>
.Example Code:
Presumed Bug Location:
The bug is likely in the
TBehavior.Match
function, specifically within theMatchWithMatchers
function:Expected Behavior:
The function should handle cases where matchers are not defined without causing an access violation.
Actual Behavior:
An access violation occurs when the first matcher is not defined.
Environment:
The text was updated successfully, but these errors were encountered: