|
@@ -78,6 +78,8 @@ type
|
|
{ TAssert }
|
|
{ TAssert }
|
|
|
|
|
|
TAssert = class(TTest)
|
|
TAssert = class(TTest)
|
|
|
|
+ protected
|
|
|
|
+ Class var AssertCount : Integer;
|
|
public
|
|
public
|
|
class procedure Fail(const AMessage: string; AErrorAddrs: Pointer = nil);
|
|
class procedure Fail(const AMessage: string; AErrorAddrs: Pointer = nil);
|
|
class procedure Fail(const AFmt: string; Args : Array of const; AErrorAddrs: Pointer = nil);
|
|
class procedure Fail(const AFmt: string; Args : Array of const; AErrorAddrs: Pointer = nil);
|
|
@@ -206,7 +208,10 @@ type
|
|
procedure SetTestName(const Value: string); virtual;
|
|
procedure SetTestName(const Value: string); virtual;
|
|
procedure SetEnableIgnores(Value: boolean); override;
|
|
procedure SetEnableIgnores(Value: boolean); override;
|
|
procedure RunBare; virtual;
|
|
procedure RunBare; virtual;
|
|
|
|
+ Public
|
|
|
|
+ Class Var CheckAssertCalled : Boolean;
|
|
public
|
|
public
|
|
|
|
+
|
|
constructor Create; virtual;
|
|
constructor Create; virtual;
|
|
constructor CreateWith(const ATestName: string; const ATestSuiteName: string); virtual;
|
|
constructor CreateWith(const ATestName: string; const ATestSuiteName: string); virtual;
|
|
constructor CreateWithName(const AName: string); virtual;
|
|
constructor CreateWithName(const AName: string); virtual;
|
|
@@ -330,7 +335,8 @@ Resourcestring
|
|
SNoValidInheritance = ' does not inherit from TTestCase';
|
|
SNoValidInheritance = ' does not inherit from TTestCase';
|
|
SNoValidTests = 'No valid tests found in ';
|
|
SNoValidTests = 'No valid tests found in ';
|
|
SNoException = 'no exception';
|
|
SNoException = 'no exception';
|
|
-
|
|
|
|
|
|
+ SAssertNotCalled = 'Assert not called during test.';
|
|
|
|
+
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
@@ -545,6 +551,7 @@ end;
|
|
|
|
|
|
class procedure TAssert.Fail(const AMessage: string; AErrorAddrs: Pointer);
|
|
class procedure TAssert.Fail(const AMessage: string; AErrorAddrs: Pointer);
|
|
begin
|
|
begin
|
|
|
|
+ Inc(AssertCount);
|
|
if AErrorAddrs = nil then
|
|
if AErrorAddrs = nil then
|
|
raise EAssertionFailedError.Create(AMessage) at CallerAddr
|
|
raise EAssertionFailedError.Create(AMessage) at CallerAddr
|
|
else
|
|
else
|
|
@@ -553,6 +560,7 @@ end;
|
|
|
|
|
|
class procedure TAssert.Fail(const AFmt: string; Args: array of const; AErrorAddrs: Pointer = nil);
|
|
class procedure TAssert.Fail(const AFmt: string; Args: array of const; AErrorAddrs: Pointer = nil);
|
|
begin
|
|
begin
|
|
|
|
+ Inc(AssertCount);
|
|
if AErrorAddrs = nil then
|
|
if AErrorAddrs = nil then
|
|
raise EAssertionFailedError.CreateFmt(AFmt,Args) at CallerAddr
|
|
raise EAssertionFailedError.CreateFmt(AFmt,Args) at CallerAddr
|
|
else
|
|
else
|
|
@@ -574,7 +582,9 @@ begin
|
|
if AErrorAddrs=Nil then
|
|
if AErrorAddrs=Nil then
|
|
AErrorAddrs:=CallerAddr;
|
|
AErrorAddrs:=CallerAddr;
|
|
if (not ACondition) then
|
|
if (not ACondition) then
|
|
- Fail(AMessage,AErrorAddrs);
|
|
|
|
|
|
+ Fail(AMessage,AErrorAddrs)
|
|
|
|
+ else
|
|
|
|
+ Inc(AssertCount); // Fail will increae AssertCount
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1013,10 +1023,13 @@ begin
|
|
RunMethod := TRunMethod(m);
|
|
RunMethod := TRunMethod(m);
|
|
ExpectException('',Nil,'',0);
|
|
ExpectException('',Nil,'',0);
|
|
try
|
|
try
|
|
|
|
+ AssertCount:=0;
|
|
FailMessage:='';
|
|
FailMessage:='';
|
|
RunMethod;
|
|
RunMethod;
|
|
if (FExpectedException<>Nil) then
|
|
if (FExpectedException<>Nil) then
|
|
- FailMessage:=Format(SExceptionCompare, [FExpectedException.ClassName, SNoException])
|
|
|
|
|
|
+ FailMessage:=Format(SExceptionCompare, [FExpectedException.ClassName, SNoException]);
|
|
|
|
+ if CheckAssertCalled and (AssertCount=0) then
|
|
|
|
+ FailMessage:=SAssertNotCalled;
|
|
except
|
|
except
|
|
On E : Exception do
|
|
On E : Exception do
|
|
begin
|
|
begin
|
|
@@ -1465,5 +1478,7 @@ begin
|
|
ITestListener(FListeners[i]).EndTestSuite(ATestSuite);
|
|
ITestListener(FListeners[i]).EndTestSuite(ATestSuite);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+initialization
|
|
|
|
+ TTestCase.CheckAssertCalled:=False;
|
|
end.
|
|
end.
|
|
|
|
|