[fpc-pascal] Testing applications with FPCUnit

Luciano de Souza luchyanus at gmail.com
Sat Dec 17 17:03:42 CET 2011


Michael,

I have a meaningful peculiarity: I am blind and I use Freepascal only in 
the console interface, reading all the output by means of my screen 
reader. Lazarus and Freepascal console IDE are both inaccessible. But, 
fortunately, for me, it's easy to call the compiler passing parameters 
at the command line.

I can compile using callings like:
fpc test.pas
fpc -XX test.pas
fpc test.pas -Fu./pas -FE./exe

I really thank Freepascal developers. The reachness of its command line 
allow me to access the features of the compiler.

For these reasons, it's not possible to open Lazarus and compile the 
project using its interface. My screen reader has an awful response in 
this environment.

After reading your message, I ask for a help. A friend told me fpcunit 
depends on FPCUnitConsole... Well, I don't remember exactly the name, 
but it's a Lazarus package.

Observe I need to compile in the console. If it's possible to run the 
executable, but it's not possible to compile in the command line, I 
won't be able to use FPCUnit.

You said that I need to use '--format=plain' '--all'. I tried:
fpc apptest.pas --format=plain -all
And also:
fpc apptest
apptest --format=plain -alll
But, in both cases, I got no result.
I don't know how to embody this parameters in my compilation tasks.

So I ask you: Is it possible to use FPCUnit only in the command line, it 
means, compiling and executing in console?

The idea of FPCUnit is really wonderful. I really would like to use it, 
but Lazarus dependences can complicate a lot.

Em 17/12/2011 11:02, Michael Van Canneyt escreveu:
>
> You see no test results, because the program file of your test 
> application is missing some essential things.
>
> If you are using lazarus, simply create a new testing application:
>
> First, make sure that package fpcunitide is installed.
>
> Then, in the 'File-New' dialog, your testproject should be of type
>
> 'FPCUNit console test application'
> or
> 'FPCUnit test application'
>
> This will install a test decorator which prints out the result.
> Then add your test unit to this application.
>
> If you run the console test application on the command-line,
> specify options '--format=plain' and '--all'
>
> The graphical application will show test results in a tree.
>
> Michael.
>
> On Sat, 17 Dec 2011, Luciano de Souza wrote:
>
>> The article is very good, but it does not focuse on all aspects.
>>
>> I have tried to create my first test example, but it didn't work. The 
>> compilation is successful and the program is executed without errors. 
>> However, I
>> received no messages, informing the test has failed. Actually, the 
>> test should be failed.
>>
>> This example is seemingly equivalent the minimum example  supplied by 
>> the article.
>>
>> As recommended, I only add the unit "test" in the clause "uses", so 
>> the test was expected to run. Does someone know what is wrong?
>>
>> First of all, a unit with a routine to be tested:
>>
>> unit numbers;
>> {$mode objfpc}{$h+}
>>
>> interface
>> uses
>> Sysutils;
>>
>> function calculate(a, b: integer):integer;
>> implementation
>>
>> function calculate(a, b: integer):integer;
>> begin
>> result := a + b;
>> end;
>>
>> INITIALIZATION
>> END.
>>
>> Now, my testcase class:
>>
>> unit test;
>> {$mode objfpc}{$h+}
>>
>> interface
>> numbers, fpcunit, testregistry;
>> uses
>>
>> type
>> TBugTest = class(TTestCase)
>> published
>> procedure calculate;
>> end;
>>
>> implementation
>> procedure TBugTest.calculate;
>> begin
>> AssertEquals('The calculation is not done', 8, numbers.calculate(5, 4));
>> end;
>>
>> INITIALIZATION
>> RegisterTest(TBugTest);
>> END.
>>
>> Now, the runer:
>>
>> program apptest;
>> {$mode objfpc}{$h+}
>>
>> uses
>> test;
>>
>> begin
>> end.
>>
>> Em 16/12/2011 11:44, Michael Van Canneyt escreveu:
>>
>>
>>       On Fri, 16 Dec 2011, Vincent Snijders wrote:
>>
>>             2011/12/16 luciano de souza <luchyanus at gmail.com>:
>>                   Hello listers,
>>
>>                   Navigating in FPC source codes, I found fpcunit. 
>> It's really
>>                   wonderful. With the tTestCase class, we can 
>>  generate a report with
>>                   the success or the failure of our tests.
>>
>>                   Is there documentation on the usage of fpcunit? 
>> What is the best way
>>                   to study it?
>>
>>
>>             Google found this (old) article:
>>             http://www.freepascal.org/olddocs-html/fpcunit.pdf
>>
>>
>>       It is old, but still correct.
>>
>>       I will see about refreshing it, and adding it in the FPC 
>> documentation.
>>
>>       Michael.
>>
>>
>> _______________________________________________
>> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>
>>
>>
>> -- 
>> Luciano de Souza
>>
>>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


-- 
Luciano de Souza
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111217/711f7eaf/attachment.html>


More information about the fpc-pascal mailing list