view core-javascript/core-javascript-work/testtools.js @ 213:0ea90a1819c2 default tip

Custom theming
author Radomir Dopieralski <radomir.dopieralski@allegro.pl>
date Wed, 27 Jun 2012 16:35:54 +0200
parents b774913eb242
children
line wrap: on
line source

var telltail = 'global';
var _assertion_count = 0;

// Define a global function 'log'.
var log;
if (this.hasOwnProperty('jsArguments')){

    log = function(s){
        print(s + '\n');
    };
} else {
    log = print;
}

//
var TEST = function(title, code){

    var x;

    log( 'Testing: ' + title );
    _assertion_count = 0;

    try {
        code();
    } catch (x) {
        log('! Exception at ' + x.fileName +':' + x.lineNumber);
        log('! [' + x.name + '] '  + x.message );
    }

};

var assert = function(arg){
    _assertion_count += 1;
    if (!arg){
        var msg = '! assert ' + _assertion_count + ' has failed';
        log(msg);
    }
};