new TravisReporter

This commit is contained in:
Dima Granetchi
2014-11-16 06:10:56 +02:00
parent ef41a6f704
commit d0460a697c
+109 -13
View File
@@ -1,8 +1,12 @@
package buddy;
import buddy.BuddySuite.Suite;
import buddy.BuddySuite.Spec;
import buddy.reporting.Reporter;
import buddy.reporting.ConsoleReporter;
import buddy.BuddySuite.TestStatus;
import promhx.Promise;
import promhx.Deferred;
using Lambda;
using StringTools;
@@ -23,29 +27,121 @@ typedef Sys = Flash;
* ...
* @author deep <system.grand@gmail.com>
*/
class TravisReporter extends ConsoleReporter
class TravisReporter implements Reporter
{
override public function done(suites:Iterable<Suite>)
#if php
var cli : Bool;
#end
public function new() {}
public function start()
{
var res = super.done(suites);
#if php
cli = (untyped __call__("php_sapi_name")) == 'cli';
if(!cli) Sys.println("<pre>");
#end
function successSuite(s : Suite):Bool {
return resolveImmediately(true);
}
public function progress(spec : Spec)
{
Sys.print(switch(spec.status) {
case TestStatus.Failed: "X";
case TestStatus.Passed: ".";
case TestStatus.Pending: "P";
case TestStatus.Unknown: "?";
});
return resolveImmediately(spec);
}
public function done(suites:Iterable<Suite>)
{
Sys.println("");
var total = 0;
var failures = 0;
var pending = 0;
var countTests : Suite -> Void = null;
var printTests : Suite -> Int -> Void = null;
countTests = function(s : Suite) {
for (sp in s.steps) switch sp {
case TSpec(sp) if (sp.status == TestStatus.Failed): return false;
case TSuite(s) if (!successSuite(s)): return false;
case _:
case TSpec(sp):
total++;
if (sp.status == TestStatus.Failed) failures++;
else if (sp.status == TestStatus.Pending) pending++;
case TSuite(s):
countTests(s);
}
return true;
};
var success = suites.foreach(successSuite);
suites.iter(countTests);
printTests = function(s : Suite, indentLevel : Int)
{
var print = function(str : String) Sys.println(str.lpad(" ", str.length + indentLevel * 2));
print(s.name);
for (step in s.steps) switch step
{
case TSpec(sp):
if (sp.status == TestStatus.Failed)
{
print(" " + sp.description + " (FAILED: " + sp.error + ")");
printTraces(sp);
if (sp.stack == null || sp.stack.length == 0) continue;
// Display the exception stack
for (s in sp.stack) switch s {
case FilePos(_, file, line) if (file.indexOf("buddy/internal/") != 0):
print(' @ $file:$line');
case _:
}
}
else
{
print(" " + sp.description + " (" + sp.status + ")");
printTraces(sp);
}
case TSuite(s):
printTests(s, indentLevel+1);
}
};
suites.iter(printTests.bind(_, 0));
Sys.println('$total specs, $failures failures, $pending pending');
Sys.println('success: ${failures <= 0}'); // #if travis
Sys.println('success: ${success}');
return res;
#if php
if(!cli) Sys.println("</pre>");
#end
return resolveImmediately(suites);
}
function printTraces(spec : Spec)
{
for (t in spec.traces)
Sys.println(" " + t);
}
private function resolveImmediately<T>(o : T) : Promise<T>
{
var def = new Deferred<T>();
var pr = def.promise();
def.resolve(o);
return pr;
}
}
#if js
#if js // && travis)
class Js
{