Add assertions

Closes #292
This commit is contained in:
ISSOtm
2020-03-05 02:58:48 +01:00
parent 03967bd623
commit fb58166e5d
18 changed files with 506 additions and 82 deletions

View File

@@ -340,6 +340,48 @@ static int32_t computeRPNExpr(struct Patch const *patch,
#undef popRPN
}
void patch_CheckAssertions(struct Assertion *assert)
{
verbosePrint("Checking assertions...");
initRPNStack();
uint8_t failures = 0;
while (assert) {
if (!computeRPNExpr(&assert->patch, assert->section)) {
switch ((enum AssertionType)assert->patch.type) {
case ASSERT_FATAL:
errx(1, "%s: %s", assert->patch.fileName,
assert->message[0] ? assert->message
: "assert failure");
/* Not reached */
break; /* Here so checkpatch doesn't complain */
case ASSERT_ERROR:
fprintf(stderr, "%s: %s\n",
assert->patch.fileName,
assert->message[0] ? assert->message
: "assert failure");
failures++;
break;
case ASSERT_WARN:
warnx("%s: %s", assert->patch.fileName,
assert->message[0] ? assert->message
: "assert failure");
break;
}
}
struct Assertion *next = assert->next;
free(assert);
assert = next;
}
freeRPNStack();
if (failures)
errx(1, "%u assertions failed!", failures);
}
/**
* Applies all of a section's patches
* @param section The section to patch
@@ -399,3 +441,4 @@ void patch_ApplyPatches(void)
sect_ForEach(applyPatches, NULL);
freeRPNStack();
}