gtester-report: cope with binaries with no test cases

It's possible that a given binary may conditionally decided not to run
any test cases (e.g. since they are all slow but -m=quick is currently
in use) In this case the xml may contain <testbinary> nodes with no
<testcase> children. This was resulting in a divide by zero when
calculating the green → red color interpolation.

https://bugzilla.gnome.org/show_bug.cgi?id=617914
This commit is contained in:
Robert Bragg 2010-05-06 15:46:00 +01:00
parent 7ca2e00054
commit 03b5db4477

View File

@ -268,16 +268,21 @@ class ReportWriter (TreeProcess):
erlink = 'href="javascript:toggle_display (\'ResultTable\', \'tr\', \'b%u_\', \'failed\')"' % self.bcounter erlink = 'href="javascript:toggle_display (\'ResultTable\', \'tr\', \'b%u_\', \'failed\')"' % self.bcounter
if binary.success_cases: if binary.success_cases:
oklink = 'href="javascript:toggle_display (\'ResultTable\', \'tr\', \'b%u_\', \'success\')"' % self.bcounter oklink = 'href="javascript:toggle_display (\'ResultTable\', \'tr\', \'b%u_\', \'success\')"' % self.bcounter
self.oprint ('<a %s>ER</a>\n' % erlink) if real_cases != 0:
self.oprint ('<a %s>OK</a>\n' % oklink) self.oprint ('<a %s>ER</a>\n' % erlink)
self.oprint ('</td>\n') self.oprint ('<a %s>OK</a>\n' % oklink)
perc = binary.success_cases * 100.0 / real_cases self.oprint ('</td>\n')
pcolor = { perc = binary.success_cases * 100.0 / real_cases
100 : 'bgcolor="lightgreen"', pcolor = {
0 : 'bgcolor="red"', 100 : 'bgcolor="lightgreen"',
}.get (int (perc), 'bgcolor="yellow"') 0 : 'bgcolor="red"',
self.oprint ('<td align="right" %s>%.2f%%</td>\n' % (pcolor, perc)) }.get (int (perc), 'bgcolor="yellow"')
self.oprint ('</tr>\n') self.oprint ('<td align="right" %s>%.2f%%</td>\n' % (pcolor, perc))
self.oprint ('</tr>\n')
else:
self.oprint ('Empty\n')
self.oprint ('</td>\n')
self.oprint ('</tr>\n')
for tc in binary.testcases: for tc in binary.testcases:
self.handle_testcase (tc, binary) self.handle_testcase (tc, binary)
def handle_totals (self): def handle_totals (self):