Skip to content

Commit 2073502

Browse files
author
Viviane Garèse
committed
Attach violations to last location
All violations were always attached to the first line of the statement or decision it is relative to. For report formats displaying violations in the source code, whenever a statement or decision spaned multiple lines it was "cut" by the violations as they were shown directly under the first line. To improve readability, violations are now attached to the last line of the statement or decision so they can be displayed after the last line. This also has the added bonus of allowing the user to select the text of the statement or decision with no hindrance from the violations.
1 parent c5153c4 commit 2073502

File tree

6 files changed

+182
-34
lines changed

6 files changed

+182
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(.|\n)*
2+
21% of 19 lines covered
3+
67% statement coverage \(6 out of 9\)
4+
50% decision coverage \(1 out of 2\)
5+
20% MC\/DC coverage \(1 out of 5\)
6+
7+
Coverage level: stmt\+mcdc
8+
1 \.: procedure Main
9+
2 \.: is
10+
3 \+: T : Boolean := True;
11+
4 \+: F : Boolean := False;
12+
5 \.:
13+
6 \.: function Concat \(S1, S2, S3: String\) return String is
14+
7 \.: begin
15+
8 -: return S1 & S2 & S3;
16+
statement "return S1\.\.\." at 8:9 not executed
17+
9 \.: end Concat;
18+
10 \.:
19+
11 \.: procedure Test \(B : Boolean\) is
20+
12 \.: begin
21+
13 !: if B
22+
14 !: and then
23+
15 !: \(T
24+
16 !: or else F\)
25+
condition "T" at 15:18 has no independent influence pair, MC/DC not achieved
26+
condition "F" at 16:25 has no independent influence pair, MC/DC not achieved
27+
17 \.: then
28+
18 !: if F
29+
19 !: or else
30+
20 !: F
31+
decision "F\.\.\." at 18:16 outcome TRUE never exercised
32+
21 \.: then
33+
22 \.: declare
34+
23 -: Dummy : String := Concat
35+
24 -: \(
36+
25 -: "B",
37+
26 -: "C",
38+
27 -: "D"
39+
28 -: \);
40+
statement "Dummy : S\.\.\." at 23:21 not executed
41+
29 \.: begin
42+
30 -: null;
43+
statement "null;" at 30:21 not executed
44+
31 \.: end;
45+
32 \.: end if;
46+
33 \.: end if;
47+
34 \.: end Test;
48+
35 \.: begin
49+
36 \+: Test \(T\);
50+
37 \+: Test \(F\);
51+
38 \.: end Main;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
procedure Main
2+
is
3+
T : Boolean := True;
4+
F : Boolean := False;
5+
6+
function Concat (S1, S2, S3: String) return String is
7+
begin
8+
return S1 & S2 & S3;
9+
end Concat;
10+
11+
procedure Test (B : Boolean) is
12+
begin
13+
if B
14+
and then
15+
(T
16+
or else F)
17+
then
18+
if F
19+
or else
20+
F
21+
then
22+
declare
23+
Dummy : String := Concat
24+
(
25+
"B",
26+
"C",
27+
"D"
28+
);
29+
begin
30+
null;
31+
end;
32+
end if;
33+
end if;
34+
end Test;
35+
begin
36+
Test (T);
37+
Test (F);
38+
end Main;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Check the display of violations in xcov reports. They should always be
3+
attached to the last line of the statement/decision and displayed after
4+
its last line.
5+
"""
6+
7+
from SCOV.minicheck import build_run_and_coverage
8+
from SUITE.context import thistest
9+
from SUITE.cutils import Wdir, contents_of
10+
from SUITE.gprutils import GPRswitches
11+
from SUITE.tutils import gprfor
12+
13+
tmp = Wdir("tmp_")
14+
15+
root = gprfor(
16+
prjid="gen",
17+
srcdirs="../src",
18+
mains=["main.adb"],
19+
objdir="obj",
20+
)
21+
22+
build_run_and_coverage(
23+
gprsw=GPRswitches(root),
24+
covlevel="stmt+mcdc",
25+
mains=["main"],
26+
trace_mode="src",
27+
extra_coverage_args=["--annotate=xcov+"],
28+
)
29+
30+
# Check the contents of the report by comparing it to the exact expected report
31+
# as we want to make sure the violations are displayed where they should.
32+
thistest.fail_if_no_match(
33+
"xcov+ report",
34+
contents_of("../ref.xcov"),
35+
contents_of("obj/main.adb.xcov"),
36+
)
37+
38+
thistest.result()

tools/gnatcov/annotations-report.adb

+5-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,11 @@ package body Annotations.Report is
579579
end if;
580580

581581
else
582-
Put (Output.all, Image (M.Sloc, Unique_Name => True));
582+
Put (Output.all, Image
583+
((if SC_Obligations.Kind (M.SCO) = Condition
584+
then First_Sloc (Enclosing_Decision (M.SCO))
585+
else First_Sloc (M.SCO)),
586+
Unique_Name => True));
583587
Put (Output.all, ": ");
584588
end if;
585589

tools/gnatcov/diagnostics.adb

+34-19
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ package body Diagnostics is
108108
-- Diagnostics can be emitted before the file table is complete,
109109
-- so we cannot rely on unique filenames, here.
110110

111-
return " " & Image (M.Sloc, Unique_Name => False) & ":";
111+
return " " & Image (M.Violation_Sloc, Unique_Name => False) & ":";
112112
else
113113
return "";
114114
end if;
@@ -197,22 +197,26 @@ package body Diagnostics is
197197
end Report;
198198

199199
procedure Report
200-
(Msg : String;
201-
Exe : Exe_File_Acc := null;
202-
PC : Pc_Type := No_PC;
203-
Sloc : Source_Location := No_Location;
204-
SCO : SCO_Id := No_SCO_Id;
205-
Tag : SC_Tag := No_SC_Tag;
206-
Kind : Report_Kind := Error)
200+
(Msg : String;
201+
Exe : Exe_File_Acc := null;
202+
PC : Pc_Type := No_PC;
203+
Sloc : Source_Location := No_Location;
204+
Violation_Sloc : Source_Location := No_Location;
205+
SCO : SCO_Id := No_SCO_Id;
206+
Tag : SC_Tag := No_SC_Tag;
207+
Kind : Report_Kind := Error)
207208
is
208209
M : constant Message :=
209-
(Kind => Kind,
210-
Exe => Exe,
211-
PC => PC,
212-
Sloc => Sloc,
213-
SCO => SCO,
214-
Tag => Tag,
215-
Msg => +Msg);
210+
(Kind => Kind,
211+
Exe => Exe,
212+
PC => PC,
213+
Sloc => Sloc,
214+
Violation_Sloc => (if Sloc /= No_Location
215+
then Sloc
216+
else Violation_Sloc),
217+
SCO => SCO,
218+
Tag => Tag,
219+
Msg => +Msg);
216220
begin
217221
Output_Message (M);
218222
Store_Message (M);
@@ -228,18 +232,29 @@ package body Diagnostics is
228232
Msg : String;
229233
Kind : Coverage_Kind)
230234
is
231-
Sloc : Source_Location;
235+
Sloc : Source_Location;
236+
-- Sloc of the message
237+
238+
Violation_Sloc : Source_Location;
239+
-- Sloc of the violation the message expresses
232240
begin
233241
-- For an MC/DC violation, the message is attached to the decision for
234242
-- the benefit of HTML output.
235243

236244
if SC_Obligations.Kind (SCO) = Condition then
237-
Sloc := First_Sloc (Enclosing_Decision (SCO));
245+
Sloc := Last_Sloc (Enclosing_Decision (SCO));
246+
Violation_Sloc := First_Sloc (Enclosing_Decision (SCO));
238247
else
239-
Sloc := First_Sloc (SCO);
248+
Sloc := Last_Sloc (SCO);
249+
Violation_Sloc := First_Sloc (SCO);
240250
end if;
241251

242-
Report (Msg, Sloc => Sloc, SCO => SCO, Tag => Tag, Kind => Kind);
252+
Report (Msg,
253+
Sloc => Sloc,
254+
Violation_Sloc => Violation_Sloc,
255+
SCO => SCO,
256+
Tag => Tag,
257+
Kind => Kind);
243258
end Report_Coverage;
244259

245260
----------------------

tools/gnatcov/diagnostics.ads

+16-14
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ package Diagnostics is
6060
subtype Coverage_Kind is Report_Kind range Info .. Exclusion;
6161

6262
type Message is record
63-
Kind : Report_Kind;
64-
Exe : Exe_File_Acc;
65-
PC : Pc_Type;
66-
Sloc : Source_Location;
67-
SCO : SCO_Id;
68-
Tag : SC_Tag;
69-
Msg : Unbounded_String;
63+
Kind : Report_Kind;
64+
Exe : Exe_File_Acc;
65+
PC : Pc_Type;
66+
Sloc : Source_Location;
67+
Violation_Sloc : Source_Location;
68+
SCO : SCO_Id;
69+
Tag : SC_Tag;
70+
Msg : Unbounded_String;
7071
end record;
7172

7273
package Message_Vectors is new Ada.Containers.Vectors
@@ -110,13 +111,14 @@ package Diagnostics is
110111
-- has message kind Exclusion.
111112

112113
procedure Report
113-
(Msg : String;
114-
Exe : Exe_File_Acc := null;
115-
PC : Pc_Type := No_PC;
116-
Sloc : Source_Location := No_Location;
117-
SCO : SCO_Id := No_SCO_Id;
118-
Tag : SC_Tag := No_SC_Tag;
119-
Kind : Report_Kind := Error);
114+
(Msg : String;
115+
Exe : Exe_File_Acc := null;
116+
PC : Pc_Type := No_PC;
117+
Sloc : Source_Location := No_Location;
118+
Violation_Sloc : Source_Location := No_Location;
119+
SCO : SCO_Id := No_SCO_Id;
120+
Tag : SC_Tag := No_SC_Tag;
121+
Kind : Report_Kind := Error);
120122
-- Output diagnostic message during coverage analysis. Messages with Notice
121123
-- kind are omitted unless global flag Verbose is set. A prefix is
122124
-- prepended depending on message kind:

0 commit comments

Comments
 (0)