PasUnit
version 1.0.6

Yann Mérignac (yann.merignac@laposte.net)
29/07/2014


PasUnit is a very simple unit testing framework for Free Pascal.

License

GNU

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/>.

Example

This is a very simple test program.

example.pas
program example;
{$mode objfpc}{$H+}
{$assertions on}                  // 1
uses
  Classes, SysUtils, PasUnit;

var
  N, Zero : Integer;

procedure TestAdd;                // 2
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');  // 3
  RegisterTest('Add', @TestAdd); // 4
  RegisterTest('Sub', @TestSub);

  RegisterSection('Section 2');
  RegisterTest('Div', @TestDiv);
  RegisterTest('Mul', @TestMul);

  RunTests;
end.
1 Ensure that assertions are on.
2 A test is simply a procedure with no parameters.
3 This line creates a new section.
4 This line registers a test.

Runing this test is trivial:

user$ fpc example
user$ ./example

The result should be something like:

pasunit-screen.png
   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) **

Downloads