view core-javascript/javascript-exercises/testtools.js @ 168:2d78ae4f0dfa javascript-exercises

Make a start on interactive exercise environment and additional exercises.
author jf3243
date Thu, 10 Nov 2011 12:28:41 +0000
parents 44d0ccb983d3
children 19e88fb18c4e
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;
    log = writeln;              // Wrong, but get us working in jsdb.exe.
}

//
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);
    }
};

var submit = function(name){

    var filename = name + '-exercises.js';
    var status = run(filename);

    if (!status){
        writeln("Could not find file '" + filename + "'");
    }

};