|
13 | 13 | from SUITE.tutils import gprfor, xcov |
14 | 14 | from SUITE.gprutils import GPRswitches |
15 | 15 |
|
| 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 | + |
16 | 36 | tmp = Wdir("tmp_") |
17 | 37 |
|
| 38 | +thistest.log("== Checkpoint creation ==") |
18 | 39 | cov_args = build_and_run( |
19 | 40 | gprsw=GPRswitches( |
20 | 41 | gprfor(srcdirs=os.path.join("..", "src"), mains=["main.adb"]) |
|
28 | 49 | # that the coverage report contains only coverage data for the specified |
29 | 50 | # subprograms for source traces. For binary traces, simply check that the |
30 | 51 | # gnatcov coverage invocation yields the expected warning. |
31 | | -os.mkdir("xcov_subp") |
32 | | -xcov( |
| 52 | +check_xcov( |
| 53 | + "xcov_subp", |
33 | 54 | cov_args |
34 | 55 | + [ |
35 | 56 | "--save-checkpoint", |
|
40 | 61 | f"{os.path.join('..', 'src', 'pkg.adb')}:10", |
41 | 62 | "--subprograms", |
42 | 63 | f"{os.path.join('..', 'src', 'pkg.adb')}:12", |
43 | | - "--output-dir=xcov_subp", |
44 | 64 | ], |
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 |
50 | 68 | "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: |
55 | 73 | check_xcov_reports( |
56 | 74 | "*.xcov", |
57 | 75 | { |
|
64 | 82 | # Then check that the checkpoint contains only coverage data for the |
65 | 83 | # specific subprogram. To do this, produce a new coverage report from the |
66 | 84 | # checkpoint without using the --subprograms switch. |
67 | | - xcov( |
| 85 | + thistest.log("== xcov_no_subp ==") |
| 86 | + check_xcov( |
| 87 | + "xcov_no_subp", |
68 | 88 | cov_args[:-1] |
69 | | - + ["--checkpoint", "trace.ckpt", "--output-dir=xcov_no_subp"] |
| 89 | + + ["--checkpoint", "trace.ckpt"], |
70 | 90 | ) |
71 | 91 | check_xcov_reports( |
72 | 92 | "*.xcov", |
|
80 | 100 | # Also check the warnings when the subprogram switch is ill-formed |
81 | 101 |
|
82 | 102 | # Case 1: missing colon in the argument |
| 103 | + thistest.log("== Missing colon ==") |
83 | 104 | xcov( |
84 | 105 | cov_args + ["--subprograms", "no-colon"], |
85 | 106 | out="xcov-wrong1.txt", |
|
92 | 113 | ) |
93 | 114 |
|
94 | 115 | # Case 2: line number is not a number |
| 116 | + thistest.log("== Bad line number ==") |
95 | 117 | xcov( |
96 | 118 | cov_args + [ |
97 | 119 | "--subprograms", f"{os.path.join('..', 'src', 'pkg.ads')}:b", |
|
106 | 128 | ) |
107 | 129 |
|
108 | 130 | # Case 3: file does not exist |
| 131 | + thistest.log("== No such file ==") |
109 | 132 | xcov( |
110 | 133 | cov_args + ["--subprograms", "dumb-file-name:4"], |
111 | 134 | out="xcov-wrong3.txt", |
|
0 commit comments