Skip to content

Commit 5d9e7d5

Browse files
committed
Setup-integration: improve error message when failing to load gnatcov_rts
1 parent 10a7e4f commit 5d9e7d5

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INVALID PROJECT FILE FOR TEST PURPOSES
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int
2+
main ()
3+
{
4+
return 0;
5+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Test that the error message emitted by the "gnatcov setup-integration" command
3+
is helpful when failing to load the coverage runtime project.
4+
"""
5+
6+
import os
7+
8+
from SUITE.cutils import Wdir
9+
from SUITE.tutils import contents_of, thistest, xcov
10+
11+
# Point gnatcov towards our invalid GNATcov_RTS project
12+
env = os.environ
13+
env["GPR_PROJECT_PATH"] = os.getcwd()
14+
15+
tmp = Wdir("tmp_")
16+
17+
# Try to setup for a simple main file
18+
integration_log = "setup-integration.log"
19+
p = xcov(
20+
[
21+
"setup-integration",
22+
"-cstmt+mcdc",
23+
"--output-dir=.",
24+
"--files=../main.c",
25+
],
26+
env=env,
27+
out=integration_log,
28+
register_failure=False
29+
)
30+
31+
thistest.fail_if(p.status == 0, "gnatcov exit status shouldn't be success")
32+
33+
# Check that the error message correctly reports an issue with the coverage
34+
# runtime.
35+
thistest.fail_if_no_match(
36+
what="gnatcov error message",
37+
regexp=r".*gnatcov(\.exe)?: Failed locating or loading gnatcov_rts\.gpr"
38+
r"(\n|.)*Is the project available on the GPR_PROJECT_PATH\?"
39+
r"(\n|.)*gprls output was:"
40+
r"(\n|.)*",
41+
actual=contents_of(integration_log),
42+
)
43+
44+
thistest.result()

tools/gnatcov/instrument-setup_config.adb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,28 @@ package body Instrument.Setup_Config is
136136
Output_Filename : constant String :=
137137
Output_Dir / "gprls_output";
138138
Output_File : File_Type;
139+
GPRLS_Success : Boolean;
139140
begin
140141
Args.Append (+"-P");
141142
Args.Append (+"gnatcov_rts");
142143
Args.Append (+"-vP1");
143-
Run_Command
144+
GPRLS_Success := Run_Command
144145
(Command => "gprls",
145146
Arguments => Args,
146147
Origin_Command_Name => "gnatcov setup-integration",
147-
Output_File => Output_Filename);
148+
Output_File => Output_Filename,
149+
Ignore_Error => True);
148150
Open (Output_File, In_File, Output_Filename);
151+
if not GPRLS_Success then
152+
Outputs.Error ("Failed locating or loading gnatcov_rts.gpr");
153+
Warning_Or_Error ("Is the project available on the"
154+
& " GPR_PROJECT_PATH?");
155+
Warning_Or_Error ("gprls output was:");
156+
while not End_Of_File (Output_File) loop
157+
Warning_Or_Error (Get_Line (Output_File));
158+
end loop;
159+
raise Xcov_Exit_Exc;
160+
end if;
149161
while not End_Of_File (Output_File) loop
150162
declare
151163
Line : constant String := Get_Line (Output_File);

0 commit comments

Comments
 (0)