/**
 *    _____ __
 *   / ___// /_  _____
 *   \__ \/ / / / / _ \
 *  ___/ / / /_/ /  __/
 * /____/_/\__, /\___/
 *       /____/
 *       Copyright 2017 Slye Development Team. All Rights Reserved.
 *       Licence: MIT License
 */

const glob      = require('glob');
const esy       = require('../src');
const colors    = require('colors');
const path      = require('path');

const xmark     = '✗ ',
	checkmark   = '✓ ';

const TIMEOUT   = 3000;

esy.configs.load('../tmp/esy.json');
esy.configs.set('cache_dir', '../tmp/.cache');
esy.cache.load();
var _console    = Object.assign({}, console);
for(var name in console){
	if(console.hasOwnProperty(name) && typeof console[name] == 'function')
		console[name]   = function () {};
}
var queue   = [],
	i       = 0,
	names   = [],
	failed  = 0,
	passed  = 0;
function test() {
	if(i == queue.length) {
		_console.log('_____________________'.gray, `\nResult:`);
		if(failed == 0){
			_console.log(`${checkmark} All tests passed.`.green)
		}else {
			_console.log(`${xmark} ${failed} test${failed == 1 ? '' : 's'} failed.`.red)
		}
		return;
	}
	var name    = names[i];
	var func    = queue[i];
	var called  = false;
	var timeout = setTimeout(function () {
		if(!called){
			assert(false);
		}
	}, TIMEOUT);
	var assert  = function(result){
		if(called)
			return;
		called  = true;
		clearTimeout(timeout);
		if(result){
			passed++;
			_console.log(`${checkmark}Test #${i}<${name}> passed.`.cyan)
		}else {
			failed++;
			_console.error(`${xmark}Test #${i}<${name}> failed.`.red)
		}
		i++;
		test();
	};
	func(assert, _console);
}
_console.log("Preparing tests...");
glob('*/*.js', {cwd: __dirname}, function (err, files) {
	var i = 0,
		tests, file, name;
	for(; i < files.length;i++){
		file    = files[i];
		try {
			tests   = require(path.join(__dirname, file));
			if(typeof tests == 'function'){
				names.push(file);
				queue.push(tests)
			}else {
				var keys = Object.keys(tests).filter(name => name.startsWith('$'));
				for(var j = 0; j < keys.length;j++) {
					name = keys[j];
					names.push(file + ':' + name);
					if(tests.hasOwnProperty(name))
						queue.push(tests[name])
				}
			}
		}catch (e){
			_console.error(`Failed to load <${file}>`, e)
		}
	}
	_console.log(`${queue.length} tests are in queue.`);
	test();
});
@@ -1226,16 +1226,22 @@
 rt(false
+, true
 );%0A%09%09%7D%0A%09
@@ -1279,24 +1279,41 @@
 ction(result
+, timeout = false
 )%7B%0A%09%09if(call
@@ -1530,32 +1530,62 @@
 $%7Bname%7D%3E failed.
+$%7Btimeout ? ' (timeout)' : ''%7D
 %60.red)%0A%09%09%7D%0A%09%09i++

Write timeout when test fails becasue of that