]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
tests: Check if Pakfire was initialized correctly
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Aug 2022 16:47:03 +0000 (16:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Aug 2022 16:47:03 +0000 (16:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/testsuite.c

index 65fca38c700162db4c340a743fcef24c151f53be..417a60b9e592b19f5350afa88f373d65e1658367 100644 (file)
@@ -55,6 +55,12 @@ static int test_run(int i, struct test* t) {
                goto ERROR;
        }
 
+       // Check if the instance was created properly
+       if (r == 0 && !t->pakfire) {
+               LOG("ERROR: Pakfire was not initialized, but no error was raised: %m\n");
+               goto ERROR;
+       }
+
        // Copy command into environment
        r = pakfire_copy_in(t->pakfire, TEST_STUB_COMMAND, "/command");
        if (r) {
@@ -69,16 +75,18 @@ static int test_run(int i, struct test* t) {
 
 ERROR:
        // Release pakfire
-       p = pakfire_unref(t->pakfire);
+       if (t->pakfire) {
+               p = pakfire_unref(t->pakfire);
 
-       // Check if Pakfire was actually released
-       if (p) {
-               LOG("Error: Pakfire instance was not released in test %d\n", i);
-               return 1;
-       }
+               // Check if Pakfire was actually released
+               if (p) {
+                       LOG("Error: Pakfire instance was not released in test %d\n", i);
+                       return 1;
+               }
 
-       // Reset pointer (just in case)
-       t->pakfire = NULL;
+               // Reset pointer (just in case)
+               t->pakfire = NULL;
+       }
 
        // Cleanup root
        pakfire_rmtree(root, 0);