diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/plugin')
9 files changed, 354 insertions, 29 deletions
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.c index 2499e8d..df57b25 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=experimental-html" } */ -/* { dg-additional-options "-fdiagnostics-show-caret" } */ +/* { dg-options "-fdiagnostics-set-output=experimental-html:javascript=no" } */ +/* { dg-additional-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */ extern char *gets (char *s); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.py index e475e95..b4c75b2 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-metadata-html.py @@ -8,12 +8,6 @@ import pytest def html_tree(): return html_tree_from_env() -XHTML = 'http://www.w3.org/1999/xhtml' -ns = {'xhtml': XHTML} - -def make_tag(local_name): - return f'{{{XHTML}}}' + local_name - def test_metadata(html_tree): root = html_tree.getroot () assert root.tag == make_tag('html') @@ -48,11 +42,21 @@ def test_metadata(html_tree): assert metadata[1][0].text == 'STR34-C' assert metadata[1][0].tail == ']' - src = diag.find('xhtml:pre', ns) - assert src.attrib['class'] == 'gcc-annotated-source' - assert src.text == ( - ' gets (buf);\n' - ' ^~~~~~~~~~\n') + src = diag.find('xhtml:table', ns) + assert src.attrib['class'] == 'locus' + + tbody = src.find('xhtml:tbody', ns) + assert tbody.attrib['class'] == 'line-span' + + rows = tbody.findall('xhtml:tr', ns) + + quoted_src_tr = rows[0] + assert_quoted_line(quoted_src_tr, + ' 10', ' gets (buf);') + + annotation_tr = rows[1] + assert_annotation_line(annotation_tr, + ' ^~~~~~~~~~') # For reference, here's the generated HTML: """ @@ -60,8 +64,13 @@ def test_metadata(html_tree): <div class="gcc-diagnostic-list"> <div class="gcc-diagnostic"> <span class="gcc-message">never use '<span class="gcc-quoted-text">gets</span>'</span> - <span class="gcc-metadata"><span class="gcc-metadata-item">[<a href="https://cwe.mitre.org/data/definitions/242.html">CWE-242</a>]</span><span class="gcc-metadata-item">[<a href="https://example.com/">STR34-C</a>]</span></span> - ...etc... + <span class="gcc-metadata"><span class="gcc-metadata-item">[<a href="https://cwe.mitre.org/data/definitions/242.html">CWE-242</a>]</span><span class="gcc-metadata-item">[<a href="https://example.com/">STR34-C</a>]</span></span><table class="locus"> +<tbody class="line-span"> +<tr><td class="linenum"> 10</td> <td class="source"> gets (buf);</td></tr> +<tr><td class="linenum"/><td class="annotation"> ^~~~~~~~~~</td></tr> +</tbody> +</table> + </div> </div> </body> diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c index 26605f7..dab9c38 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-add-output=experimental-html" } */ +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-add-output=experimental-html:javascript=no" } */ #include <stddef.h> #include <stdlib.h> diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.py index c212e49..59bee24 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-2.py @@ -8,12 +8,6 @@ import pytest def html_tree(): return html_tree_from_env() -XHTML = 'http://www.w3.org/1999/xhtml' -ns = {'xhtml': XHTML} - -def make_tag(local_name): - return f'{{{XHTML}}}' + local_name - def test_paths(html_tree): root = html_tree.getroot () assert root.tag == make_tag('html') @@ -29,7 +23,19 @@ def test_paths(html_tree): assert diag is not None assert diag.attrib['class'] == 'gcc-diagnostic' - pre = diag.findall('xhtml:pre', ns) - assert pre[0].attrib['class'] == 'gcc-annotated-source' - assert pre[1].attrib['class'] == 'gcc-execution-path' - assert pre[1].text.startswith(" 'make_a_list_of_random_ints_badly': events 1-3") + event_ranges = diag.find('xhtml:div', ns) + assert_class(event_ranges, 'event-ranges') + + frame_margin = event_ranges.find('xhtml:table', ns) + assert_class(frame_margin, 'stack-frame-with-margin') + + tr = frame_margin.find('xhtml:tr', ns) + assert tr is not None + tds = tr.findall('xhtml:td', ns) + assert len(tds) == 2 + + assert_class(tds[0], 'interprocmargin') + + test_frame = tds[1] + assert_frame(test_frame, 'make_a_list_of_random_ints_badly') + assert_event_range_with_margin(test_frame[1]) diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.c index 847b6d4..7eb0c50 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */ +/* { dg-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-add-output=experimental-html:javascript=no" } */ /* { dg-enable-nn-line-numbers "" } */ #include <stdio.h> @@ -82,3 +82,7 @@ void test (void) | | (9) calling 'fprintf' | { dg-end-multiline-output "" } */ + +/* Use a Python script to verify various properties about the generated + HTML file: + { dg-final { run-html-pytest diagnostic-test-paths-4.c "diagnostic-test-paths-4.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.py new file mode 100644 index 0000000..e738729 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.py @@ -0,0 +1,190 @@ +# Verify that interprocedural execution paths work in HTML output. + +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +def test_paths(html_tree): + diag = get_diag_by_index(html_tree, 0) + src = get_locus_within_diag (diag) + + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + + rows = tbody.findall('xhtml:tr', ns) + + quoted_src_tr = rows[0] + assert_quoted_line(quoted_src_tr, + ' 13', ' fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to \'fprintf\' from within signal handler" } */') + + annotation_tr = rows[1] + assert_annotation_line(annotation_tr, + ' ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') + + event_ranges = diag.find('xhtml:div', ns) + assert_class(event_ranges, 'event-ranges') + + test_frame_margin = event_ranges.find('xhtml:table', ns) + assert_class(test_frame_margin, 'stack-frame-with-margin') + + tr = test_frame_margin.find('xhtml:tr', ns) + assert tr is not None + tds = tr.findall('xhtml:td', ns) + assert len(tds) == 2 + + assert_class(tds[0], 'interprocmargin') + + test_frame = tds[1] + assert_frame(test_frame, 'test') + assert_event_range_with_margin(test_frame[1]) + +# For reference, generated HTML looks like this: +""" +<table class="stack-frame-with-margin"><tr> + <td class="interprocmargin" style="padding-left: 100px"/> + <td class="stack-frame"> +<div class="frame-funcname"><span>test</span></div><table class="event-range-with-margin"><tr> + <td class="event-range"> + <div class="events-hdr"><span class="funcname">test</span>: <span class="event-ids">events 1-2</span></div> +<table class="locus"> +<tbody class="line-span"> +<tr><td class="linenum"> 27</td> <td class="source">{</td></tr> +<tr><td class="linenum"/><td class="annotation">^</td></tr> +<tr><td class="linenum"/><td class="annotation">|</td></tr> +<tr><td class="linenum"/><td class="annotation">(1) entering 'test'</td></tr> +<tr><td class="linenum"> 28</td> <td class="source"> register_handler ();</td></tr> +<tr><td class="linenum"/><td class="annotation"> ~~~~~~~~~~~~~~~~~~~</td></tr> +<tr><td class="linenum"/><td class="annotation"> |</td></tr> +<tr><td class="linenum"/><td class="annotation"> (2) calling 'register_handler'</td></tr> +</tbody> +</table> +</td></tr></table> +<div class="between-ranges-call"> + <svg height="30" width="150"> + <defs> + <marker id="arrowhead" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto" stroke="#0088ce" fill="#0088ce"> + <polygon points="0 0, 10 3.5, 0 7"/> + </marker> + </defs> + <polyline points="20,0 20,10 120,10 120,20" + style="fill:none;stroke: #0088ce" + marker-end="url(#arrowhead)"/> + </svg> +</div> + +<table class="stack-frame-with-margin"><tr> + <td class="interprocmargin" style="padding-left: 100px"/> + <td class="stack-frame"> +<div class="frame-funcname"><span>register_handler</span></div><table class="event-range-with-margin"><tr> + <td class="event-range"> + <div class="events-hdr"><span class="funcname">register_handler</span>: <span class="event-ids">events 3-4</span></div> +<table class="locus"> +<tbody class="line-span"> +<tr><td class="linenum"> 22</td> <td class="source">{</td></tr> +<tr><td class="linenum"/><td class="annotation">^</td></tr> +<tr><td class="linenum"/><td class="annotation">|</td></tr> +<tr><td class="linenum"/><td class="annotation">(3) entering 'register_handler'</td></tr> +<tr><td class="linenum"> 23</td> <td class="source"> signal(SIGINT, int_handler);</td></tr> +<tr><td class="linenum"/><td class="annotation"> ~~~~~~~~~~~~~~~~~~~~~~~~~~~</td></tr> +<tr><td class="linenum"/><td class="annotation"> |</td></tr> +<tr><td class="linenum"/><td class="annotation"> (4) registering 'int_handler' as signal handler</td></tr> +</tbody> +</table> +</td></tr></table> +</td></tr></table> +</td></tr></table> +<div class="between-ranges-return"> + <svg height="30" width="250"> + <defs> + <marker id="arrowhead" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto" stroke="#0088ce" fill="#0088ce"> + <polygon points="0 0, 10 3.5, 0 7"/> + </marker> + </defs> + <polyline points="220,0 220,10 20,10 20,20" + style="fill:none;stroke: #0088ce" + marker-end="url(#arrowhead)"/> + </svg> +</div> + +<table class="event-range-with-margin"><tr> + <td class="event-range"> + <div class="events-hdr"><span class="event-ids">event 5</span></div> + (5): later on, when the signal is delivered to the process +</td></tr></table> +<div class="between-ranges-call"> + <svg height="30" width="150"> + <defs> + <marker id="arrowhead" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto" stroke="#0088ce" fill="#0088ce"> + <polygon points="0 0, 10 3.5, 0 7"/> + </marker> + </defs> + <polyline points="20,0 20,10 120,10 120,20" + style="fill:none;stroke: #0088ce" + marker-end="url(#arrowhead)"/> + </svg> +</div> + +<table class="stack-frame-with-margin"><tr> + <td class="interprocmargin" style="padding-left: 100px"/> + <td class="stack-frame"> +<div class="frame-funcname"><span>int_handler</span></div><table class="event-range-with-margin"><tr> + <td class="event-range"> + <div class="events-hdr"><span class="funcname">int_handler</span>: <span class="event-ids">events 6-7</span></div> +<table class="locus"> +<tbody class="line-span"> +<tr><td class="linenum"> 17</td> <td class="source">{</td></tr> +<tr><td class="linenum"/><td class="annotation">^</td></tr> +<tr><td class="linenum"/><td class="annotation">|</td></tr> +<tr><td class="linenum"/><td class="annotation">(6) entering 'int_handler'</td></tr> +<tr><td class="linenum"> 18</td> <td class="source"> custom_logger("got signal");</td></tr> +<tr><td class="linenum"/><td class="annotation"> ~~~~~~~~~~~~~~~~~~~~~~~~~~~</td></tr> +<tr><td class="linenum"/><td class="annotation"> |</td></tr> +<tr><td class="linenum"/><td class="annotation"> (7) calling 'custom_logger'</td></tr> +</tbody> +</table> +</td></tr></table> +<div class="between-ranges-call"> + <svg height="30" width="150"> + <defs> + <marker id="arrowhead" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto" stroke="#0088ce" fill="#0088ce"> + <polygon points="0 0, 10 3.5, 0 7"/> + </marker> + </defs> + <polyline points="20,0 20,10 120,10 120,20" + style="fill:none;stroke: #0088ce" + marker-end="url(#arrowhead)"/> + </svg> +</div> + +<table class="stack-frame-with-margin"><tr> + <td class="interprocmargin" style="padding-left: 100px"/> + <td class="stack-frame"> +<div class="frame-funcname"><span>custom_logger</span></div><table class="event-range-with-margin"><tr> + <td class="event-range"> + <div class="events-hdr"><span class="funcname">custom_logger</span>: <span class="event-ids">events 8-9</span></div> +<table class="locus"> +<tbody class="line-span"> +<tr><td class="linenum"> 12</td> <td class="source">{</td></tr> +<tr><td class="linenum"/><td class="annotation">^</td></tr> +<tr><td class="linenum"/><td class="annotation">|</td></tr> +<tr><td class="linenum"/><td class="annotation">(8) entering 'custom_logger'</td></tr> +<tr><td class="linenum"> 13</td> <td class="source"> fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */</td></tr> +<tr><td class="linenum"/><td class="annotation"> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</td></tr> +<tr><td class="linenum"/><td class="annotation"> |</td></tr> +<tr><td class="linenum"/><td class="annotation"> (9) calling 'fprintf'</td></tr> +</tbody> +</table> +</td></tr></table> +</td></tr></table> +</td></tr></table> + +</div> + """ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c index 1e8f73b..e81856a 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" } */ +/* { dg-options "-O -fdiagnostics-show-caret -fdiagnostics-show-line-numbers -fdiagnostics-add-output=experimental-html:javascript=no" } */ /* This is a collection of unittests for diagnostic_show_locus; see the overview in diagnostic_plugin_test_show_locus.c. @@ -118,3 +118,7 @@ void test_fixit_insert_newline (void) { dg-end-multiline-output "" } */ #endif } + +/* Use a Python script to verify various properties about the generated + HTML file: + { dg-final { run-html-pytest diagnostic-test-show-locus-bw-line-numbers.c "diagnostic-test-show-locus.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py new file mode 100644 index 0000000..d963b29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py @@ -0,0 +1,111 @@ +# Verify that diagnostic-show-locus.cc works with HTML output. + +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +#def get_tr_within_thead(thead, idx) + +def get_ruler_text(thead, idx): + trs = thead.findall('xhtml:tr', ns) + tr = trs[idx] + tds = tr.findall('xhtml:td', ns) + assert len(tds) == 3 + assert_class(tds[2], 'ruler') + return tds[2].text + +def test_very_wide_line(html_tree): + diag = get_diag_by_index(html_tree, 2) + src = get_locus_within_diag(diag) + + # Check ruler + thead = src.find('xhtml:thead', ns) + assert_class(thead, 'ruler') + trs = thead.findall('xhtml:tr', ns) + assert len(trs) == 3 + + assert get_ruler_text(thead, 0) == ' 0 0 0 0 0 1 1 ' + assert get_ruler_text(thead, 1) == ' 5 6 7 8 9 0 1 ' + assert get_ruler_text(thead, 2) == '34567890123456789012345678901234567890123456789012345678901234567890123' + + # Check quoted source + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + trs = tbody.findall('xhtml:tr', ns) + assert len(trs) == 5 + assert_quoted_line(trs[0], ' 43', ' float f = foo * bar; /* { dg-warning "95: test" } */') + assert_annotation_line(trs[1], ' ~~~~^~~~~') + assert_annotation_line(trs[2], ' |') + assert_annotation_line(trs[3], ' label 0') + assert_annotation_line(trs[4], ' bar * foo') + +def test_fixit_insert(html_tree): + diag = get_diag_by_index(html_tree, 3) + msg = get_message_within_diag(diag) + assert msg.text == 'example of insertion hints' + + src = get_locus_within_diag(diag) + + # Check quoted source + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + trs = tbody.findall('xhtml:tr', ns) + assert len(trs) == 3 + assert_quoted_line(trs[0], ' 63', ' int a[2][2] = { 0, 1 , 2, 3 }; /* { dg-warning "insertion hints" } */') + assert_annotation_line(trs[1], ' ^~~~') + assert_annotation_line(trs[2], ' { }') + +def test_fixit_remove(html_tree): + diag = get_diag_by_index(html_tree, 4) + msg = get_message_within_diag(diag) + assert msg.text == 'example of a removal hint' + + src = get_locus_within_diag(diag) + + # Check quoted source + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + trs = tbody.findall('xhtml:tr', ns) + assert len(trs) == 3 + assert_quoted_line(trs[0], ' 77', ' int a;; /* { dg-warning "example of a removal hint" } */') + assert_annotation_line(trs[1], ' ^') + assert_annotation_line(trs[2], ' -') + +def test_fixit_replace(html_tree): + diag = get_diag_by_index(html_tree, 5) + msg = get_message_within_diag(diag) + assert msg.text == 'example of a replacement hint' + + src = get_locus_within_diag(diag) + + # Check quoted source + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + trs = tbody.findall('xhtml:tr', ns) + assert len(trs) == 3 + assert_quoted_line(trs[0], ' 91', ' gtk_widget_showall (dlg); /* { dg-warning "example of a replacement hint" } */') + assert_annotation_line(trs[1], ' ^~~~~~~~~~~~~~~~~~') + assert_annotation_line(trs[2], ' gtk_widget_show_all') + +def test_fixit_insert_newline(html_tree): + diag = get_diag_by_index(html_tree, 6) + msg = get_message_within_diag(diag) + assert msg.text == 'example of newline insertion hint' + + src = get_locus_within_diag(diag) + + # Check quoted source + tbody = src.find('xhtml:tbody', ns) + assert_class(tbody, 'line-span') + trs = tbody.findall('xhtml:tr', ns) + assert len(trs) == 4 + assert_quoted_line(trs[0], ' 109', ' x = a;') + assert_annotation_line(trs[1], ' break;', + expected_line_num=' +++', + expected_left_margin='+') + assert_quoted_line(trs[2], ' 110', " case 'b': /* { dg-warning \"newline insertion\" } */") + assert_annotation_line(trs[3], ' ^~~~~~~~') diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc index 5ec3418..4ade232 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc @@ -176,9 +176,10 @@ test_diagnostic_text_starter (diagnostic_text_output_format &text_output, void test_diagnostic_start_span_fn (const diagnostic_location_print_policy &, - pretty_printer *pp, + to_text &sink, expanded_location) { + pretty_printer *pp = get_printer (sink); pp_string (pp, "START_SPAN_FN: "); pp_newline (pp); } |