Last active
August 29, 2015 14:02
-
-
Save hron84/ad235d959d8c63b2fcc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import groovy.util.XmlParser | |
def dasher = { Integer n, String c -> def ret = ""; for(i = 0; i < n; i++) ret += c ; return ret } | |
BufferedReader STDIN = new BufferedReader(new InputStreamReader(System.in)) | |
def clear = { | |
if(System.getProperty("os.name").substring(0,3).toLowerCase().equals("win")) { | |
// Ugly solution, windows is fucked up | |
print dasher(25, "\n") | |
} else { | |
print "\033[2J\033[1;1H" | |
} | |
} | |
def dash = dasher(60, '-') | |
def processTestSuite = { report -> | |
def testdetails = [] | |
def total = [email protected]() | |
def fails = [email protected]() | |
def errors = [email protected]() | |
def success = total - fails - errors | |
report.testcase.each({ | |
name = [it.@classname, it.@name] | |
name.removeAll { it == null } | |
realname = name.join('#') | |
failed = it?.children()*.name().indexOf('failure') >= 0 | |
error = it?.children()*.name().indexOf('error') >= 0 | |
tag = error ? "ERROR" : ( failed ? "FAIL" : "OK") | |
result = error ? it.error.text() : it.failure.text() | |
time = it.@time | |
entry = [ 'name': realname, 'tag': tag, 'result': result, 'time': time] | |
testdetails << entry | |
}) | |
while(true) { | |
clear() | |
print "Testsuite: ${report.@name}" | |
if(report.@hostname && [email protected]()) | |
print " on ${report.@hostname}" | |
if(report.@timestamp && [email protected]()) | |
print " at ${report.@timestamp}" | |
println "\n" // TWO newline character! | |
print "Total time: ${report.@time}s" | |
println " ${success} / ${total} succeeded, ${fails} failed, ${errors} error" | |
println dash | |
testdetails.eachWithIndex { test, i -> | |
m = test['name'].size() > 40 ? 40 : test['name'].size() | |
println " [${i + 1}] ${sprintf("%-40s", test['name'].substring(0, m))} [${sprintf("%-5s", test['tag'])}]" | |
} | |
println " [D] Dump suite properties" | |
println "" | |
println " [Q] Exit" | |
println dash | |
print " * Select testcase to see details (it's available only for unsuccessful testcases) : " | |
rep = STDIN.readLine().trim() | |
if(rep.toLowerCase().equals('q')) { | |
break; | |
} | |
if(rep.toLowerCase().equals("d")) { | |
def testprops = [:] | |
report.properties.property.each { testprops[it.@name] = it.@value } | |
testprops.sort { a,b -> a.key <=> b.key }.each { key, value -> | |
if(key.size() + value.size() + 7 < 40) { | |
println " [${key}] => ${value}" | |
} else { | |
println " [${key}] =>" | |
println " ${value}" | |
} | |
} | |
println "" | |
println dash | |
println " * Press ENTER to continue" | |
STDIN.readLine() | |
continue | |
} | |
try { | |
idx = rep.toInteger() | |
} catch(NumberFormatException ex) { idx = 0 } | |
if(idx < 1 || idx > testdetails.size()) { | |
println " ! Invalid ID." | |
sleep(500, {true}) | |
continue | |
} | |
println dash | |
tcase = testdetails[idx - 1] | |
println "Testcase: ${tcase['name']}" | |
println "Run time: ${tcase['time']}s" | |
println "Result: ${tcase['tag']}" | |
println "" | |
tcase['result'].eachLine { println " ${it}" } | |
println dash | |
println " * Press ENTER to continue" | |
STDIN.readLine() | |
} | |
} | |
def file = null | |
try { | |
file = this.args[0] | |
} catch(ArrayIndexOutOfBoundsException) { | |
// pass | |
} | |
//println file | |
if(file == null || file == '--help') { | |
println "Usage: ${getClass().protectionDomain.codeSource.location.path} TEST-junit.xml" | |
System.exit(1) | |
} | |
def f = new File(file) | |
if(!f.exists()) { | |
println "junit-dumper: ${file}: File not found" | |
System.exit(1) | |
} | |
report = new XmlParser().parse(new FileInputStream(file)) | |
if(report.name() == 'testsuite') { | |
processTestSuite(report) | |
} else { | |
suites = report.testsuite.collect { it.@name } | |
while(true) { | |
clear() | |
suites.eachWithIndex { suite, i -> | |
m = suite.size() > 40 ? 40 : suite.size() | |
println " [${i + 1}] ${sprintf("%-40s", suite.substring(0, m))}" | |
} | |
println "" | |
println " [Q] Exit" | |
println dash | |
print " * Select testsuite to see testcases : " | |
rep = STDIN.readLine().trim() | |
if(rep.toLowerCase().equals('q')) { | |
break; | |
} | |
try { | |
idx = rep.toInteger() | |
} catch(NumberFormatException ex) { idx = 0 } | |
if(idx < 1 || idx > suites.size()) { | |
println " ! Invalid ID." | |
sleep(500, {true}) | |
continue | |
} | |
processTestSuite(report.testsuite[idx - 1]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment