view core-javascript/core-javascript-work/testtools.js @ 148:7f86f1a807f8 core-javascript

Get testtools.js running on JSDB (and some minor changes).
author jf3243
date Mon, 31 Oct 2011 15:50:46 +0000
parents 71b7fd796ddf
children
line wrap: on
line source

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

// Define a global function 'log'.
var log;
if (this.writeln){             // True if JSDB.
    
    log = function(s){
        print(s + '\n');
    };
} else {
    log = print;    
}

// Log name of test and run the code.
var TEST = function(title, code){

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

// Increment assertion code and report failure.
var assert = function(arg){
    _assertion_count += 1;
    if (!arg){
        var msg = '! assert ' + _assertion_count + ' has failed';
        log(msg);
    }
};