You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-17 01:12:23 +02:00
Use THROW_ON_SYS_ERROR*() to improve code coverage.
There is only one instance in the core code where this helps. It is mostly helpful in the tests. There is an argument to be made that only THROW_SYS_ERROR*() variants should be used in the core code to improve test coverage. If so, that will be the subject of a future commit.
This commit is contained in:
@ -114,6 +114,10 @@
|
||||
<release-item>
|
||||
<p>Add <code>cfgOptionUInt()</code> and <code>cfgOptionUInt64()</code> and update code to use them.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Use <code>THROW_ON_SYS_ERROR*()</code> to improve code coverage.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -107,9 +107,9 @@ storageDriverS3DateTime(time_t authTime)
|
||||
|
||||
char buffer[ISO_8601_DATE_TIME_SIZE + 1];
|
||||
|
||||
if (strftime( // {uncoverable - nothing invalid can be passed}
|
||||
buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", gmtime(&authTime)) != ISO_8601_DATE_TIME_SIZE)
|
||||
THROW_SYS_ERROR(AssertError, "unable to format date"); // {+uncoverable}
|
||||
THROW_ON_SYS_ERROR(
|
||||
strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", gmtime(&authTime)) != ISO_8601_DATE_TIME_SIZE, AssertError,
|
||||
"unable to format date");
|
||||
|
||||
FUNCTION_TEST_RETURN(strNew(buffer));
|
||||
}
|
||||
|
@ -378,8 +378,7 @@ testRun(void)
|
||||
int stdoutSave = dup(STDOUT_FILENO);
|
||||
String *stdoutFile = strNewFmt("%s/stdout.help", testPath());
|
||||
|
||||
if (freopen(strPtr(stdoutFile), "w", stdout) == NULL) // {uncoverable - does not fail}
|
||||
THROW_SYS_ERROR(FileWriteError, "unable to reopen stdout"); // {uncoverable+}
|
||||
THROW_ON_SYS_ERROR(freopen(strPtr(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout");
|
||||
|
||||
// Not in a test wrapper to avoid writing to stdout
|
||||
cmdHelp();
|
||||
|
@ -816,8 +816,7 @@ testRun(void)
|
||||
int stdoutSave = dup(STDOUT_FILENO);
|
||||
String *stdoutFile = strNewFmt("%s/stdout.info", testPath());
|
||||
|
||||
if (freopen(strPtr(stdoutFile), "w", stdout) == NULL) // {uncoverable - does not fail}
|
||||
THROW_SYS_ERROR(FileWriteError, "unable to reopen stdout"); // {uncoverable+}
|
||||
THROW_ON_SYS_ERROR(freopen(strPtr(stdoutFile), "w", stdout) == NULL, FileWriteError, "unable to reopen stdout");
|
||||
|
||||
// Not in a test wrapper to avoid writing to stdout
|
||||
cmdInfo();
|
||||
|
@ -22,8 +22,7 @@ testLogOpen(const char *logFile, int flags, int mode)
|
||||
|
||||
int result = open(logFile, flags, mode);
|
||||
|
||||
if (result == -1) // {uncovered - no errors in test}
|
||||
THROW_SYS_ERROR_FMT(FileOpenError, "unable to open log file '%s'", logFile); // {+uncovered}
|
||||
THROW_ON_SYS_ERROR_FMT(result == -1, FileOpenError, "unable to open log file '%s'", logFile);
|
||||
|
||||
FUNCTION_HARNESS_RESULT(INT, result);
|
||||
}
|
||||
@ -52,17 +51,15 @@ testLogLoad(const char *logFile, char *buffer, size_t bufferSize)
|
||||
|
||||
do
|
||||
{
|
||||
actualBytes = read(handle, buffer, bufferSize - totalBytes);
|
||||
|
||||
if (actualBytes == -1) // {uncovered - no errors in test}
|
||||
THROW_SYS_ERROR_FMT(FileOpenError, "unable to read log file '%s'", logFile); // {+uncovered}
|
||||
THROW_ON_SYS_ERROR_FMT(
|
||||
(actualBytes = read(handle, buffer, bufferSize - totalBytes)) == -1, FileOpenError, "unable to read log file '%s'",
|
||||
logFile);
|
||||
|
||||
totalBytes += (size_t)actualBytes;
|
||||
}
|
||||
while (actualBytes != 0);
|
||||
|
||||
if (close(handle) == -1) // {uncovered - no errors in test}
|
||||
THROW_SYS_ERROR_FMT(FileOpenError, "unable to close log file '%s'", logFile); // {+uncovered}
|
||||
THROW_ON_SYS_ERROR_FMT(close(handle) == -1, FileOpenError, "unable to close log file '%s'", logFile);
|
||||
|
||||
// Remove final linefeed
|
||||
buffer[totalBytes - 1] = 0;
|
||||
|
Reference in New Issue
Block a user