Unit Command.Test

Description

This unit contains procedures to configure and execute a command to create dipslay unit tests colored output. Also should display source code location for each failed test.

If a heap trace file is found on test project directory an output with possible leaks is generated.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TTestRunResult Result of a test project execution.

Functions and Procedures

procedure TestCommand(ABuilder: ICommandBuilder);
function RunTests(ABuilder: ICommandBuilder; const ABuild: Boolean): TTestRunResult;
function BuildTestProject(ABuilder: ICommandBuilder; const AProjectFile: string; const ABuildMode: string = ''): Boolean; overload;
function BuildTestProject(ABuilder: ICommandBuilder; const AProjectFile, ABuildMode: string; out AError: string): Boolean; overload;
function FirstBuildError(const AOutput: string): string;
procedure Registry(ABuilder: ICommandBuilder);
function FindTestProject(ABuilder: ICommandBuilder; const AQuiet: Boolean = False): string;
function GetTestExecutable(ABuilder: ICommandBuilder): string;

Description

Functions and Procedures

procedure TestCommand(ABuilder: ICommandBuilder);

This command searches for a fpcunit test project in the current folder or in a tests subfolder, builds it using lazbuild and runs it. At the end of the execution, an xml file with the same name as the test project is expected to be read. From this reading, a result is generated with the objective of highlighting the tests that failed, formatting the name of the source code file with a line and column in a format that vscode is able to understand and providing the developer with a link for quick navigation through the code.

If a memory leak trace file named heap.trc is found, the command also outputs information with details about the possible memory leaks in a format that vscode can provide easy navigation through the code.

Parameters
ABuilder
Command builder of the main application that will be used to output user instructions about the execution state of this command.
function RunTests(ABuilder: ICommandBuilder; const ABuild: Boolean): TTestRunResult;

Runs the test project found from the current directory and outputs the report. If ABuild is true the test project is built with lazbuild before running. Returns whether the tests ran and how many passed and failed.

Parameters
ABuilder
Command builder of the main application that will be used to output user instructions about the execution state of this command.
ABuild
Builds the test project before running it.
function BuildTestProject(ABuilder: ICommandBuilder; const AProjectFile: string; const ABuildMode: string = ''): Boolean; overload;

Builds the test project using lazbuild. The .lpi file with the same name of the project file is preferred if it exists. Returns true if the build succeeded.

Parameters
ABuilder
Command builder of the main application that will be used to output the build result in case of failure.
AProjectFile
Test project file (.lpr or .lpi).
ABuildMode
Build mode passed to lazbuild, empty for the default one.
function BuildTestProject(ABuilder: ICommandBuilder; const AProjectFile, ABuildMode: string; out AError: string): Boolean; overload;

Builds the test project like the other BuildTestProject, and returns in AError the first error of the compiler when the build fails, for a summary.

Parameters
ABuilder
Command builder of the main application that will be used to output the build result in case of failure.
AProjectFile
Test project file (.lpr or .lpi).
ABuildMode
Build mode passed to lazbuild, empty for the default one.
AError
Returns the first error, or empty if the build succeeded.
function FirstBuildError(const AOutput: string): string;

Returns the first error in the output of lazbuild, the line that explains the failure among the hints and the lazbuild messages, like TestCommandGreet.pas(11,3) Fatal: Can't find unit Command.Interfaces used by TestCommandGreet. The folder of the file and the message number are removed. Returns empty if there is no error.

Parameters
AOutput
Output of lazbuild.
procedure Registry(ABuilder: ICommandBuilder);

Registry a test command using the command builder from pascli.

Parameters
ABuilder
Command builder of the main application that will be used to registry the command.
function FindTestProject(ABuilder: ICommandBuilder; const AQuiet: Boolean = False): string;

From the current directory it tries to locate an fpcunit compatible test project, in the current folder or in a tests subfolder. Returns the complete test project file name, or empty if the project does not exist or is not of the expected type.

Parameters
ABuilder
Command builder of the main application that will be used to output info about the existence of the test project and whether it is valid.
AQuiet
Does not output a message when the project is not found.
function GetTestExecutable(ABuilder: ICommandBuilder): string;

From the current directory it tries to locate an fpcunit compatible test project that has been previously compiled. Returns complete test file executable name. If the function returns empty, the project does not exist or is not of the expected type.

Parameters
ABuilder
Command builder of the main application that will be used to output info about the existence of the test project and whether it is valid.

Generated by PasDoc 1.0.4.