var fs = require("fs"),
	slave = require("../slave-driver");
require("colors");

var module = process.argv[2] || "test";

slave.ready(function(run) {
	var s = run(module);

	console.log("Running with NodeJS: " + process.version);
	var out = "", err = "";

	s.on("out", function(data) {
		out += data;
		console.log("[test.js:out]:\n".green + data);
	});

	s.on("err", function(err, data) {
		err += data;
		console.log("[test.js:err]:\n".red + err, data);
	});

	s.on("complete", function(code, sig) {
		fs.writeFile("./logs/" + module + ".out.log", out);
		fs.writeFile("./logs/" + module + ".err.log", err);
		console.log("test completed with code:", code, 'sig:', sig);
	});
});

@@ -1,12 +1,32 @@
+#!/usr/bin/env node%0A
 var fs = req
@@ -34,12 +34,80 @@
 ire(
-%22fs%22
+'fs'),%0A%09args = require('argsparser').parse(),%0A%09colors = require('colors'
 ),%0A%09
@@ -122,17 +122,17 @@
 require(
-%22
+'
 ../slave
@@ -142,120 +142,581 @@
 iver
-%22);%0Arequire(%22colors%22);%0A%0Avar module = process.argv%5B2%5D %7C%7C %22test%22;%0A%0Aslave.ready(function(run) %7B%0A%09var s = run(module
+'),%0A%0A%09// optional flags%0A%09module = process.argv%5B2%5D %7C%7C 'test',%0A%09uninstallAfter = args%5B'--uninstall-after'%5D %7C%7C false,%0A%09reportResults = args%5B'--report-results'%5D %7C%7C false;%0A%0Aif (reportResults) %7B%0A%09console.log('YES --reportResults to couchDB.');%0A%7D else %7B%0A%09console.log('NOT --reportResults to couchDB.');%0A%7D%0Aif (uninstallAfter) %7B%0A%09console.log('YES --uninstall-after each package is tested');%0A%7D else %7B%0A%09console.log('NOT --uninstall-after each package is tested');%0A%7D%0A%0Aslave.ready(function(run) %7B%0A%09var s = run(module, %7B%0A%09%09reportResults: reportResults,%0A%09%09uninstallAfter:uninstallAfter%0A%09%7D
 );%0A%0A
@@ -728,17 +728,17 @@
 ole.log(
-%22
+'
 Running 
@@ -750,17 +750,17 @@
 NodeJS: 
-%22
+'
  + proce
@@ -787,18 +787,18 @@
 t = 
-%22%22
+''
 , err = 
 %22%22;%0A
@@ -797,10 +797,10 @@
 r = 
-%22%22
+''
 ;%0A%0A%09
@@ -808,13 +808,13 @@
 .on(
-%22out%22
+'out'
 , fu
@@ -849,33 +849,33 @@
 ;%0A%09%09console.log(
-%22
+'
 %5Btest.js:out%5D:%5Cn
@@ -874,17 +874,17 @@
 :out%5D:%5Cn
-%22
+'
 .green +
@@ -907,13 +907,13 @@
 .on(
-%22err%22
+'err'
 , fu
@@ -961,17 +961,17 @@
 ole.log(
-%22
+'
 %5Btest.js
@@ -978,17 +978,17 @@
 :err%5D:%5Cn
-%22
+'
 .red + e
@@ -1014,17 +1014,17 @@
 .on(
-%22
+'
 complete
 %22, f
@@ -1019,17 +1019,17 @@
 complete
-%22
+'
 , functi
@@ -1055,33 +1055,33 @@
 s.writeFile(
-%22
+'
 ./logs/
-%22
+'
  + module + 
@@ -1084,17 +1084,17 @@
 e + 
-%22
+'
 .out.log
 %22, o
@@ -1089,17 +1089,17 @@
 .out.log
-%22
+'
 , out);%0A
@@ -1117,17 +1117,17 @@
 ile(
-%22
+'
 ./logs/
-%22
+'
  + m
@@ -1138,17 +1138,17 @@
 e + 
-%22
+'
 .err.log
 %22, e
@@ -1143,17 +1143,17 @@
 .err.log
-%22
+'
 , err);%0A
@@ -1166,17 +1166,17 @@
 ole.log(
-%22
+'
 test com
@@ -1196,9 +1196,9 @@
 ode:
-%22
+'
 , co

improve run-test CLI options