Browse Source

Merged revisions 7449,7457 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r7449 | michael | 2007-05-24 10:47:09 +0200 (Thu, 24 May 2007) | 1 line

* Patch from Graeme Geldenhuys to easily add testsuites
........
r7457 | michael | 2007-05-24 19:53:46 +0200 (Thu, 24 May 2007) | 1 line

* Patch from Graeme to correct output
........

git-svn-id: branches/fixes_2_2@8037 -

joost 18 years ago
parent
commit
1b631ef8ca

+ 7 - 0
packages/fcl-fpcunit/src/DUnitCompatibleInterface.inc

@@ -20,6 +20,8 @@
     class procedure CheckSame(expected, actual: TObject; msg: string = ''); overload;
     class procedure CheckSame(expected, actual: TObject; msg: string = ''); overload;
     class procedure FailNotEquals(expected, actual: string; msg: string = ''; errorAddr: Pointer = nil); virtual;
     class procedure FailNotEquals(expected, actual: string; msg: string = ''; errorAddr: Pointer = nil); virtual;
 
 
+    class function Suite: TTest;
+
     {
     {
     *** TODO  ***
     *** TODO  ***
     procedure CheckEqualsBin(expected, actual: longword; msg: string = ''; digits: integer=32); virtual;
     procedure CheckEqualsBin(expected, actual: longword; msg: string = ''; digits: integer=32); virtual;
@@ -133,5 +135,10 @@ begin
   Fail(msg + ComparisonMsg(Expected, Actual));
   Fail(msg + ComparisonMsg(Expected, Actual));
 end;
 end;
 
 
+class function TAssert.Suite: TTest;
+begin
+  result := TTestSuite.Create(self);
+end;
+
 {$ENDIF read_implementation}
 {$ENDIF read_implementation}
 
 

+ 1 - 1
packages/fcl-fpcunit/src/fpcunitreport.pp

@@ -189,12 +189,12 @@ begin
     Inc(TSuiteResults(FResultsList[i]).Ignores);
     Inc(TSuiteResults(FResultsList[i]).Ignores);
 end;
 end;
 
 
-
 constructor TCustomResultsWriter.Create(AOwner: TComponent);
 constructor TCustomResultsWriter.Create(AOwner: TComponent);
 begin
 begin
   inherited Create(AOwner);
   inherited Create(AOwner);
   FLevel := -1;
   FLevel := -1;
   FCount := 1;
   FCount := 1;
+  FFilename := '';
   FSuiteResultsStack := TSuiteResultsStack.Create;
   FSuiteResultsStack := TSuiteResultsStack.Create;
 end;
 end;
 
 

+ 76 - 2
packages/fcl-fpcunit/src/testregistry.pp

@@ -1,5 +1,3 @@
-{$mode objfpc}
-{$h+}
 {
 {
     This file is part of the Free Component Library (FCL)
     This file is part of the Free Component Library (FCL)
     Copyright (c) 2004 by Dean Zobec, Michael Van Canneyt
     Copyright (c) 2004 by Dean Zobec, Michael Van Canneyt
@@ -16,6 +14,9 @@
  **********************************************************************}
  **********************************************************************}
 unit testregistry;
 unit testregistry;
 
 
+{$mode objfpc}
+{$h+}
+
 interface
 interface
 
 
 uses
 uses
@@ -27,6 +28,8 @@ type
 
 
 
 
 procedure RegisterTest(ATestClass: TTestCaseClass); overload;
 procedure RegisterTest(ATestClass: TTestCaseClass); overload;
+procedure RegisterTest(ASuitePath: String; ATestClass: TTestCaseClass); overload;
+procedure RegisterTest(ASuitePath: String; ATest: TTest); overload;
 
 
 procedure RegisterTests(ATests: Array of TTestCaseClass);
 procedure RegisterTests(ATests: Array of TTestCaseClass);
 
 
@@ -37,6 +40,9 @@ function NumberOfRegisteredTests: longint;
 function GetTestRegistry: TTestSuite;
 function GetTestRegistry: TTestSuite;
 
 
 implementation
 implementation
+uses
+  Classes
+  ;
 
 
 var
 var
   FTestRegistry: TTestSuite;
   FTestRegistry: TTestSuite;
@@ -48,11 +54,79 @@ begin
   Result := FTestRegistry;
   Result := FTestRegistry;
 end;
 end;
 
 
+procedure RegisterTestInSuite(ARootSuite: TTestSuite; APath: string; ATest: TTest);
+var
+  i: Integer;
+  lTargetSuite: TTestSuite;
+  lCurrentTest: TTest;
+  lSuiteName: String;
+  lPathRemainder: String;
+  lDotPos: Integer;
+  lTests: TFPList;
+begin
+  if APath = '' then
+  begin
+    // end recursion
+    ARootSuite.AddTest(ATest);
+  end
+  else
+  begin
+    // Split the path on the dot (.)
+    lDotPos := Pos('.', APath);
+    if (lDotPos <= 0) then lDotPos := Pos('\', APath);
+    if (lDotPos <= 0) then lDotPos := Pos('/', APath);
+    if (lDotPos > 0) then
+    begin
+      lSuiteName := Copy(APath, 1, lDotPos - 1);
+      lPathRemainder := Copy(APath, lDotPos + 1, length(APath) - lDotPos);
+    end
+    else
+    begin
+      lSuiteName := APath;
+      lPathRemainder := '';
+    end;
+
+    // Check to see if the path already exists
+    lTargetSuite := nil;
+    lTests := ARootSuite.Tests;
+    for i := 0 to lTests.Count -1 do
+    begin
+      lCurrentTest := TTest(lTests[i]);
+      if lCurrentTest is TTestSuite then
+      begin
+        if (lCurrentTest.TestName = lSuiteName) then
+        begin
+          lTargetSuite := TTestSuite(lCurrentTest);
+          break;
+        end;
+      end;  { if }
+    end;  { for }
+
+    if not Assigned(lTargetSuite) then
+    begin
+      lTargetSuite := TTestSuite.Create(lSuiteName);
+      ARootSuite.AddTest(lTargetSuite);
+    end;
+
+    RegisterTestInSuite(lTargetSuite, lPathRemainder, ATest);
+  end;  { if/else }
+end;
+
 procedure RegisterTest(ATestClass: TTestCaseClass);
 procedure RegisterTest(ATestClass: TTestCaseClass);
 begin
 begin
   GetTestRegistry.AddTestSuiteFromClass(ATestClass);
   GetTestRegistry.AddTestSuiteFromClass(ATestClass);
 end;
 end;
 
 
+procedure RegisterTest(ASuitePath: String; ATestClass: TTestCaseClass);
+begin
+  RegisterTestInSuite(GetTestRegistry, ASuitePath, TTestSuite.Create(ATestClass));
+end;
+
+procedure RegisterTest(ASuitePath: String; ATest: TTest);
+begin
+  RegisterTestInSuite(GetTestRegistry, ASuitePath, ATest);
+end;
+
 procedure RegisterTestDecorator(ADecoratorClass: TTestDecoratorClass; ATestClass: TTestCaseClass);
 procedure RegisterTestDecorator(ADecoratorClass: TTestDecoratorClass; ATestClass: TTestCaseClass);
 begin
 begin
   GetTestRegistry.AddTest(ADecoratorClass.Create(TTestSuite.Create(ATestClass)));
   GetTestRegistry.AddTest(ADecoratorClass.Create(TTestSuite.Create(ATestClass)));

+ 9 - 4
packages/fcl-fpcunit/src/xmltestreport.pp

@@ -276,10 +276,15 @@ begin
   n := FDoc.CreateElement('DateTimeRan');
   n := FDoc.CreateElement('DateTimeRan');
   n.AppendChild(FDoc.CreateTextNode(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now)));
   n.AppendChild(FDoc.CreateTextNode(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now)));
   lResults.AppendChild(n);
   lResults.AppendChild(n);
-  system.Assign(f, FileName);
-  rewrite(f);
-  WriteXMLFile(FDoc, f);
-  close(f);
+
+  // This is so that the GUI Test Runner doesn't output text as well.
+  if FileName <> 'null' then
+  begin
+    system.Assign(f, FileName);
+    rewrite(f);
+    WriteXMLFile(FDoc, f);
+    close(f);
+  end;
 end;
 end;
 
 
 end.
 end.