Skip to content

Commit 434d99f

Browse files
committed
subp_of_interest: check that coverage logs are empty
1 parent ec63dd9 commit 434d99f

File tree

1 file changed

+37
-14
lines changed
  • testsuite/tests/subp_of_interest

1 file changed

+37
-14
lines changed

testsuite/tests/subp_of_interest/test.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,29 @@
1313
from SUITE.tutils import gprfor, xcov
1414
from SUITE.gprutils import GPRswitches
1515

16+
17+
src_traces = thistest.options.trace_mode == "src"
18+
19+
20+
def check_xcov(label, args, expected_output=""):
21+
"""
22+
Run xcov with the given aruments and check its output.
23+
24+
Also pass it --output-dir={label}, and create that directory beforehand.
25+
"""
26+
log = f"{label}.log"
27+
os.mkdir(label)
28+
xcov(args + [f"--output-dir={label}"], out=log)
29+
thistest.fail_if_not_equal(
30+
"'gnatcov coverage' output",
31+
expected_output,
32+
contents_of(log).strip(),
33+
)
34+
35+
1636
tmp = Wdir("tmp_")
1737

38+
thistest.log("== Checkpoint creation ==")
1839
cov_args = build_and_run(
1940
gprsw=GPRswitches(
2041
gprfor(srcdirs=os.path.join("..", "src"), mains=["main.adb"])
@@ -28,8 +49,8 @@
2849
# that the coverage report contains only coverage data for the specified
2950
# subprograms for source traces. For binary traces, simply check that the
3051
# gnatcov coverage invocation yields the expected warning.
31-
os.mkdir("xcov_subp")
32-
xcov(
52+
check_xcov(
53+
"xcov_subp",
3354
cov_args
3455
+ [
3556
"--save-checkpoint",
@@ -40,18 +61,15 @@
4061
f"{os.path.join('..', 'src', 'pkg.adb')}:10",
4162
"--subprograms",
4263
f"{os.path.join('..', 'src', 'pkg.adb')}:12",
43-
"--output-dir=xcov_subp",
4464
],
45-
out="coverage.log",
46-
)
47-
if thistest.options.trace_mode == "bin":
48-
thistest.fail_if_no_match(
49-
"gnatcov coverage output",
65+
expected_output=(
66+
""
67+
if src_traces else
5068
"warning: Ignoring --subprograms switches as this is not supported"
51-
" with binary traces.",
52-
contents_of("coverage.log"),
53-
)
54-
else:
69+
" with binary traces."
70+
),
71+
)
72+
if src_traces:
5573
check_xcov_reports(
5674
"*.xcov",
5775
{
@@ -64,9 +82,11 @@
6482
# Then check that the checkpoint contains only coverage data for the
6583
# specific subprogram. To do this, produce a new coverage report from the
6684
# checkpoint without using the --subprograms switch.
67-
xcov(
85+
thistest.log("== xcov_no_subp ==")
86+
check_xcov(
87+
"xcov_no_subp",
6888
cov_args[:-1]
69-
+ ["--checkpoint", "trace.ckpt", "--output-dir=xcov_no_subp"]
89+
+ ["--checkpoint", "trace.ckpt"],
7090
)
7191
check_xcov_reports(
7292
"*.xcov",
@@ -80,6 +100,7 @@
80100
# Also check the warnings when the subprogram switch is ill-formed
81101

82102
# Case 1: missing colon in the argument
103+
thistest.log("== Missing colon ==")
83104
xcov(
84105
cov_args + ["--subprograms", "no-colon"],
85106
out="xcov-wrong1.txt",
@@ -92,6 +113,7 @@
92113
)
93114

94115
# Case 2: line number is not a number
116+
thistest.log("== Bad line number ==")
95117
xcov(
96118
cov_args + [
97119
"--subprograms", f"{os.path.join('..', 'src', 'pkg.ads')}:b",
@@ -106,6 +128,7 @@
106128
)
107129

108130
# Case 3: file does not exist
131+
thistest.log("== No such file ==")
109132
xcov(
110133
cov_args + ["--subprograms", "dumb-file-name:4"],
111134
out="xcov-wrong3.txt",

0 commit comments

Comments
 (0)