CoreTest.borg

CoreTest.borg


{
GO()::{
` Here comes the inclusion of all the testfiles
` Please note that every testfile should be able
` To run multiple times. The testfiles themselves
` should be located in the directory CoreTest
` Every testfile should use ITEM to test a certain
` item.
  TEST("Table Operations","NatTable")
& TEST("Identity Operations","NatIdentity")
& TEST("Aritmetic Operations","NatArithmetic")
& TEST("Metalevel Operations","NatMeta")
& TEST("Control Flow Primitives","NatStructure")
& TEST("Object Primitives","NatObjects")
& TEST("Agent Primitives","NatAgents")
& TEST("Interaction Primitives","NatInteraction")
& TEST("Timing Primitives","NatTiming")
};

`ITEM wordt opgeroepen om een gegeven functionaliteit van een groep
`te testen. text zou een woord moeten zijn dat omschrijft wat getest
`wordt. func is een functie die true zeergeeft indien alles ok is
`false/crash in het andere geval :-)
showitems:true;
dogc:false;
itemtext:filetext:"";
replyer:void;        `replyobject for sync tests
testrunnr:0;        `testrunnr

ERROR(text)::
    {
    display(filetext+"/"+itemtext+": "+text+" Failure"+eoln);
    false
    };

ITEM(text, func, every)::
    {
    itemtext:=text;
    if (testrunnr\\every = 0,
        if(showitems,
            {
            display(text);
            if (func(), display(" "), ERROR(""))
            },
            {
            display(".");
            if (func(), true, ERROR(""))
            }),
        if(showitems,
            {
            display("----")
            },
            {
            display(" ")
            })
        )
    };


TEST(txt, filename)::
    {
    filetext:=txt;
    if (showitems,
        {
        display("Testing "+txt);
        display("[ ")
        },display("o"));
    if(!(load(filename+".borg")~false),
        {
        if (showitems, display("]"+eoln), false);
        if (dogc, gc(), false);
        true
        },
        {
        display("Load failed !");
        false
        })
    };

displaybar()::
{
now:100*(totalmem()-freemem())/totalmem();
txt:"";
for(cur:0.0,cur<100.0,cur:=cur+3.0,
    txt:=txt+if(cur<=now, "#", "-"));
display(" ",txt,eoln)
};

runtests()::
    {
    stop:false;
    display("Testing with gc() call between tests", eoln);
    dogc:=true;
    GO();
    dogc:=false;
    showitems:=false;
    testrunnr:=1;
    display("____________________________________________________________________________"+eoln);
    while(!stop,
        {display("[",text(testrunnr),"] ");
        stop:=!GO();
        displaybar();
`        display(" ",100*(totalmem()-freemem())/totalmem(),eoln)
        testrunnr:=testrunnr+1
        });
    "done"
    };

runtests()}