mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-29 21:42:28 +01:00
test runner: added writing results to file and showing simple progress
git-svn-id: trunk@9940 -
This commit is contained in:
parent
c5b91833fc
commit
ea03a657dc
@ -1,36 +1,101 @@
|
|||||||
|
{ $ID: $}
|
||||||
|
{ Copyright (C) <2006> <Vincent Snijders>
|
||||||
|
|
||||||
|
This source is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free
|
||||||
|
Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This code is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
A copy of the GNU General Public License is available on the World Wide Web
|
||||||
|
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
|
||||||
|
to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||||
|
MA 02111-1307, USA.
|
||||||
|
}
|
||||||
program runtests;
|
program runtests;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
custapp, Classes, SysUtils, fpcunit, testregistry, testreport,
|
custapp, Classes, SysUtils, fpcunit, testregistry, testreport, testutils,
|
||||||
xmlreporter, xmlwrite,
|
xmlreporter, xmlwrite,
|
||||||
TestLpi;
|
TestLpi;
|
||||||
|
|
||||||
const
|
const
|
||||||
ShortOpts = 'alh';
|
ShortOpts = 'alhp';
|
||||||
Longopts: array[1..6] of string =
|
Longopts: array[1..8] of string =
|
||||||
('all', 'list', 'format:', 'suite:', 'compiler:', 'help');
|
('all', 'list', 'progress', 'help',
|
||||||
Version = 'Version 0.1';
|
'suite:', 'format:', 'file:', 'compiler:');
|
||||||
|
Version = '0.2';
|
||||||
|
|
||||||
type
|
type
|
||||||
TFormat = (fPlain, fLatex, fXML);
|
TFormat = (fPlain, fLatex, fXML);
|
||||||
|
|
||||||
|
{ TTestRunner }
|
||||||
|
|
||||||
TTestRunner = class(TCustomApplication)
|
TTestRunner = class(TCustomApplication)
|
||||||
private
|
private
|
||||||
|
FShowProgress: boolean;
|
||||||
|
FFileName: string;
|
||||||
protected
|
protected
|
||||||
|
property FileName: string read FFileName write FFileName;
|
||||||
|
property ShowProgress: boolean read FShowProgress write FShowProgress;
|
||||||
procedure DoRun; override;
|
procedure DoRun; override;
|
||||||
procedure doTestRun(aTest: TTest); virtual;
|
procedure doTestRun(aTest: TTest); virtual;
|
||||||
public
|
public
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TProgressWriter }
|
||||||
|
|
||||||
|
TProgressWriter= class(TNoRefCountObject, ITestListener)
|
||||||
|
public
|
||||||
|
destructor Destroy; override;
|
||||||
|
|
||||||
|
{ ITestListener interface requirements }
|
||||||
|
procedure AddFailure(ATest: TTest; AFailure: TTestFailure);
|
||||||
|
procedure AddError(ATest: TTest; AError: TTestFailure);
|
||||||
|
procedure StartTest(ATest: TTest);
|
||||||
|
procedure EndTest(ATest: TTest);
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TProgressWriter.Destroy;
|
||||||
|
begin
|
||||||
|
// on descruction, just write the missing line ending
|
||||||
|
writeln;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TProgressWriter.AddFailure(ATest: TTest; AFailure: TTestFailure);
|
||||||
|
begin
|
||||||
|
write('F');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TProgressWriter.AddError(ATest: TTest; AError: TTestFailure);
|
||||||
|
begin
|
||||||
|
write('E');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TProgressWriter.StartTest(ATest: TTest);
|
||||||
|
begin
|
||||||
|
// nothing to do
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TProgressWriter.EndTest(ATest: TTest);
|
||||||
|
begin
|
||||||
|
write('.');
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
FormatParam: TFormat;
|
FormatParam: TFormat;
|
||||||
|
|
||||||
procedure TTestRunner.doTestRun(aTest: TTest);
|
procedure TTestRunner.doTestRun(aTest: TTest);
|
||||||
var
|
var
|
||||||
testResult: TTestResult;
|
testResult: TTestResult;
|
||||||
|
progressWriter: TProgressWriter;
|
||||||
|
|
||||||
procedure doXMLTestRun(aTest: TTest);
|
procedure doXMLTestRun(aTest: TTest);
|
||||||
var
|
var
|
||||||
@ -43,6 +108,9 @@ var
|
|||||||
XMLResultsWriter.WriteResult(testResult);
|
XMLResultsWriter.WriteResult(testResult);
|
||||||
XMLResultsWriter.Document.StylesheetType := 'text/xsl';
|
XMLResultsWriter.Document.StylesheetType := 'text/xsl';
|
||||||
XMLResultsWriter.Document.StylesheetHRef := 'results.xsl';
|
XMLResultsWriter.Document.StylesheetHRef := 'results.xsl';
|
||||||
|
if FileName<>'' then
|
||||||
|
WriteXMLFile(XMLResultsWriter.Document, FileName)
|
||||||
|
else
|
||||||
WriteXMLFile(XMLResultsWriter.Document, output);
|
WriteXMLFile(XMLResultsWriter.Document, output);
|
||||||
finally
|
finally
|
||||||
XMLResultsWriter.Free;
|
XMLResultsWriter.Free;
|
||||||
@ -68,9 +136,13 @@ var
|
|||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
testResult := TTestResult.Create;
|
testResult := TTestResult.Create;
|
||||||
|
if ShowProgress then begin
|
||||||
|
progressWriter := TProgressWriter.Create;
|
||||||
|
testResult.AddListener(progressWriter);
|
||||||
|
end;
|
||||||
|
try
|
||||||
case FormatParam of
|
case FormatParam of
|
||||||
fLatex: doXMLTestRun(aTest); //no latex implemented yet
|
fLatex: doXMLTestRun(aTest); //no latex implemented yet
|
||||||
{$IFNDEF VER2_0}
|
{$IFNDEF VER2_0}
|
||||||
@ -79,13 +151,17 @@ var
|
|||||||
else
|
else
|
||||||
doXMLTestRun(aTest);
|
doXMLTestRun(aTest);
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
if ShowProgress then
|
||||||
|
progressWriter.Free;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestRunner.DoRun;
|
procedure TTestRunner.DoRun;
|
||||||
var
|
var
|
||||||
I: integer;
|
I: integer;
|
||||||
S: string;
|
S: string;
|
||||||
begin
|
begin
|
||||||
S := CheckOptions(ShortOpts, LongOpts);
|
S := CheckOptions(ShortOpts, LongOpts);
|
||||||
if (S <> '') then
|
if (S <> '') then
|
||||||
Writeln(S);
|
Writeln(S);
|
||||||
@ -101,9 +177,11 @@ var
|
|||||||
writeln(' --format=plain output as plain ASCII source');
|
writeln(' --format=plain output as plain ASCII source');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
writeln(' --format=xml output as XML source (default)');
|
writeln(' --format=xml output as XML source (default)');
|
||||||
|
writeln(' --file=<filename> output results to file');
|
||||||
writeln;
|
writeln;
|
||||||
writeln(' -l or --list show a list of registered tests');
|
writeln(' -l or --list show a list of registered tests');
|
||||||
writeln(' -a or --all run all tests');
|
writeln(' -a or --all run all tests');
|
||||||
|
writeln(' -p or --progress show progress');
|
||||||
writeln(' --suite=MyTestSuiteName run single test suite class');
|
writeln(' --suite=MyTestSuiteName run single test suite class');
|
||||||
writeln(' --compiler=<ppcxxx> use ppcxxx to build test projects');
|
writeln(' --compiler=<ppcxxx> use ppcxxx to build test projects');
|
||||||
writeln;
|
writeln;
|
||||||
@ -123,6 +201,11 @@ var
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
ShowProgress := HasOption('p', 'progress');
|
||||||
|
|
||||||
|
if HasOption('file') then
|
||||||
|
FileName := GetOptionValue('file');
|
||||||
|
|
||||||
//get a list of all registed tests
|
//get a list of all registed tests
|
||||||
if HasOption('l', 'list') then
|
if HasOption('l', 'list') then
|
||||||
case FormatParam of
|
case FormatParam of
|
||||||
@ -154,7 +237,7 @@ var
|
|||||||
doTestRun(GetTestRegistry[i]);
|
doTestRun(GetTestRegistry[i]);
|
||||||
end;
|
end;
|
||||||
Terminate;
|
Terminate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
App: TTestRunner;
|
App: TTestRunner;
|
||||||
@ -162,7 +245,7 @@ var
|
|||||||
begin
|
begin
|
||||||
App := TTestRunner.Create(nil);
|
App := TTestRunner.Create(nil);
|
||||||
App.Initialize;
|
App.Initialize;
|
||||||
App.Title := 'FPCUnit Console Test Case runner.';
|
App.Title := 'FPCUnit Console runner for the Lazarus Test Suite.';
|
||||||
App.Run;
|
App.Run;
|
||||||
App.Free;
|
App.Free;
|
||||||
end.
|
end.
|
||||||
|
|||||||
@ -5,8 +5,7 @@ unit TestLpi;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpcunit, testutils, testregistry, process,
|
Classes, SysUtils, fpcunit, testregistry, process, FileUtil;
|
||||||
FileUtil;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -110,6 +109,8 @@ begin
|
|||||||
try
|
try
|
||||||
{$IFDEF win32}
|
{$IFDEF win32}
|
||||||
LazBuild.Options := [poNewConsole];
|
LazBuild.Options := [poNewConsole];
|
||||||
|
{$ELSE}
|
||||||
|
LazBuild.Options := [poNoConsole];
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
LazBuild.ShowWindow := swoHIDE;
|
LazBuild.ShowWindow := swoHIDE;
|
||||||
LazBuild.CommandLine := LazBuildPath;
|
LazBuild.CommandLine := LazBuildPath;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user