This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules,and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.
You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>.
This is a very simple test program.
program example;
{$mode objfpc}{$H+}
{$assertions on} //
uses
Classes, SysUtils, PasUnit;
var
N, Zero : Integer;
procedure TestAdd; //
begin
Assert(2 + 2 = 4);
end;
procedure TestSub;
begin
Assert(2 - 2 = 0);
end;
procedure TestDiv;
begin
N := N div Zero;
Assert(N = 56);
end;
procedure TestMul;
begin
Assert(3 * 2 = 6);
end;
begin
N := 54;
Zero := 0;
SetUseColors(true);
RegisterSection('Section 1'); //
RegisterTest('Add', @TestAdd); //
RegisterTest('Sub', @TestSub);
RegisterSection('Section 2');
RegisterTest('Div', @TestDiv);
RegisterTest('Mul', @TestMul);
RunTests;
end.
Ensure that assertions are on. | |
A test is simply a procedure with no parameters. | |
This line creates a new section. | |
This line registers a test. |
Runing this test is trivial:
user$ fpc example user$ ./example
The result should be something like:
Section 1 --------- Add pass (0.000s) sub pass (0.000s) -- 2 tests, 0 failures (0.000s) -- Section 2 --------- Div FAIL (0.002s) ==> EInvalidOp($080480C6) : Invalid floating point operation Mul pass (0.000s) -- 2 tests, 1 failures (0.002s) -- ** Report result : 4 tests, 1 failures (0.002s) **
Version 1.0.6 for FPC 2.6.4
Source distribution |
Version 1.0.4 for FPC 2.6.2 and 2.6.4
Source distribution |