-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
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:
procedure TExample_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:
function TBehavior.Match(const Args: TArray<TValue>): Boolean;
function MatchWithMatchers: Boolean;
var
i : integer;
begin
result := False;
for i := 0 to High(FMatchers) do
begin
// Access violation when FMatchers[i] is nil
if not 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
Metadata
Metadata
Assignees
Labels
No labels