From d74fe7a222c1e1ae0f02addbeb712f8946d3d731 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 26 Oct 2021 13:53:44 -0400 Subject: [PATCH] Add coverage for empty CATCH() blocks. Currently empty CATCH() blocks are always marked as covered because of the loop structure of error handling. A prototype implementation of error handling without looping has shown that these CATCH() blocks are not covered without new tests. Whether or not that prototype gets committed it is worth adding the tests. --- test/src/module/command/backupTest.c | 31 +++++++++++++++++++--------- test/src/module/command/repoTest.c | 13 +++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index 877675dde..79b3cc88d 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -1191,6 +1191,27 @@ testRun(void) cfgOptionSet(cfgOptResume, cfgSourceParam, BOOL_TRUE_VAR); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("cannot resume when error on manifest load"); + + Manifest *manifest = NULL; + + OBJ_NEW_BEGIN(Manifest) + { + manifest = manifestNewInternal(); + manifest->pub.data.backupType = backupTypeFull; + manifest->pub.data.backrestVersion = STRDEF("BOGUS"); + } + OBJ_NEW_END(); + + HRN_STORAGE_PUT_Z(storageRepoWrite(), STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, "X"); + + TEST_RESULT_PTR(backupResumeFind(manifest, NULL), NULL, "find resumable backup"); + + TEST_RESULT_LOG( + "P00 WARN: backup '20191003-105320F' cannot be resumed: unable to read" + " /20191003-105320F/backup.manifest.copy"); + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("cannot resume when pgBackRest version has changed"); @@ -1216,16 +1237,6 @@ testRun(void) storageNewWriteP( storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT)))); - Manifest *manifest = NULL; - - OBJ_NEW_BEGIN(Manifest) - { - manifest = manifestNewInternal(); - manifest->pub.data.backupType = backupTypeFull; - manifest->pub.data.backrestVersion = STRDEF("BOGUS"); - } - OBJ_NEW_END(); - TEST_RESULT_PTR(backupResumeFind(manifest, NULL), NULL, "find resumable backup"); TEST_RESULT_LOG( diff --git a/test/src/module/command/repoTest.c b/test/src/module/command/repoTest.c index de5825232..e5dd4cf3e 100644 --- a/test/src/module/command/repoTest.c +++ b/test/src/module/command/repoTest.c @@ -179,6 +179,12 @@ testRun(void) // Not in a test wrapper to avoid writing to stdout cmdStorageList(); + // Close the fd to make sure the error gets caught + close(STDOUT_FILENO); + + // // Not in a test wrapper to avoid writing to stdout + cmdStorageList(); + // Restore normal stdout dup2(stdoutSave, STDOUT_FILENO); @@ -530,12 +536,17 @@ testRun(void) // Not in a test wrapper to avoid writing to stdout ASSERT(cmdStorageGet() == 0); + // Close the fd to make sure the error gets caught + close(STDOUT_FILENO); + + // Not in a test wrapper to avoid writing to stdout + ASSERT(cmdStorageGet() == 1); + // Restore normal stdout dup2(stdoutSave, STDOUT_FILENO); TEST_STORAGE_GET(storageRepo(), "stdout.txt", fileRawContent, .comment = "get matches put"); - // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("ignore missing file");