1 #============================================================
2 # Author: John Theofanopoulos
3 # A simple parser. Takes the output files generated during the build process and
4 # extracts information relating to the tests.
7 # To capture an output file under VS builds use the following:
8 # devenv [build instructions] > Output.txt & type Output.txt
10 # To capture an output file under GCC/Linux builds use the following:
11 # make | tee Output.txt
13 # To use this parser use the following command
14 # ruby parseOutput.rb [options] [file]
15 # options: -xml : produce a JUnit compatible XML file
16 # file : file to scan for results
17 #============================================================
21 # The following flag is set to true when a test is found or false otherwise.
28 # Set the flag to indicate if there will be an XML output file or not
33 # if write our output to XML
35 output = File.open("report.xml", "w")
36 output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
37 @arrayList.each do |item|
38 output << item << "\n"
40 output << "</testsuite>\n"
43 # This function will try and determine when the suite is changed. This is
44 # is the name that gets added to the classname parameter.
45 def testSuiteVerify(testSuiteName)
49 testName = testSuiteName.split("/")
50 # Remove the extension
51 baseName = testName[testName.size - 1].split(".")
52 @testSuite = "test." + baseName[0]
53 printf "New Test: %s\n", @testSuite
58 # Test was flagged as having passed so format the output
60 lastItem = array.length - 1
61 testName = array[lastItem - 1]
62 testSuiteVerify(array[@className])
63 printf "%-40s PASS\n", testName
65 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\"/>"
69 # Test was flagged as being ingored so format the output
70 def testIgnored(array)
71 lastItem = array.length - 1
72 testName = array[lastItem - 2]
73 reason = array[lastItem].chomp
74 testSuiteVerify(array[@className])
75 printf "%-40s IGNORED\n", testName
77 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
78 @arrayList.push " <skipped type=\"TEST IGNORED\"> " + reason + " </skipped>"
79 @arrayList.push " </testcase>"
83 # Test was flagged as having failed so format the line
85 lastItem = array.length - 1
86 testName = array[lastItem - 2]
87 reason = array[lastItem].chomp + " at line: " + array[lastItem - 3]
88 testSuiteVerify(array[@className])
89 printf "%-40s FAILED\n", testName
91 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
92 @arrayList.push " <failure type=\"ASSERT FAILED\"> " + reason + " </failure>"
93 @arrayList.push " </testcase>"
98 # Figure out what OS we are running on. For now we are assuming if it's not Windows it must
101 myOS = RUBY_PLATFORM.split("-")
103 if myOS[1] == "mingw32"
114 # Main function used to parse the file that was captured.
117 @arrayList = Array.new
121 puts "Parsing file: " + name
128 puts "=================== RESULTS ====================="
130 File.open(name).each do |line|
131 # Typical test lines look like this:
132 # <path>/<test_file>.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0
133 # <path>/<test_file>.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented
134 # <path>/<test_file>.c:115:test_tc5100_initCanVoidPtrs:PASS
136 # where path is different on Unix vs Windows devices (Windows leads with a drive letter)
137 lineArray = line.split(":")
138 lineSize = lineArray.size
139 # If we were able to split the line then we can look to see if any of our target words
140 # were found. Case is important.
142 # Determine if this test passed
143 if line.include? ":PASS"
144 testPassed(lineArray)
146 elsif line.include? ":FAIL:"
147 testFailed(lineArray)
149 elsif line.include? ":IGNORE:"
150 testIgnored(lineArray)
152 # If none of the keywords are found there are no more tests for this suite so clear
162 puts "=================== SUMMARY ====================="
164 puts "Tests Passed : " + testPass.to_s
165 puts "Tests Failed : " + testFail.to_s
166 puts "Tests Ignored : " + testIgnore.to_s
167 @totalTests = testPass + testFail + testIgnore
169 heading = "<testsuite tests=\"" + @totalTests.to_s + "\" failures=\"" + testFail.to_s + "\"" + " skips=\"" + testIgnore.to_s + "\">"
170 @arrayList.insert(0, heading)
179 # If the command line has no values in, used a default value of Output.txt
180 parseMyFile = ParseOutput.new
185 parseMyFile.setXmlOutput();
187 parseMyFile.process(a)