-- Shared single-file battery (dimensions 1-6) -------------------------- * * Runs the six single-file invariants against one fixture. Returns 0 when all * pass, 1 otherwise (printing a per-dimension FAIL line). lang_tag is for * diagnostics only. expect_label is the def label the fixture is guaranteed to * produce (e.g. "Function"); callee is the in-body callee name that must * appear in th
| 73 | * appear in the extracted calls. |
| 74 | */ |
| 75 | static int single_file_battery(const char *lang_tag, const char *src, |
| 76 | CBMLanguage lang, const char *file, |
| 77 | const char *expect_label, |
| 78 | const char *callee) { |
| 79 | const char *RED = tf_red(); |
| 80 | const char *RST = tf_reset(); |
| 81 | int fails = 0; |
| 82 | |
| 83 | /* 1. extract-clean -- must hold before anything else is meaningful. */ |
| 84 | if (inv_extract_clean(src, lang, file) != 1) { |
| 85 | printf(" %sFAIL%s [%s] extract-clean: NULL result or has_error set\n", |
| 86 | RED, RST, lang_tag); |
| 87 | return 1; /* nothing else can be trusted */ |
| 88 | } |
| 89 | |
| 90 | CBMFileResult *r = inv_rx(src, lang, file); |
| 91 | if (!r) { |
| 92 | printf(" %sFAIL%s [%s] inv_rx returned NULL after clean extract\n", |
| 93 | RED, RST, lang_tag); |
| 94 | return 1; |
| 95 | } |
| 96 | |
| 97 | /* 2. labels-valid */ |
| 98 | int bad_labels = inv_count_bad_labels(r); |
| 99 | if (bad_labels != 0) { |
| 100 | printf(" %sFAIL%s [%s] labels-valid: %d def(s) with invalid label\n", |
| 101 | RED, RST, lang_tag, bad_labels); |
| 102 | fails++; |
| 103 | } |
| 104 | |
| 105 | /* 3. fqn-wellformed */ |
| 106 | int bad_fqns = inv_count_bad_fqns(r); |
| 107 | if (bad_fqns != 0) { |
| 108 | printf(" %sFAIL%s [%s] fqn-wellformed: %d def(s) with malformed QN\n", |
| 109 | RED, RST, lang_tag, bad_fqns); |
| 110 | fails++; |
| 111 | } |
| 112 | |
| 113 | /* 4. ranges-valid */ |
| 114 | int bad_ranges = inv_count_bad_ranges(r); |
| 115 | if (bad_ranges != 0) { |
| 116 | printf(" %sFAIL%s [%s] ranges-valid: %d def(s) with invalid range\n", |
| 117 | RED, RST, lang_tag, bad_ranges); |
| 118 | fails++; |
| 119 | } |
| 120 | |
| 121 | /* 5. defs-present -- the function/definition the fixture wrote must be extracted. */ |
| 122 | if (expect_label && inv_count_label(r, expect_label) < 1) { |
| 123 | printf(" %sFAIL%s [%s] defs-present: no def labelled \"%s\"\n", |
| 124 | RED, RST, lang_tag, expect_label); |
| 125 | fails++; |
| 126 | } |
| 127 | |
| 128 | /* 6. calls-extracted -- the in-body call must be captured. */ |
| 129 | if (inv_has_call(r, callee) != 1) { |
| 130 | printf(" %sFAIL%s [%s] calls-extracted: no call to \"%s\" found" |
| 131 | " -- known extraction gap\n", |
| 132 | RED, RST, lang_tag, callee); |
no test coverage detected