Patch from Dean Zobec:

- renamed AssertNull and AssertNotNull for Interfaces to AssertNullIntf,
    AssertNotNullIntf to not confuse the compiler in case of passing objects implementing interfaces
  - registering tests in the unit where they are defined
This commit is contained in:
michael 2005-02-27 12:20:19 +00:00
parent 26381ab2e7
commit e5be257621
7 changed files with 42 additions and 23 deletions

View File

@ -20,15 +20,8 @@ unit suiteconfig;
interface
uses
fpcunittests, testregistry;
procedure RegisterUnitTests;
fpcunittests, moneytest;
implementation
procedure RegisterUnitTests;
begin
RegisterTests([TTestCaseTest, TTestSuiteTest, TAssertTest, TListenerTest]);
end;
end.

View File

@ -17,8 +17,7 @@
**********************************************************************}
program testrunner;
uses
custapp, classes, SysUtils, fpcunit, suiteconfig, testreport,
testregistry;
custapp, classes, SysUtils, fpcunit, suiteconfig, testreport;
Const
ShortOpts = 'alh';
@ -125,7 +124,6 @@ Var
App : TTestRunner;
begin
RegisterUnitTests;
App:=TTestRunner.Create(Nil);
App.Initialize;
App.Title := 'FPCUnit Console Test Case runner.';

View File

@ -20,7 +20,7 @@ unit fpcunittests;
interface
uses
SysUtils, Classes, fpcunit, testutils;
SysUtils, Classes, fpcunit, testutils, testregistry;
type
@ -48,6 +48,8 @@ type
procedure TestExtractMethods;
end;
{ TAssertTest }
TAssertTest = class(TTestCase)
private
Fa,
@ -78,6 +80,7 @@ type
procedure TestNull;
procedure TestNullInterface;
procedure TestNotNull;
procedure TestNotNullWithInterface;
procedure TestNotNullInterface;
procedure TestFailEqualsInt;
procedure TestFailEqualsInt64;
@ -310,6 +313,15 @@ begin
obj.Free;
end;
procedure TAssertTest.TestNotNullWithInterface;
var
obj: TMyIntfObj;
begin
obj := TMyIntfObj.Create;
AssertNotNull(obj);
obj.Free;
end;
procedure TAssertTest.TestNotNullInterface;
var
myintf: IMyIntf;
@ -732,4 +744,8 @@ begin
AssertTrue(True);
end;
initialization
RegisterTests([TTestCaseTest, TTestSuiteTest, TAssertTest, TListenerTest]);
end.

View File

@ -5,7 +5,7 @@ unit moneytest;
interface
uses
Classes, SysUtils, fpcunit, money;
Classes, SysUtils, fpcunit, money, testregistry;
type
@ -290,5 +290,9 @@ begin
AssertTrue('expected ' + mb.toString + ' but was ' + (FMB2 *2).toString, (FMB2 * 2).equals(mb));
end;
initialization
RegisterTests([TMoneyTest]);
end.

View File

@ -90,14 +90,14 @@ type
class procedure AssertNotSame(Expected, Actual: Pointer); overload;
class procedure AssertNotNull(const AMessage: string; AObject: TObject); overload;
class procedure AssertNotNull(AObject: TObject); overload;
class procedure AssertNotNull(const AMessage: string; AInterface: IInterface); overload;
class procedure AssertNotNull(AInterface: IInterface); overload;
class procedure AssertNotNullIntf(const AMessage: string; AInterface: IInterface); overload;
class procedure AssertNotNullIntf(AInterface: IInterface); overload;
class procedure AssertNotNull(const AMessage: string; APointer: Pointer); overload;
class procedure AssertNotNull(APointer: Pointer); overload;
class procedure AssertNull(const AMessage: string; AObject: TObject); overload;
class procedure AssertNull(AObject: TObject); overload;
class procedure AssertNull(const AMessage: string; AInterface: IInterface); overload;
class procedure AssertNull(AInterface: IInterface); overload;
class procedure AssertNullIntf(const AMessage: string; AInterface: IInterface); overload;
class procedure AssertNullIntf(AInterface: IInterface); overload;
class procedure AssertNull(const AMessage: string; APointer: Pointer); overload;
class procedure AssertNull(APointer: Pointer); overload;
class procedure AssertNotNull(const AMessage, AString: string); overload;
@ -518,12 +518,12 @@ begin
AssertNotNull('', AObject);
end;
class procedure TAssert.AssertNotNull(const AMessage: string; AInterface: IInterface);
class procedure TAssert.AssertNotNullIntf(const AMessage: string; AInterface: IInterface);
begin
AssertTrue(AMessage, (AInterface <> nil));
end;
class procedure TAssert.AssertNotNull(AInterface: IInterface);
class procedure TAssert.AssertNotNullIntf(AInterface: IInterface);
begin
AssertNotNull('', AInterface);
end;
@ -548,12 +548,12 @@ begin
AssertNull('', AObject);
end;
class procedure TAssert.AssertNull(const AMessage: string; AInterface: IInterface);
class procedure TAssert.AssertNullIntf(const AMessage: string; AInterface: IInterface);
begin
AssertTrue(AMessage, (AInterface = nil));
end;
class procedure TAssert.AssertNull(AInterface: IInterface);
class procedure TAssert.AssertNullINtf(AInterface: IInterface);
begin
AssertNull('', AInterface);
end;

View File

@ -20,7 +20,7 @@ unit asserttest;
interface
uses
fpcunit;
fpcunit, testregistry;
type
@ -210,5 +210,9 @@ begin
Fail('Error: Objects are the same!');
end;
initialization
RegisterTests([TAssertTest]);
end.

View File

@ -20,7 +20,7 @@ unit suitetest;
interface
uses
fpcunit, testreport;
fpcunit, testreport, testregistry;
type
@ -218,5 +218,9 @@ begin
end;
end;
initialization
RegisterTests([TSuiteTest]);
end.