class ParseOutput
@testFlag
@xmlOut
@arrayList
@totalTests
@classIndex
def setXmlOutput()
@xmlOut = true
end
def writeXmlOuput()
output = File.open("report.xml", "w")
output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@arrayList.each do |item|
output << item << "\n"
end
output << "</testsuite>\n"
end
def testSuiteVerify(testSuiteName)
if @testFlag == false
@testFlag = true;
testName = testSuiteName.split("/")
baseName = testName[testName.size - 1].split(".")
@testSuite = "test." + baseName[0]
printf "New Test: %s\n", @testSuite
end
end
def testPassed(array)
lastItem = array.length - 1
testName = array[lastItem - 1]
testSuiteVerify(array[@className])
printf "%-40s PASS\n", testName
if @xmlOut == true
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\"/>"
end
end
def testIgnored(array)
lastItem = array.length - 1
testName = array[lastItem - 2]
reason = array[lastItem].chomp
testSuiteVerify(array[@className])
printf "%-40s IGNORED\n", testName
if @xmlOut == true
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
@arrayList.push " <skipped type=\"TEST IGNORED\"> " + reason + " </skipped>"
@arrayList.push " </testcase>"
end
end
def testFailed(array)
lastItem = array.length - 1
testName = array[lastItem - 2]
reason = array[lastItem].chomp + " at line: " + array[lastItem - 3]
testSuiteVerify(array[@className])
printf "%-40s FAILED\n", testName
if @xmlOut == true
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
@arrayList.push " <failure type=\"ASSERT FAILED\"> " + reason + " </failure>"
@arrayList.push " </testcase>"
end
end
def detectOS()
myOS = RUBY_PLATFORM.split("-")
if myOS.size == 2
if myOS[1] == "mingw32"
@className = 1
else
@className = 0
end
else
@className = 0
end
end
def process(name)
@testFlag = false
@arrayList = Array.new
detectOS()
puts "Parsing file: " + name
testPass = 0
testFail = 0
testIgnore = 0
puts ""
puts "=================== RESULTS ====================="
puts ""
File.open(name).each do |line|
lineArray = line.split(":")
lineSize = lineArray.size
if lineSize >= 4
if line.include? ":PASS"
testPassed(lineArray)
testPass += 1
elsif line.include? ":FAIL:"
testFailed(lineArray)
testFail += 1
elsif line.include? ":IGNORE:"
testIgnored(lineArray)
testIgnore += 1
else
@testFlag = false
end
else
@testFlag = false
end
end
puts ""
puts "=================== SUMMARY ====================="
puts ""
puts "Tests Passed : " + testPass.to_s
puts "Tests Failed : " + testFail.to_s
puts "Tests Ignored : " + testIgnore.to_s
@totalTests = testPass + testFail + testIgnore
if @xmlOut == true
heading = "<testsuite tests=\"" + @totalTests.to_s + "\" failures=\"" + testFail.to_s + "\"" + " skips=\"" + testIgnore.to_s + "\">"
@arrayList.insert(0, heading)
writeXmlOuput()
end
end
end
parseMyFile = ParseOutput.new
if ARGV.size >= 1
ARGV.each do |a|
if a == "-xml"
parseMyFile.setXmlOutput();
else
parseMyFile.process(a)
break
end
end
end