1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Add _FMT variants for all THROW macros so format types are checked by the compiler.

This commit is contained in:
David Steele
2018-05-03 11:24:29 -04:00
parent 6a40c916d4
commit c3a8fbe706
40 changed files with 246 additions and 194 deletions

View File

@ -178,7 +178,7 @@ testRun()
}
// -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("THROW_CODE()"))
if (testBegin("THROW_CODE() and THROW_CODE_FMT()"))
{
TRY_BEGIN()
{
@ -191,6 +191,18 @@ testRun()
}
TRY_END();
// -------------------------------------------------------------------------------------------------------------------------
TRY_BEGIN()
{
THROW_CODE_FMT(122, "message %d", 1);
}
CATCH_ANY()
{
assert(errorCode() == 122);
assert(strcmp(errorMessage(), "message 1") == 0);
}
TRY_END();
// -------------------------------------------------------------------------------------------------------------------------
TRY_BEGIN()
{
@ -205,7 +217,7 @@ testRun()
}
// -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("THROW_SYS_ERROR()"))
if (testBegin("THROW_SYS_ERROR() and THROW_SYS_ERROR_FMT()"))
{
TRY_BEGIN()
{
@ -219,5 +231,19 @@ testRun()
assert(strcmp(errorMessage(), "message: [7] Argument list too long") == 0);
}
TRY_END();
// -------------------------------------------------------------------------------------------------------------------------
TRY_BEGIN()
{
errno = EIO;
THROW_SYS_ERROR_FMT(AssertError, "message %d", 1);
}
CATCH_ANY()
{
printf("%s\n", errorMessage());
assert(errorCode() == AssertError.code);
assert(strcmp(errorMessage(), "message 1: [5] Input/output error") == 0);
}
TRY_END();
}
}