aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/lib/htmltest.py
blob: 35f524c8d55c6c1a09ed9dcb699d259948a99cda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import xml.etree.ElementTree as ET

def html_tree_from_env():
    # return parsed HTML content as an ET from an HTML_PATH file
    html_filename = os.environ['HTML_PATH']
    html_filename += '.html'
    print('html_filename: %r' % html_filename)
    return ET.parse(html_filename)

XHTML = 'http://www.w3.org/1999/xhtml'
SVG   = 'http://www.w3.org/2000/svg'
ns = {'xhtml': XHTML,
      'svg'  : SVG}

def make_tag(local_name):
    return f'{{{XHTML}}}' + local_name

def assert_tag(element, expected):
    assert element.tag == make_tag(expected)

def assert_class(element, expected):
    assert element.attrib['class'] == expected

def assert_quoted_line(tr, expected_line_num, expected_src):
    """Verify that tr is a line of quoted source."""
    tds = tr.findall('xhtml:td', ns)
    assert len(tds) == 3
    assert_class(tds[0], 'linenum')
    assert tds[0].text == expected_line_num
    assert_class(tds[1], 'left-margin')
    assert tds[1].text == ' '
    assert_class(tds[2], 'source')
    assert tds[2].text == expected_src

def assert_annotation_line(tr, expected_src,
                           expected_line_num='     ',
                           expected_left_margin=' '):
    """Verify that tr is an annotation line."""
    tds = tr.findall('xhtml:td', ns)
    assert len(tds) == 3
    assert_class(tds[0], 'linenum')
    assert tds[0].text == expected_line_num
    assert_class(tds[1], 'left-margin')
    assert tds[1].text == expected_left_margin
    assert_class(tds[2], 'annotation')
    assert tds[2].text == expected_src

def assert_frame(frame, expected_fnname):
    """
    Assert that frame is of class 'stack-frame'
    and has a child showing the expected fnname.
    """
    assert_class(frame, 'stack-frame')
    funcname = frame[0]
    assert_class(funcname, 'frame-funcname')
    span = funcname[0]
    assert_tag(span, 'span')
    assert span.text == expected_fnname

def assert_event_range_with_margin(element):
    """
    Verify that "element" is an event-range-with-margin
    """
    assert_tag(element, 'table')
    assert_class(element, 'event-range-with-margin')
    tr = element.find('xhtml:tr', ns)
    assert tr is not None
    td = tr.find('xhtml:td', ns)
    assert_class(td, 'event-range')

    events_hdr = td.find('xhtml:div', ns)
    assert_class(events_hdr, 'events-hdr')

    #...etc

def get_diag_by_index(html_tree, index):
    root = html_tree.getroot ()
    assert root.tag == make_tag('html')

    body = root.find('xhtml:body', ns)
    assert body is not None

    diag_list = body.find('xhtml:div', ns)
    assert diag_list is not None
    assert_class(diag_list, 'gcc-diagnostic-list')

    diag = diag_list.find(f"xhtml:div[@id='gcc-diag-{index}']", ns)
    return diag

def get_message_within_diag(diag_element):
    msg = diag_element.find("xhtml:div[@class='gcc-message']", ns)
    return msg

def get_locus_within_diag(diag_element):
    src = diag_element.find('xhtml:table', ns)
    assert_class(src, 'locus')
    return src