Skip to content

Commit 6d3c427

Browse files
committed
Add test coverage for new gcc.Location functionality
1 parent 4c36443 commit 6d3c427

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2017 David Malcolm <[email protected]>
3+
Copyright 2017 Red Hat, Inc.
4+
5+
This is free software: you can redistribute it and/or modify it
6+
under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see
17+
<http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/* { dg-do compile } */
21+
/* { dg-options "-fdiagnostics-show-caret" } */
22+
23+
int test (int foo, int bar)
24+
{ return foo + bar; }
25+
/* { dg-message "14: compound location" "" { target *-*-* } .-1 } */
26+
/* { dg-begin-multiline-output "" }
27+
{ return foo + bar; }
28+
~~~~^~~~~
29+
{ dg-end-multiline-output "" } */
30+
31+
32+
/*
33+
PEP-7
34+
Local variables:
35+
c-basic-offset: 4
36+
indent-tabs-mode: nil
37+
End:
38+
*/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2017 David Malcolm <[email protected]>
2+
# Copyright 2017 Red Hat, Inc.
3+
#
4+
# This is free software: you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful, but
10+
# WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see
16+
# <http://www.gnu.org/licenses/>.
17+
18+
import sys
19+
20+
import gcc
21+
22+
# Verify that various aspects of gcc.Location work
23+
24+
def on_pass_execution(p, fn):
25+
if p.name == '*warn_function_return':
26+
caret = fn.start.offset_column(13)
27+
start = fn.start.offset_column(9)
28+
finish = fn.start.offset_column(17)
29+
compound = gcc.Location(caret, start, finish)
30+
gcc.inform(compound, "compound location")
31+
assert compound.caret == caret
32+
assert compound.start == start
33+
assert compound.finish == finish
34+
35+
# Wire up our callback:
36+
gcc.register_callback(gcc.PLUGIN_PASS_EXECUTION,
37+
on_pass_execution)
38+

0 commit comments

Comments
 (0)