── Callable battery with calls-extracted (dims 1-6) ─────────────────────── * * Adds dims 5 (optional) and 6 (calls-extracted) to the base invariants. * Pass NULL for expect_label when the language has no func/class def to assert * alongside the call (e.g. HCL has class_types=block but call_types are for * built-in function calls unrelated to the block defs). * Returns 0 on PASS, 1 on FAIL.
| 253 | * Returns 0 on PASS, 1 on FAIL. |
| 254 | */ |
| 255 | static int config_callable_battery(const char *lang_tag, const char *src, |
| 256 | CBMLanguage lang, const char *file, |
| 257 | const char *expect_label, |
| 258 | const char *callee) { |
| 259 | const char *RED = tf_red(); |
| 260 | const char *RST = tf_reset(); |
| 261 | |
| 262 | /* 1. extract-clean */ |
| 263 | if (inv_extract_clean(src, lang, file) != 1) { |
| 264 | printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n", |
| 265 | RED, RST, lang_tag); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | CBMFileResult *r = inv_rx(src, lang, file); |
| 270 | if (!r) { |
| 271 | printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n", |
| 272 | RED, RST, lang_tag); |
| 273 | return 1; |
| 274 | } |
| 275 | |
| 276 | int fails = 0; |
| 277 | |
| 278 | /* 2. labels-valid */ |
| 279 | int bad_labels = inv_count_bad_labels(r); |
| 280 | if (bad_labels != 0) { |
| 281 | printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n", |
| 282 | RED, RST, lang_tag, bad_labels); |
| 283 | fails++; |
| 284 | } |
| 285 | |
| 286 | /* 3. fqn-wellformed */ |
| 287 | int bad_fqns = inv_count_bad_fqns(r); |
| 288 | if (bad_fqns != 0) { |
| 289 | printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n", |
| 290 | RED, RST, lang_tag, bad_fqns); |
| 291 | fails++; |
| 292 | } |
| 293 | |
| 294 | /* 4. ranges-valid */ |
| 295 | int bad_ranges = inv_count_bad_ranges(r); |
| 296 | if (bad_ranges != 0) { |
| 297 | printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n", |
| 298 | RED, RST, lang_tag, bad_ranges); |
| 299 | fails++; |
| 300 | } |
| 301 | |
| 302 | /* 5. defs-present (only when a def label is expected) */ |
| 303 | if (expect_label && inv_count_label(r, expect_label) < 1) { |
| 304 | printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n", |
| 305 | RED, RST, lang_tag, expect_label); |
| 306 | fails++; |
| 307 | } |
| 308 | |
| 309 | /* 6. calls-extracted */ |
| 310 | if (callee && inv_has_call(r, callee) != 1) { |
| 311 | printf(" %sFAIL%s [%s] calls-extracted: no call to \"%s\" found\n", |
| 312 | RED, RST, lang_tag, callee); |
no test coverage detected