* Patch from Reinier OlieSlagers to correct message in case of not equals (bug ID 24433)

git-svn-id: trunk@24889 -
This commit is contained in:
michael 2013-06-13 14:43:21 +00:00
parent f95f42d72b
commit 30621e2e06
2 changed files with 27 additions and 8 deletions

View File

@ -85,19 +85,19 @@ end;
class procedure TAssert.CheckNotEquals(expected, actual: string; msg: string);
begin
if AnsiCompareStr(Expected, Actual) = 0 then
Fail(msg + ComparisonMsg(Expected, Actual));
Fail(msg + ComparisonMsg(Expected, Actual, false));
end;
class procedure TAssert.CheckNotEquals(expected, actual: integer; msg: string);
begin
if (expected = actual) then
Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual)));
Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual), false));
end;
class procedure TAssert.CheckNotEquals(expected, actual: boolean; msg: string);
begin
if (expected = actual) then
Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual)));
Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual), false));
end;
class procedure TAssert.CheckNotEquals(expected: extended; actual: extended;

View File

@ -285,12 +285,13 @@ type
property StartingTime: TDateTime read FStartingTime;
end;
function ComparisonMsg(const aExpected: string; const aActual: string): string;
function ComparisonMsg(const aExpected: string; const aActual: string; const aCheckEqual: boolean=true): string;
Resourcestring
SCompare = ' expected: <%s> but was: <%s>';
SCompareNotEqual = ' expected: not equal to <%s> but was: <%s>';
SExpectedNotSame = 'expected not same';
SExceptionCompare = 'Exception %s expected but %s was raised';
SMethodNotFound = 'Method <%s> not found';
@ -332,9 +333,13 @@ begin
end;
function ComparisonMsg(const aExpected: string; const aActual: string): string;
function ComparisonMsg(const aExpected: string; const aActual: string; const aCheckEqual: boolean=true): string;
// aCheckEqual=false gives the error message if the test does *not* expect the results to be the same.
begin
Result := format(SCompare, [aExpected, aActual]);
if aCheckEqual then
Result := format(SCompare, [aExpected, aActual])
else {check unequal requires opposite error message}
Result := format(SCompareNotEqual, [aExpected, aActual]);
end;
@ -375,7 +380,10 @@ end;
function TTestFailure.GetExceptionClassName: string;
begin
Result := FRaisedExceptionClass.ClassName;
if Assigned(FRaisedExceptionClass) then
Result := FRaisedExceptionClass.ClassName
else
Result := '<NIL>'
end;
@ -570,8 +578,18 @@ end;
class procedure TAssert.AssertEquals(const AMessage: string; Expected, Actual: TClass);
Function GetN(C : TClass) : string;
begin
if C=Nil then
Result:='<NIL>'
else
Result:=C.ClassName;
end;
begin
AssertTrue(AMessage + ComparisonMsg(Expected.ClassName, Actual.ClassName), Expected = Actual);
If (Expected<>Nil) then
AssertTrue(AMessage + ComparisonMsg(GetN(Expected), GetN(Actual)), Expected = Actual);
end;
@ -892,6 +910,7 @@ var
i: integer;
tc: TTestCaseClass;
begin
TAssert.AssertNotNull(AClass);
Create(AClass.ClassName);
if AClass.InheritsFrom(TTestCase) then
begin