|
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 | +pkg_spec = os.path.join("..", "src", "pkg.ads") |
| 39 | +pkg_body = os.path.join("..", "src", "pkg.adb") |
| 40 | + |
| 41 | +thistest.log("== Checkpoint creation ==") |
18 | 42 | cov_args = build_and_run( |
19 | 43 | gprsw=GPRswitches( |
20 | 44 | gprfor(srcdirs=os.path.join("..", "src"), mains=["main.adb"]) |
|
28 | 52 | # that the coverage report contains only coverage data for the specified |
29 | 53 | # subprograms for source traces. For binary traces, simply check that the |
30 | 54 | # gnatcov coverage invocation yields the expected warning. |
31 | | -os.mkdir("xcov_subp") |
32 | | -xcov( |
| 55 | +check_xcov( |
| 56 | + "xcov_subp", |
33 | 57 | cov_args |
34 | 58 | + [ |
35 | 59 | "--save-checkpoint", |
36 | 60 | "trace.ckpt", |
37 | | - "--subprograms", |
38 | | - f"{os.path.join('..', 'src', 'pkg.ads')}:4", |
39 | | - "--subprograms", |
40 | | - f"{os.path.join('..', 'src', 'pkg.adb')}:10", |
41 | | - "--subprograms", |
42 | | - f"{os.path.join('..', 'src', 'pkg.adb')}:12", |
43 | | - "--output-dir=xcov_subp", |
| 61 | + f"--subprograms={pkg_spec}:4", |
| 62 | + f"--subprograms={pkg_body}:10", |
| 63 | + f"--subprograms={pkg_body}:12", |
44 | 64 | ], |
45 | | - out="coverage.log", |
| 65 | + expected_output=( |
| 66 | + "" |
| 67 | + if src_traces else |
| 68 | + "warning: Ignoring --subprograms switches as this is not supported" |
| 69 | + " with binary traces." |
| 70 | + ), |
46 | 71 | ) |
47 | | -if thistest.options.trace_mode == "bin": |
48 | | - thistest.fail_if_no_match( |
49 | | - "gnatcov coverage output", |
50 | | - "warning: Ignoring --subprograms switches as this is not supported with" |
51 | | - " binary traces.", |
52 | | - contents_of("coverage.log"), |
53 | | - ) |
54 | | -else: |
| 72 | +if src_traces: |
55 | 73 | check_xcov_reports( |
56 | 74 | "*.xcov", |
57 | 75 | { |
|
61 | 79 | "xcov_subp", |
62 | 80 | ) |
63 | 81 |
|
64 | | - # Then check that the checkpoint contains only coverage data for the specific |
65 | | - # subprogram. To do this, produce a new coverage report from the checkpoint |
66 | | - # without using the --subprograms switch. |
67 | | - xcov( |
| 82 | + # Then check that the checkpoint contains only coverage data for the |
| 83 | + # specific subprogram. To do this, produce a new coverage report from the |
| 84 | + # checkpoint without using the --subprograms switch. |
| 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", |
|
90 | 111 | regexp=r".*Wrong argument passed to --subprograms: .*", |
91 | 112 | actual=contents_of("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 | | - cov_args + ["--subprograms", f"{os.path.join('..', 'src', 'pkg.ads')}:b",], |
| 118 | + cov_args + ["--subprograms", f"{pkg_spec}:b"], |
97 | 119 | out="xcov-wrong2.txt", |
98 | 120 | register_failure=False, |
99 | 121 | ) |
|
102 | 124 | regexp=r".*Wrong argument passed to --subprograms: .*", |
103 | 125 | actual=contents_of("xcov-wrong2.txt"), |
104 | 126 | ) |
105 | | - |
| 127 | + |
106 | 128 | # Case 3: file does not exist |
| 129 | + thistest.log("== No such file ==") |
107 | 130 | xcov( |
108 | 131 | cov_args + ["--subprograms", "dumb-file-name:4"], |
109 | 132 | out="xcov-wrong3.txt", |
110 | 133 | register_failure=False, |
111 | 134 | ) |
112 | 135 | thistest.fail_if_no_match( |
113 | 136 | what="unexpected coverage output", |
114 | | - regexp=r".*Error when parsing --subprograms argument dumb-file-name:4:" |
115 | | - r".*dumb-file-name does not exist", |
| 137 | + regexp=( |
| 138 | + r".*Error when parsing --subprograms argument dumb-file-name:4:" |
| 139 | + r" unknown source file" |
| 140 | + ), |
116 | 141 | actual=contents_of("xcov-wrong3.txt"), |
117 | 142 | ) |
118 | 143 |
|
| 144 | + # Case 4: scope does not exist |
| 145 | + thistest.log("== No such scope ==") |
| 146 | + xcov( |
| 147 | + cov_args + [f"--subprograms={pkg_body}:14"], |
| 148 | + out="xcov-wrong3.txt", |
| 149 | + register_failure=False, |
| 150 | + ) |
| 151 | + thistest.fail_if_no_match( |
| 152 | + what="unexpected coverage output", |
| 153 | + regexp=( |
| 154 | + f".*Error when parsing --subprograms argument {pkg_body}:14:" |
| 155 | + " unknown subprogram" |
| 156 | + ), |
| 157 | + actual=contents_of("xcov-wrong3.txt"), |
| 158 | + ) |
119 | 159 |
|
120 | 160 |
|
121 | 161 | thistest.result() |
0 commit comments