Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3202

Show
Ignore:
Timestamp:
02/16/08 08:56:07 (10 months ago)
Author:
larsivi
Message:

Can now create a unittest runner that reports and continues instead of aborting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/unittest.sh

    r3176 r3202  
    1313} 
    1414 
     15usage() { 
     16    echo 'Usage: ./unittest.sh [otions ...] 
     17Options: 
     18  --help: This message 
     19  --run-all: Reports result instead of breaking. Do not use this if you want to 
     20         run unittest runner through a debugger. 
     21  dmd: Builds unittests for dmd 
     22  gdc: Builds unittests for gdc 
     23 
     24  <none>: Builds unittests for all known compilers.' 
     25  exit 0 
     26} 
     27 
    1528DC= 
    1629LIB= 
     30RUNALL= 
    1731 
    1832compile() { 
     
    3246module ${EXE}; 
    3347 
     48import tango.io.Stdout; 
     49import tango.core.Runtime; 
     50 
     51bool tangoUnitTester() 
     52{ 
     53    uint count = 0; 
     54    Stdout ("NOTE: This is still fairly rudimentary, and will only report the").newline; 
     55    Stdout ("    first error per module.").newline; 
     56    foreach ( m; ModuleInfo )  // _moduleinfo_array ) 
     57    { 
     58        if ( m.unitTest) { 
     59            Stdout.format ("{}. Executing unittests in '{}' ", count, m.name); 
     60            try { 
     61               m.unitTest(); 
     62            } 
     63            catch (Exception e) { 
     64                Stdout(" - Unittest failed.").newline; 
     65                Stdout.format("   File '{}', line '{}'.", e.file, e.line).newline; 
     66                Stdout.format("     Message is : '{}'", e.msg).newline; 
     67                if (e.info) 
     68                    Stdout.format("     TraceInfo: {}", e.info.toString).newline; 
     69                continue; 
     70            } 
     71            Stdout(" - Success.").newline; 
     72            count++; 
     73        } 
     74    } 
     75    return true; 
     76} 
     77 
     78static this() { 
     79    $RUNALL     
     80} 
     81 
    3482void main() {} 
    3583EOF 
    3684 
    37         rebuild -d -L-ldl -L-lz -debug=UnitTest -debug -full -clean -unittest -version=UnitTest $EXE.d tango/core/*.d tango/io/digest/*.d tango/io/model/*.d tango/io/protocol/*.d tango/io/selector/*.d tango/io/*.d tango/io/vfs/*.d tango/io/vfs/model/* tango/math/*.d tango/net/ftp/*.d tango/net/http/*.d tango/net/model/*.d tango/stdc/stringz.d tango/sys/*.d tango/text/convert/*.d tango/text/locale/Collation.d tango/text/locale/Convert.d tango/text/locale/Core.d tango/text/locale/Data.d tango/text/locale/Locale.d tango/text/locale/Parse.d tango/text/locale/Posix.d tango/text/stream/*.d tango/text/*.d tango/util/*.d tango/util/collection/model/*.d tango/util/collection/*.d tango/util/collection/iterator/*.d tango/util/collection/impl/*.d tango/util/log/model/*.d tango/util/log/*.d tango/time/chrono/*.d tango/time/*.d -dc=$DC-posix-tango 
     85        rebuild -w -d -g -L-ldl -L-lz -debug=UnitTest -debug -full -clean -unittest -version=UnitTest $EXE.d tango/core/*.d tango/io/digest/*.d tango/io/model/*.d tango/io/protocol/*.d tango/io/selector/*.d tango/io/*.d tango/io/vfs/*.d tango/io/vfs/model/* tango/math/*.d tango/net/ftp/*.d tango/net/http/*.d tango/net/model/*.d tango/stdc/stringz.d tango/sys/*.d tango/text/convert/*.d tango/text/locale/Collation.d tango/text/locale/Convert.d tango/text/locale/Core.d tango/text/locale/Data.d tango/text/locale/Locale.d tango/text/locale/Parse.d tango/text/locale/Posix.d tango/text/stream/*.d tango/text/*.d tango/util/*.d tango/util/collection/model/*.d tango/util/collection/*.d tango/util/collection/iterator/*.d tango/util/collection/impl/*.d tango/util/log/model/*.d tango/util/log/*.d tango/time/chrono/*.d tango/time/*.d -dc=$DC-posix-tango 
    3886 
    3987        mv $EXE lib/$EXE 
     
    4593} 
    4694 
    47 compile dmd runUnitTest_dmd 
    48 compile gdc runUnitTest_gdc 
     95while [ "$#" != "0" ] 
     96do 
     97    case "$1" in 
     98        --help) 
     99            usage 
     100            ;; 
     101        --run-all) 
     102            RUNALL="Runtime.moduleUnitTester( &tangoUnitTester );" 
     103            ;; 
     104        dmd) 
     105            DMD=1 
     106            ;; 
     107        gdc) 
     108            GDC=1 
     109            ;; 
     110        *) 
     111            usage 
     112            ;; 
     113    esac 
     114    shift 
     115done 
     116 
     117if [ ! "$DMD" -a ! "$GDC" ] 
     118then 
     119    DMD=1 
     120    GDC=1 
     121fi 
     122 
     123if [ "$DMD" = "1" ] 
     124then 
     125    compile dmd runUnitTest_dmd 
     126fi 
     127if [ "$GDC" = "1" ] 
     128then 
     129    compile gdc runUnitTest_gdc 
     130fi 
     131