File tree 5 files changed +69
-3
lines changed
testsuite/tests/instr-cov/363-annot-crash
5 files changed +69
-3
lines changed Original file line number Diff line number Diff line change
1
+ package body Pkg is
2
+ procedure Foo is
3
+ begin
4
+ null ;
5
+ end Foo ;
6
+ end Pkg ;
Original file line number Diff line number Diff line change
1
+ package Pkg is
2
+ procedure Foo ;
3
+ end Pkg ;
Original file line number Diff line number Diff line change
1
+ with Pkg ;
2
+
3
+ procedure Test is
4
+ begin
5
+ Pkg.Foo;
6
+ end Test ;
Original file line number Diff line number Diff line change
1
+ """
2
+ Regression test: check that gnatcov does not crash when generating a XML / HTML
3
+ report with missing sources. It used to crash when trying to compute scope
4
+ metrics.
5
+ """
6
+
7
+ from e3 .fs import mv , sync_tree
8
+
9
+ import os
10
+
11
+ from SCOV .minicheck import build_and_run
12
+ from SUITE .cutils import Wdir
13
+ from SUITE .gprutils import GPRswitches
14
+ from SUITE .tutils import gprfor , thistest , xcov
15
+
16
+ tmp = Wdir ("tmp_" )
17
+
18
+ sync_tree (os .path .join (".." , "src" ), "src" )
19
+
20
+ xcov_args = build_and_run (
21
+ gprsw = GPRswitches (
22
+ root_project = gprfor (srcdirs = ["src" ], mains = ["test.adb" ])
23
+ ),
24
+ covlevel = "stmt" ,
25
+ mains = ["test" ],
26
+ extra_coverage_args = [],
27
+ trace_mode = "src" ,
28
+ )
29
+
30
+ # Then hide the sources
31
+ os .mkdir ("src_hidden" )
32
+ mv (os .path .join ("src" , "pkg.adb" ), "src_hidden" )
33
+
34
+ # Try to generate a HTML, and an XML report
35
+ xcov (xcov_args + ["-axml" ], tolerate_messages = "warning: can't open" )
36
+ xcov (xcov_args + ["-ahtml" ], tolerate_messages = "warning: can't open" )
37
+
38
+ thistest .result ()
Original file line number Diff line number Diff line change @@ -996,11 +996,24 @@ package body Annotations is
996
996
(FI : File_Info_Access;
997
997
From, To : Natural) return Li_Stat_Array
998
998
is
999
- Result : Li_Stat_Array := (others => 0 );
999
+ Result : Li_Stat_Array := (others => 0 );
1000
+ Actual_To : Natural := To;
1001
+ Last_Loaded_Line : Natural renames Last_Line (FI);
1000
1002
begin
1001
- for L in From .. To loop
1003
+ -- Do not try to retrieve a line that was not loaded (which has an index
1004
+ -- superior to Last_Line (FI)). This can happen when the sources are not
1005
+ -- available. In that case, only loop until the last loaded line is
1006
+ -- reached (it actually corresponds to the last SCO line), and consider
1007
+ -- the subsequent lines as no code.
1008
+
1009
+ if To > Last_Loaded_Line then
1010
+ Result (No_Code) := To - Last_Loaded_Line;
1011
+ Actual_To := Last_Loaded_Line;
1012
+ end if ;
1013
+
1014
+ for L in From .. Actual_To loop
1002
1015
declare
1003
- LI : constant Line_Info_Access := Get_Line (FI, L);
1016
+ LI : constant Line_Info_Access := Get_Line (FI, L);
1004
1017
S : constant Any_Line_State := Aggregated_State (LI.all );
1005
1018
begin
1006
1019
-- Update counts. Note that No_Code lines are always counted as
You can’t perform that action at this time.
0 commit comments