── Structural battery with defs-present (dims 1-5) ──────────────────────── * * Adds the defs-present dimension for languages with class_types, func_types, * or reliably-labelled var_types (DOCKERFILE, GOMOD, K8S, KUSTOMIZE). * Pass NULL for expect_label2 when only one label type is needed. * Returns 0 on PASS, 1 on FAIL. */
| 185 | * Returns 0 on PASS, 1 on FAIL. |
| 186 | */ |
| 187 | static int build_struct_battery(const char *lang_tag, const char *src, |
| 188 | CBMLanguage lang, const char *file, |
| 189 | const char *expect_label, |
| 190 | const char *expect_label2) { |
| 191 | const char *RED = tf_red(); |
| 192 | const char *RST = tf_reset(); |
| 193 | |
| 194 | /* 1. extract-clean */ |
| 195 | if (inv_extract_clean(src, lang, file) != 1) { |
| 196 | printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n", |
| 197 | RED, RST, lang_tag); |
| 198 | return 1; |
| 199 | } |
| 200 | |
| 201 | CBMFileResult *r = inv_rx(src, lang, file); |
| 202 | if (!r) { |
| 203 | printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n", |
| 204 | RED, RST, lang_tag); |
| 205 | return 1; |
| 206 | } |
| 207 | |
| 208 | int fails = 0; |
| 209 | |
| 210 | /* 2. labels-valid */ |
| 211 | int bad_labels = inv_count_bad_labels(r); |
| 212 | if (bad_labels != 0) { |
| 213 | printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n", |
| 214 | RED, RST, lang_tag, bad_labels); |
| 215 | fails++; |
| 216 | } |
| 217 | |
| 218 | /* 3. fqn-wellformed */ |
| 219 | int bad_fqns = inv_count_bad_fqns(r); |
| 220 | if (bad_fqns != 0) { |
| 221 | printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n", |
| 222 | RED, RST, lang_tag, bad_fqns); |
| 223 | fails++; |
| 224 | } |
| 225 | |
| 226 | /* 4. ranges-valid */ |
| 227 | int bad_ranges = inv_count_bad_ranges(r); |
| 228 | if (bad_ranges != 0) { |
| 229 | printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n", |
| 230 | RED, RST, lang_tag, bad_ranges); |
| 231 | fails++; |
| 232 | } |
| 233 | |
| 234 | /* 5. defs-present (primary label) */ |
| 235 | if (expect_label && inv_count_label(r, expect_label) < 1) { |
| 236 | printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n", |
| 237 | RED, RST, lang_tag, expect_label); |
| 238 | fails++; |
| 239 | } |
| 240 | |
| 241 | /* 5b. defs-present (secondary label, optional) */ |
| 242 | if (expect_label2 && inv_count_label(r, expect_label2) < 1) { |
| 243 | printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n", |
| 244 | RED, RST, lang_tag, expect_label2); |
no test coverage detected