View Issue Details

IDProjectCategoryView StatusLast Update
0034075FPCFCLpublic2018-08-02 08:00
ReporterFr0sTAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSWindowsOS Version7
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0034075: FPCUnit - CheckNotEquals do not affect assert counter
DescriptionCurrently CheckNotEquals, CheckTrue, CheckFalse methods do not change AssertCount field thus triggering false positive of assert count check. I suggest simple patch to solve this issue.
Steps To ReproduceCreate a test with one of mentioned methods
Set TTestCase.CheckAssertCalled := True
Run test
Observe "N assertions were called" error
Additional InformationIn general, I'm not sure if changing this counter in every method is OK. Seems more logical to call some basic method like AssertTrue(True) or something.
Tagsfpcunit
Fixed in Revision39544
FPCOldBugId
FPCTarget
Attached Files
  • assertcount.diff (2,653 bytes)
     .../fcl-fpcunit/src/DUnitCompatibleInterface.inc   | 28 ++++++++++++++++------
     1 file changed, 21 insertions(+), 7 deletions(-)
    
    diff --git a/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc b/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
    index 12ce58064a..b99a3d37b0 100644
    --- a/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
    +++ b/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
    @@ -90,32 +90,42 @@ end;
     class procedure TAssert.CheckNotEquals(expected, actual: string; msg: string);
     begin
       if AnsiCompareStr(Expected, Actual) = 0 then
    -    Fail(msg + ComparisonMsg(Expected, Actual, false));
    +    Fail(msg + ComparisonMsg(Expected, Actual, false))
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckNotEquals(expected, actual: unicodestring; msg: string);
     begin
       if (Expected=Actual) then
    -    Fail(msg + ComparisonMsg(Expected, Actual, false));
    +    Fail(msg + ComparisonMsg(Expected, Actual, false))
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckNotEquals(expected, actual: integer; msg: string);
     begin
       if (expected = actual) then
    -    Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual), false));
    +    Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual), false))
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckNotEquals(expected, actual: boolean; msg: string);
     begin
       if (expected = actual) then
    -    Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual), false));
    +    Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual), false))
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckNotEquals(expected: extended; actual: extended;
       delta: extended; msg: string);
     begin
       if (abs(expected-actual) <= delta) then
    -      FailNotEquals(FloatToStr(expected), FloatToStr(actual), msg, nil);
    +    FailNotEquals(FloatToStr(expected), FloatToStr(actual), msg, nil)
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckNull(obj: IUnknown; msg: string);
    @@ -155,13 +165,17 @@ end;
     class procedure TAssert.CheckTrue(condition: Boolean; msg: string);
     begin
       if (not condition) then
    -      FailNotEquals(BoolToStr(true, true), BoolToStr(false, true), msg, nil);
    +    FailNotEquals(BoolToStr(true, true), BoolToStr(false, true), msg, nil)
    +  else
    +    Inc(AssertCount);
     end;
     
     class procedure TAssert.CheckFalse(condition: Boolean; msg: string);
     begin
       if (condition) then
    -      FailNotEquals(BoolToStr(false, true), BoolToStr(true, true), msg, nil);
    +    FailNotEquals(BoolToStr(false, true), BoolToStr(true, true), msg, nil)
    +  else
    +    Inc(AssertCount);
     end;
     
     
    
    assertcount.diff (2,653 bytes)

Activities

Fr0sT

2018-08-01 17:23

reporter  

assertcount.diff (2,653 bytes)
 .../fcl-fpcunit/src/DUnitCompatibleInterface.inc   | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc b/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
index 12ce58064a..b99a3d37b0 100644
--- a/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
+++ b/packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc
@@ -90,32 +90,42 @@ end;
 class procedure TAssert.CheckNotEquals(expected, actual: string; msg: string);
 begin
   if AnsiCompareStr(Expected, Actual) = 0 then
-    Fail(msg + ComparisonMsg(Expected, Actual, false));
+    Fail(msg + ComparisonMsg(Expected, Actual, false))
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckNotEquals(expected, actual: unicodestring; msg: string);
 begin
   if (Expected=Actual) then
-    Fail(msg + ComparisonMsg(Expected, Actual, false));
+    Fail(msg + ComparisonMsg(Expected, Actual, false))
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckNotEquals(expected, actual: integer; msg: string);
 begin
   if (expected = actual) then
-    Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual), false));
+    Fail(msg + ComparisonMsg(IntToStr(expected), IntToStr(actual), false))
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckNotEquals(expected, actual: boolean; msg: string);
 begin
   if (expected = actual) then
-    Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual), false));
+    Fail(msg + ComparisonMsg(BoolToStr(expected), BoolToStr(actual), false))
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckNotEquals(expected: extended; actual: extended;
   delta: extended; msg: string);
 begin
   if (abs(expected-actual) <= delta) then
-      FailNotEquals(FloatToStr(expected), FloatToStr(actual), msg, nil);
+    FailNotEquals(FloatToStr(expected), FloatToStr(actual), msg, nil)
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckNull(obj: IUnknown; msg: string);
@@ -155,13 +165,17 @@ end;
 class procedure TAssert.CheckTrue(condition: Boolean; msg: string);
 begin
   if (not condition) then
-      FailNotEquals(BoolToStr(true, true), BoolToStr(false, true), msg, nil);
+    FailNotEquals(BoolToStr(true, true), BoolToStr(false, true), msg, nil)
+  else
+    Inc(AssertCount);
 end;
 
 class procedure TAssert.CheckFalse(condition: Boolean; msg: string);
 begin
   if (condition) then
-      FailNotEquals(BoolToStr(false, true), BoolToStr(true, true), msg, nil);
+    FailNotEquals(BoolToStr(false, true), BoolToStr(true, true), msg, nil)
+  else
+    Inc(AssertCount);
 end;
 
 
assertcount.diff (2,653 bytes)

Michael Van Canneyt

2018-08-02 08:00

administrator   ~0109825

Applied the patch, thank you. I will look into cleaning up the counter code.

Issue History

Date Modified Username Field Change
2018-08-01 17:23 Fr0sT New Issue
2018-08-01 17:23 Fr0sT File Added: assertcount.diff
2018-08-01 17:27 Fr0sT Tag Attached: fpcunit
2018-08-01 17:57 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-08-01 17:57 Michael Van Canneyt Status new => assigned
2018-08-02 08:00 Michael Van Canneyt Fixed in Revision => 39544
2018-08-02 08:00 Michael Van Canneyt Note Added: 0109825
2018-08-02 08:00 Michael Van Canneyt Status assigned => resolved
2018-08-02 08:00 Michael Van Canneyt Fixed in Version => 3.1.1
2018-08-02 08:00 Michael Van Canneyt Resolution open => fixed
2018-08-02 08:00 Michael Van Canneyt Target Version => 3.2.0