1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch# Copyright 2013 the V8 project authors. All rights reserved.
2b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# Redistribution and use in source and binary forms, with or without
3b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# modification, are permitted provided that the following conditions are
4b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# met:
5b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#
6b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#     * Redistributions of source code must retain the above copyright
7b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       notice, this list of conditions and the following disclaimer.
8b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#     * Redistributions in binary form must reproduce the above
9b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       copyright notice, this list of conditions and the following
10b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       disclaimer in the documentation and/or other materials provided
11b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       with the distribution.
12b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#     * Neither the name of Google Inc. nor the names of its
13b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       contributors may be used to endorse or promote products derived
14b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#       from this software without specific prior written permission.
15b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#
16b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochimport xml.etree.ElementTree as xml
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochclass JUnitTestOutput:
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  def __init__(self, test_suite_name):
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    self.root = xml.Element("testsuite")
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    self.root.attrib["name"] = test_suite_name
36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  def HasRunTest(self, test_name, test_duration, test_failure):
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    testCaseElement = xml.Element("testcase")
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    testCaseElement.attrib["name"] = " ".join(test_name)
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    testCaseElement.attrib["time"] = str(round(test_duration, 3))
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    if len(test_failure):
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      failureElement = xml.Element("failure")
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      failureElement.text = test_failure
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      testCaseElement.append(failureElement)
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    self.root.append(testCaseElement)
46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  def FinishAndWrite(self, file):
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    xml.ElementTree(self.root).write(file, "UTF-8")
49