Browse Source

--- Merging r24889 into '.':
U packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
U packages/fcl-fpcunit/src/fpcunit.pp
--- Merging r25378 into '.':
G packages/fcl-fpcunit/src/fpcunit.pp

# revisions: 24889,25378
r24889 | michael | 2013-06-13 16:43:21 +0200 (Thu, 13 Jun 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
M /trunk/packages/fcl-fpcunit/src/fpcunit.pp

* Patch from Reinier OlieSlagers to correct message in case of not equals (bug ID 24433)
r25378 | michael | 2013-08-27 12:02:03 +0200 (Tue, 27 Aug 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-fpcunit/src/fpcunit.pp

* Remove redundant if

git-svn-id: branches/fixes_2_6@25765 -

marco 12 years ago
parent
commit
13daadd2db

+ 3 - 3
packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc

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

+ 23 - 5
packages/fcl-fpcunit/src/fpcunit.pp

@@ -285,12 +285,13 @@ type
     property StartingTime: TDateTime read FStartingTime;
     property StartingTime: TDateTime read FStartingTime;
   end;
   end;
 
 
-  function ComparisonMsg(const aExpected: string; const aActual: string): string;
+  function ComparisonMsg(const aExpected: string; const aActual: string; const aCheckEqual: boolean=true): string;
 
 
   
   
 Resourcestring
 Resourcestring
 
 
   SCompare = ' expected: <%s> but was: <%s>';
   SCompare = ' expected: <%s> but was: <%s>';
+  SCompareNotEqual = ' expected: not equal to <%s> but was: <%s>';
   SExpectedNotSame = 'expected not same';
   SExpectedNotSame = 'expected not same';
   SExceptionCompare = 'Exception %s expected but %s was raised';
   SExceptionCompare = 'Exception %s expected but %s was raised';
   SMethodNotFound = 'Method <%s> not found';
   SMethodNotFound = 'Method <%s> not found';
@@ -332,9 +333,13 @@ begin
 end;
 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
 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;
 end;
 
 
 
 
@@ -375,7 +380,10 @@ end;
 
 
 function TTestFailure.GetExceptionClassName: string;
 function TTestFailure.GetExceptionClassName: string;
 begin
 begin
-  Result := FRaisedExceptionClass.ClassName;
+  if Assigned(FRaisedExceptionClass) then
+    Result := FRaisedExceptionClass.ClassName
+  else
+    Result := '<NIL>'
 end;
 end;
 
 
 
 
@@ -570,8 +578,17 @@ end;
 
 
 
 
 class procedure TAssert.AssertEquals(const AMessage: string; Expected, Actual: TClass);
 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
 begin
-  AssertTrue(AMessage + ComparisonMsg(Expected.ClassName, Actual.ClassName), Expected = Actual);
+  AssertTrue(AMessage + ComparisonMsg(GetN(Expected), GetN(Actual)), Expected = Actual);
 end;
 end;
 
 
 
 
@@ -892,6 +909,7 @@ var
   i: integer;
   i: integer;
   tc: TTestCaseClass;
   tc: TTestCaseClass;
 begin
 begin
+  TAssert.AssertNotNull(AClass);
   Create(AClass.ClassName);
   Create(AClass.ClassName);
   if AClass.InheritsFrom(TTestCase) then
   if AClass.InheritsFrom(TTestCase) then
   begin
   begin