]> git.ipfire.org Git - pakfire.git/commitdiff
testsuite: Make tests cleanup after themselves
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 13:18:40 +0000 (13:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Sep 2021 13:18:40 +0000 (13:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
18 files changed:
tests/libpakfire/arch.c
tests/libpakfire/archive.c
tests/libpakfire/cgroup.c
tests/libpakfire/compress.c
tests/libpakfire/config.c
tests/libpakfire/db.c
tests/libpakfire/downloader.c
tests/libpakfire/execute.c
tests/libpakfire/key.c
tests/libpakfire/main.c
tests/libpakfire/makefile.c
tests/libpakfire/packager.c
tests/libpakfire/parser.c
tests/libpakfire/progressbar.c
tests/libpakfire/repo.c
tests/libpakfire/util.c
tests/testsuite.c
tests/testsuite.h

index aa3097bda63d8f3e549fec6e1258c596f2266cbd..b35006604c56f2a6415ccbb6ce4eac52df32d569 100644 (file)
@@ -38,6 +38,9 @@ static int test_native(const struct test* t) {
        ASSERT(arch1 == arch2);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_SUCCESS;
 }
 
 static int test_supported(const struct test* t) {
@@ -54,6 +57,9 @@ static int test_supported(const struct test* t) {
        ASSERT(!r);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_SUCCESS;
 }
 
 static int test_compatible(const struct test* t) {
@@ -80,6 +86,9 @@ static int test_compatible(const struct test* t) {
        ASSERT(!r);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_SUCCESS;
 }
 
 static int test_machine(const struct test* t) {
@@ -95,6 +104,9 @@ static int test_machine(const struct test* t) {
        ASSERT(r == 0);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_SUCCESS;
 }
 
 int main(int argc, char** argv) {
index b3e09ef4ba9f5caf2e5e1258958f1c0a5d6c01b8..64de50b7c682e9aaf422da275033462bef343712 100644 (file)
 #define TEST_PKG1_FILE "usr/bin/beep"
 
 static int test_open(const struct test* t) {
+       struct pakfire_archive* archive = NULL;
+       int r = EXIT_FAILURE;
+
        const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
        LOG("Trying to open %s\n", path);
 
        // Open the archive
-       struct pakfire_archive* archive;
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
 
        pakfire_archive_verify_status_t status;
@@ -45,40 +47,55 @@ static int test_open(const struct test* t) {
        ASSERT(pakfire_archive_verify(archive, &status, NULL) == 0);
        ASSERT(status == PAKFIRE_ARCHIVE_VERIFY_OK);
 
-       pakfire_archive_unref(archive);
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (archive)
+               pakfire_archive_unref(archive);
 
-       return EXIT_SUCCESS;
+       return r;
 }
 
 static int test_filelist(const struct test* t) {
        const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+       int r = EXIT_FAILURE;
+
+       struct pakfire_archive* archive = NULL;
+       struct pakfire_filelist* list = NULL;
 
        // Open the archive
-       struct pakfire_archive* archive;
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
 
        // Fetch the filelist
-       struct pakfire_filelist* list = pakfire_archive_get_filelist(archive);
+       list = pakfire_archive_get_filelist(archive);
        ASSERT(list);
 
        // This packages has 7 files
        ASSERT(pakfire_filelist_size(list) == 7);
 
-       // Cleanup
-       pakfire_filelist_unref(list);
-       pakfire_archive_unref(archive);
-       return EXIT_SUCCESS;
+       // Everything passed
+       r =  EXIT_SUCCESS;
+
+FAIL:
+       if (list)
+               pakfire_filelist_unref(list);
+       if (archive)
+               pakfire_archive_unref(archive);
+
+       return r;
 }
 
 static int test_extract(const struct test* t) {
        const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+       int r = EXIT_FAILURE;
+
+       struct pakfire_archive* archive = NULL;
 
-       struct pakfire_archive* archive;
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
 
        // Extract the archive payload
-       int r = pakfire_archive_extract(archive, NULL);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_archive_extract(archive, NULL));
 
 #if 0
        char file[PATH_MAX];
@@ -88,34 +105,47 @@ static int test_extract(const struct test* t) {
        ASSERT_SUCCESS(access(file, F_OK));
 #endif
 
-       pakfire_archive_unref(archive);
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (archive)
+               pakfire_archive_unref(archive);
+
+       return r;
 }
 
 static int test_import(const struct test* t) {
        const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+       int r = EXIT_FAILURE;
 
-       struct pakfire_archive* archive;
-       ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
-
+       struct pakfire_archive* archive = NULL;
        struct pakfire_repo* repo = NULL;
+       struct pakfire_package* package = NULL;
+
+       // Open archive
+       ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
+       ASSERT(archive);
 
        // Create a new repository
        ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "tmp"));
        ASSERT(repo);
 
-       struct pakfire_package* package = NULL;
-
        // Add the package to the repository
        ASSERT_SUCCESS(pakfire_repo_add_archive(repo, archive, &package));
        ASSERT(package);
 
-       pakfire_repo_unref(repo);
-       pakfire_package_unref(package);
-       pakfire_archive_unref(archive);
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (repo)
+               pakfire_repo_unref(repo);
+       if (package)    
+               pakfire_package_unref(package);
+       if (archive)
+               pakfire_archive_unref(archive);
 
-       return EXIT_SUCCESS;
+       return r;
 }
 
 int main(int argc, char** argv) {
index 61502d95540228f10e277b0376629371f350bebf..5cc8b61f7f5f503008c5a9807419f89b7077ed3f 100644 (file)
@@ -36,6 +36,9 @@ static int test_create_and_destroy(const struct test* t) {
        );
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_attach(const struct test* t) {
@@ -75,6 +78,9 @@ static int test_attach(const struct test* t) {
        );
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static void handle_signal(int signum) {
@@ -107,6 +113,9 @@ static pid_t fork_child_process() {
                return child_process();
 
        return pid;
+
+FAIL:
+       abort();
 }
 
 static int test_killall(const struct test* t) {
@@ -132,6 +141,9 @@ static int test_killall(const struct test* t) {
        );
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_cpustat(const struct test* t) {
@@ -165,6 +177,9 @@ static int test_cpustat(const struct test* t) {
        );
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_nice(const struct test* t) {
@@ -182,6 +197,9 @@ static int test_nice(const struct test* t) {
        );
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_random_name(const struct test* t) {
@@ -195,6 +213,9 @@ static int test_random_name(const struct test* t) {
        ASSERT_STRING_NOT_EQUALS(name1, name2);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 int main(int argc, char** argv) {
index a6c153f12550d765fdf60f18a4c6bea22394dbc8..d9a46b1f600950b26ad360e5121104c5dbbe4ae2 100644 (file)
@@ -31,14 +31,17 @@ const char TEST_DATA[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
 
 static int read_test(const struct test* t,
                FILE* (function)(FILE* f, const char* mode), const char* file) {
+       int r = EXIT_FAILURE;
+
+       FILE* f = NULL;
        char path[PATH_MAX];
        char buffer[1024];
 
-       int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, file);
+       r = pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file);
        ASSERT(r >= 0);
 
-       FILE* f = fopen(path, "r");
-       ASSERT(f);
+       // Open file
+       ASSERT(f = fopen(path, "r"));
 
        // Engage decompressor
        f = function(f, "r");
@@ -50,17 +53,25 @@ static int read_test(const struct test* t,
 
        // Buffer should equal the test data
        ASSERT(bytes_read >= sizeof(TEST_DATA) - 1);
-       ASSERT(memcmp(buffer, TEST_DATA, sizeof(TEST_DATA) - 1) == 0);
+       ASSERT_SUCCESS(memcmp(buffer, TEST_DATA, sizeof(TEST_DATA) - 1));
 
-       fclose(f);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (f)
+               fclose(f);
+
+       return r;
 }
 
 static int write_test(const struct test* t, FILE* (function)(FILE* f, const char* mode)) {
+       int r = EXIT_FAILURE;
+
+       FILE* f = NULL;
+
        // Create a backend storage file
-       FILE* f = test_mktemp();
-       ASSERT(f);
+       ASSERT(f = test_mktemp());
 
        // Open compressed file for writing
        f = function(f, "w");
@@ -72,9 +83,14 @@ static int write_test(const struct test* t, FILE* (function)(FILE* f, const char
                ASSERT(bytes_written == sizeof(TEST_DATA) - 1);
        }
 
-       fclose(f);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (f)
+               fclose(f);
+
+       return r;
 }
 
 static int test_xzfopen_read(const struct test* t) {
@@ -94,10 +110,13 @@ static int test_zstdfopen_write(const struct test* t) {
 }
 
 static int test_xfopen(const struct test* t) {
-       ASSERT(read_test(t, pakfire_xfopen, "data/compress/data.xz") == EXIT_SUCCESS);
-       ASSERT(read_test(t, pakfire_xfopen, "data/compress/data.zst") == EXIT_SUCCESS);
+       ASSERT_SUCCESS(read_test(t, pakfire_xfopen, "data/compress/data.xz"));
+       ASSERT_SUCCESS(read_test(t, pakfire_xfopen, "data/compress/data.zst"));
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 int main(int argc, char** argv) {
index fa8c8f98ec754d9a8afb29037151b749260dcde5..f2d4daaf86171b497423c5ea7e49f2cedf940c47 100644 (file)
@@ -23,7 +23,8 @@
 #include "../testsuite.h"
 
 static int test_get_and_set(const struct test* t) {
-       struct pakfire_config* config;
+       struct pakfire_config* config = NULL;
+       int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_config_create(&config));
 
@@ -63,12 +64,17 @@ static int test_get_and_set(const struct test* t) {
        ASSERT(pakfire_config_has_section(config, "section1"));
        ASSERT(!pakfire_config_has_section(config, "section3"));
 
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
        pakfire_config_unref(config);
 
-       return EXIT_SUCCESS;
+       return r;
 }
 
 static int test_parse(const struct test* t) {
+       int r = EXIT_FAILURE;
        char* TEST_INPUT =
                "key1 = value1\n"
                "\n"
@@ -83,7 +89,7 @@ static int test_parse(const struct test* t) {
        FILE* f = fmemopen(TEST_INPUT, strlen(TEST_INPUT), "r");
        ASSERT(f);
 
-       struct pakfire_config* config;
+       struct pakfire_config* config = NULL;
 
        ASSERT_SUCCESS(pakfire_config_create(&config));
        ASSERT_SUCCESS(pakfire_config_read(config, f));
@@ -110,11 +116,15 @@ static int test_parse(const struct test* t) {
        ASSERT_STRING_EQUALS(sections[1], "section2");
        ASSERT_NULL(sections[2]);
 
-       pakfire_config_unref(config);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       fclose(f);
+FAIL:
+       if (f)
+               fclose(f);
+       pakfire_config_unref(config);
 
-       return EXIT_SUCCESS;
+       return r;
 }
 
 int main(int argc, char** argv) {
index aa595c78eea59ef590b7be1ba02becb42f248691..6bcc607693cee1864b272d422006b451ad6ec220 100644 (file)
 #include "../testsuite.h"
 
 static int test_open_ro(const struct test* t) {
-       struct pakfire_db* db;
+       struct pakfire_db* db = NULL;
+       int r = EXIT_FAILURE;
 
-       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READONLY);
-       ASSERT(!r);
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READONLY));
 
-       pakfire_db_unref(db);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return 0;
+FAIL:
+       if (db)
+               pakfire_db_unref(db);
+
+       return r;
 }
 
 static int test_open_rw(const struct test* t) {
-       struct pakfire_db* db;
+       struct pakfire_db* db = NULL;
+       int r = EXIT_FAILURE;
+
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
 
-       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
-       ASSERT(!r);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       pakfire_db_unref(db);
+FAIL:
+       if (db)
+               pakfire_db_unref(db);
 
-       return 0;
+       return r;
 }
 
 static int test_check(const struct test* t) {
-       struct pakfire_db* db;
+       struct pakfire_db* db = NULL;
+       int r = EXIT_FAILURE;
 
-       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
-       ASSERT(!r);
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
 
        // Perform check
-       ASSERT(!pakfire_db_check(db));
+       ASSERT_SUCCESS(pakfire_db_check(db));
+
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       pakfire_db_unref(db);
+FAIL:
+       if (db)
+               pakfire_db_unref(db);
 
-       return 0;
+       return r;
 }
 
 static int test_add_package(const struct test* t) {
-       struct pakfire_db* db;
+       struct pakfire_db* db = NULL;
+       struct pakfire_repo* repo = NULL;
+       struct pakfire_archive* archive = NULL;
+       int r = EXIT_FAILURE;
 
-       struct pakfire_repo* repo = pakfire_get_repo(t->pakfire, "@dummy");
-       ASSERT(repo);
+       ASSERT(repo = pakfire_get_repo(t->pakfire, "@dummy"));
 
-       int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
-       ASSERT(!r);
+       ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
 
        // There must be no packages installed
        ssize_t packages = pakfire_db_packages(db);
@@ -78,7 +94,6 @@ static int test_add_package(const struct test* t) {
        const char* path = TEST_SRC_PATH "/data/beep-1.3-2.ip3.x86_64.pfm";
 
        // Open archive
-       struct pakfire_archive* archive;
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
        ASSERT(archive);
 
@@ -89,28 +104,31 @@ static int test_add_package(const struct test* t) {
        ASSERT(package);
 
        // Try to add the package to the database
-       r = pakfire_db_add_package(db, package, archive, 1);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_db_add_package(db, package, archive, 1));
 
        // One package should be installed
-       packages = pakfire_db_packages(db);
-       ASSERT(packages == 1);
+       ASSERT(pakfire_db_packages(db) == 1);
 
        // Remove the package again
-       r = pakfire_db_remove_package(db, package);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_db_remove_package(db, package));
 
        // No packages should be installed any more
-       packages = pakfire_db_packages(db);
-       ASSERT(packages == 0);
-
-       // Cleanup
-       pakfire_archive_unref(archive);
-       pakfire_db_unref(db);
-       pakfire_package_unref(package);
-       pakfire_repo_unref(repo);
-
-       return 0;
+       ASSERT(pakfire_db_packages(db) == 0);
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (archive)
+               pakfire_archive_unref(archive);
+       if (db)
+               pakfire_db_unref(db);
+       if (package)
+               pakfire_package_unref(package);
+       if (repo)
+               pakfire_repo_unref(repo);
+
+       return r;
 }
 
 int main(int argc, char** argv) {
index febb25ee8308bc3b52564f5af7aa92f232c55860..5fe0bd3fa87abd8269f72ae95e4de6516c9a504f 100644 (file)
 #define DOWNLOAD_PATH TEST_ROOTFS "/downloaded.file"
 
 static int test_simple(const struct test* t) {
-       struct pakfire_downloader* d;
+       struct pakfire_downloader* d = NULL;
+       int r = EXIT_FAILURE;
 
        // Create downloader
-       int r = pakfire_downloader_create(&d, t->pakfire);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
 
        // Retrieve a file
-       r = pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
-               PAKFIRE_DIGEST_NONE, NULL, 0, 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(
+               pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+                       PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+       );
 
-       // Cleanup
-       pakfire_downloader_unref(d);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (d)
+               pakfire_downloader_unref(d);
+
+       return r;
 }
 
 static int test_retrieve_with_pending_transfers(const struct test* t) {
-       struct pakfire_downloader* d;
+       struct pakfire_downloader* d = NULL;
+       int r = EXIT_FAILURE;
 
        // Create downloader
-       int r = pakfire_downloader_create(&d, t->pakfire);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
 
        // Add a transfer
-       r = pakfire_downloader_add_transfer(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
-               PAKFIRE_DIGEST_NONE, NULL, 0, 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(
+               pakfire_downloader_add_transfer(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+                       PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+       );
 
        // Retrieve a file
-       r = pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
-               PAKFIRE_DIGEST_NONE, NULL, 0, 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(
+               pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+                       PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+       );
+
 
-       // Cleanup
-       pakfire_downloader_unref(d);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (d)
+               pakfire_downloader_unref(d);
+
+       return r;
 }
 
 static int test_retrieve_with_mirrors(const struct test* t) {
-       struct pakfire_downloader* d;
-       struct pakfire_mirrorlist* m;
+       struct pakfire_downloader* d = NULL;
+       struct pakfire_mirrorlist* m = NULL;
+       int r = EXIT_FAILURE;
 
        // Create downloader
-       int r = pakfire_downloader_create(&d, t->pakfire);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
 
        // Create mirrorlist
        ASSERT_SUCCESS(pakfire_mirrorlist_create(&m, t->pakfire));
@@ -93,11 +105,16 @@ static int test_retrieve_with_mirrors(const struct test* t) {
        ASSERT_SUCCESS(pakfire_downloader_retrieve(d, NULL, m,
                NULL, "beep-1.3-2.ip3.x86_64.pfm", DOWNLOAD_PATH, PAKFIRE_DIGEST_NONE, NULL, 0, 0));
 
-       // Cleanup
-       ASSERT_NULL(pakfire_mirrorlist_unref(m));
-       ASSERT_NULL(pakfire_downloader_unref(d));
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (d)
+               pakfire_downloader_unref(d);
+       if (m)
+               pakfire_mirrorlist_unref(m);
 
-       return 0;
+       return r;
 }
 
 int main(int argc, char** argv) {
index 2775983bd3cfb770ced3d6181085f3d88568ff4e..823646513f9960686b80ee6b6e0e5ed04fa3ffe0 100644 (file)
@@ -30,10 +30,12 @@ static const char* cmd[2] = {
 };
 
 static int test_does_not_exist(const struct test* t) {
-       int r = pakfire_execute(t->pakfire, cmd, NULL, 0, NULL, NULL);
-       ASSERT(r != 0);
+       ASSERT_FAILURE(pakfire_execute(t->pakfire, cmd, NULL, 0, NULL, NULL));
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 int main(int argc, char** argv) {
index 29f9a7e49ca1368f1eaff83b8dc6d79acc6013bf..b6fa3904ede5438aa25e9e82f044f181e68b01c9 100644 (file)
@@ -29,6 +29,7 @@
 
 static int test_init(const struct test* t) {
        struct pakfire_key** keys = NULL;
+       int r = EXIT_FAILURE;
 
        // Try loading any keys & delete them all
        ASSERT_SUCCESS(pakfire_list_keys(t->pakfire, &keys));
@@ -45,7 +46,11 @@ static int test_init(const struct test* t) {
        // Must be empty now
        ASSERT(keys == NULL);
 
-       return EXIT_SUCCESS;
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       return r;
 }
 
 static int test_import_export(const struct test* t) {
index ccb1fbdb870b8a3628f0dff380976701ddf5d115..7b84782924ae5d631310eda0c122a3202af71121 100644 (file)
@@ -33,6 +33,9 @@ static int test_path(const struct test* t) {
        ASSERT_STRING_STARTSWITH(path, TEST_ROOTFS);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 int main(int argc, char** argv) {
index 6a44c3939388c64393d30d1fd9d31da8bfbab1f2..4ec9ef7960af4c23941c9d27efe43976b32785e3 100644 (file)
@@ -44,16 +44,22 @@ static int load_macros(struct pakfire_parser* parser) {
        ASSERT(r == 0);
 
        for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
-               r = pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL);
-               ASSERT(r == 0);
+               ASSERT_SUCCESS(
+                       pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL)
+               );
        }
 
-       return 0;
+       return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_parse(const struct test* t) {
+       struct pakfire_parser* parser = NULL;
        const char** makefile = makefiles;
        char path[PATH_MAX];
+       int r = EXIT_FAILURE;
 
        while (*makefile) {
                int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *makefile);
@@ -63,43 +69,57 @@ static int test_parse(const struct test* t) {
                FILE* f = fopen(path, "r");
                ASSERT(f);
 
-               struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
+               parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
 
-               r = pakfire_parser_read(parser, f, NULL);
-               ASSERT(r == 0);
+               ASSERT_SUCCESS(pakfire_parser_read(parser, f, NULL));
 
                pakfire_parser_unref(parser);
+               parser = NULL;
                fclose(f);
 
                // Next file
                makefile++;
        }
 
-       return EXIT_SUCCESS;
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (parser)
+               pakfire_parser_unref(parser);
+
+       return r;
 }
 
 static int test_macros(const struct test* t) {
+       int r = EXIT_FAILURE;
+
        struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
        ASSERT(parser);
 
        // Load 'em all
-       int r = load_macros(parser);
-       if (r)
-               return r;
+       ASSERT_SUCCESS(load_macros(parser));
 
-       pakfire_parser_unref(parser);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (parser)
+               pakfire_parser_unref(parser);
+
+       return r;
 }
 
 static int test_packages(const struct test* t) {
+       struct pakfire_parser* parser = NULL;
        struct pakfire_package* pkg = NULL;
        struct pakfire_repo* repo = NULL;
+       int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
        ASSERT(repo);
 
-       struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL,
+       parser = pakfire_parser_create(t->pakfire, NULL, NULL,
                PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
        ASSERT(parser);
 
@@ -107,15 +127,12 @@ static int test_packages(const struct test* t) {
        pakfire_parser_set(parser, NULL, "DISTRO_ARCH", "x86_64", 0);
 
        // Load macros
-       int r = load_macros(parser);
-       if (r)
-               return r;
+       ASSERT_SUCCESS(load_macros(parser));
 
        // Read beep.nm
        const char* path = TEST_SRC_PATH "data/beep.nm";
 
-       r = pakfire_parser_read_file(parser, path, NULL);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_read_file(parser, path, NULL));
 
        // Create package
        r = pakfire_parser_create_package(parser, &pkg, repo, NULL, NULL);
@@ -132,12 +149,18 @@ static int test_packages(const struct test* t) {
        const char* name = pakfire_package_get_name(pkg);
        ASSERT_STRING_EQUALS(name, "beep");
 
-       // Cleanup
-       pakfire_parser_unref(parser);
-       pakfire_package_unref(pkg);
-       pakfire_repo_unref(repo);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (parser)
+               pakfire_parser_unref(parser);
+       if (pkg)
+               pakfire_package_unref(pkg);
+       if (repo)
+               pakfire_repo_unref(repo);
+
+       return r;
 }
 
 int main(int argc, char** argv) {
index 05f81ba2ad3226284ce6f7335969bc99a00099b9..73afb38d4eb59b7bcc0a21749ad7811f216001b3 100644 (file)
 #include "../testsuite.h"
 
 static int test_create(const struct test* t) {
-       struct pakfire_packager* packager;
+       struct pakfire_packager* packager = NULL;
+       struct pakfire_package* pkg = NULL;
        struct pakfire_repo* repo = NULL;
+       int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
        ASSERT(repo);
 
-       struct pakfire_package* pkg = pakfire_package_create(t->pakfire, repo,
+       pkg = pakfire_package_create(t->pakfire, repo,
                "test", "1.0-1", "src");
        ASSERT(pkg);
 
        // Create packager
-       int r = pakfire_packager_create(&packager, pkg);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_packager_create(&packager, pkg));
 
        // Add a file to the package
        const char* path = TEST_SRC_PATH "data/beep-1.3-2.ip3.x86_64.pfm";
 
-       r = pakfire_packager_add(packager, path, NULL);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_packager_add(packager, path, NULL));
 
        // Write archive
        FILE* f = test_mktemp();
        r = pakfire_packager_finish(packager, f);
        ASSERT(r == 0);
 
-       // Cleanup
-       pakfire_packager_unref(packager);
-       pakfire_package_unref(pkg);
-       pakfire_repo_unref(repo);
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (packager)
+               pakfire_packager_unref(packager);
+       if (pkg)
+               pakfire_package_unref(pkg);
+       if (repo)
+               pakfire_repo_unref(repo);
 
        return EXIT_SUCCESS;
 }
index f77c07931446a8f409747d316143cce0df83d3c2..52d0a312a6d877259ac8d10004ef548450ac2444 100644 (file)
@@ -28,7 +28,9 @@
 #include "../testsuite.h"
 
 static int test_parser(const struct test* t) {
+       struct pakfire_parser* subparser = NULL;
        char* value = NULL;
+       int r = EXIT_FAILURE;
 
        // Create a new parser
        struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
@@ -38,23 +40,21 @@ static int test_parser(const struct test* t) {
        ASSERT(!value);
 
        // Set a value
-       int r = pakfire_parser_set(parser, NULL, "a", "a", 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "a", "a", 0));
 
        // Retrieve the value again
        value = pakfire_parser_get(parser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a");
 
        // Append something to the value
-       r = pakfire_parser_append(parser, NULL, "a", "b");
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_append(parser, NULL, "a", "b"));
 
        // Retrieve the value again
        value = pakfire_parser_get(parser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Make a child parser
-       struct pakfire_parser* subparser = pakfire_parser_create_child(parser, "child");
+       subparser = pakfire_parser_create_child(parser, "child");
        ASSERT(subparser);
 
        // Try to get a again
@@ -62,8 +62,7 @@ static int test_parser(const struct test* t) {
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Append something to the subparser
-       r = pakfire_parser_append(subparser, NULL, "a", "c");
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_append(subparser, NULL, "a", "c"));
 
        // The subparser should return "a b c"
        value = pakfire_parser_get(subparser, NULL, "a");
@@ -74,15 +73,13 @@ static int test_parser(const struct test* t) {
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Set another value
-       r = pakfire_parser_append(subparser, NULL, "b", "1");
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_append(subparser, NULL, "b", "1"));
 
        // Merge the two parsers
        pakfire_parser_merge(parser, subparser);
 
        // Set a variable
-       r = pakfire_parser_set(parser, NULL, "c", "%{b}", 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "c", "%{b}", 0));
 
        // Get the value of c
        value = pakfire_parser_get(parser, NULL, "c");
@@ -92,12 +89,18 @@ static int test_parser(const struct test* t) {
        char* s = pakfire_parser_dump(parser);
        printf("%s\n", s);
 
-       // Cleanup
-       pakfire_parser_unref(subparser);
-       pakfire_parser_unref(parser);
-       free(value);
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (subparser)
+               pakfire_parser_unref(subparser);
+       if (parser)
+               pakfire_parser_unref(parser);
+       if (value)
+               free(value);
+
+       return r;
 }
 
 static const char* files[] = {
@@ -114,6 +117,7 @@ static const char* files[] = {
 static int test_parser_files(const struct test* t) {
        const char** file = files;
        char path[PATH_MAX];
+       int r = EXIT_FAILURE;
 
        while (*file) {
                int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *file);
@@ -138,25 +142,36 @@ static int test_parser_files(const struct test* t) {
                file++;
        }
 
-       return EXIT_SUCCESS;
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       return r;
 }
 
 static int test_parser_command(const struct test* t) {
        const char* command = "%(echo \"ABC\")";
+       struct pakfire_parser* parser = NULL;
+       int r = EXIT_FAILURE;
 
-       struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL,
+       parser = pakfire_parser_create(t->pakfire, NULL, NULL,
                PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
        ASSERT(parser);
 
-       ASSERT(pakfire_parser_set(parser, NULL, "command", command, 0) == 0);
+       ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "command", command, 0));
 
        // Retrieve the expanded value
        char* value = pakfire_parser_get(parser, NULL, "command");
        ASSERT_STRING_EQUALS(value, "ABC");
 
-       pakfire_parser_unref(parser);
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (parser)
+               pakfire_parser_unref(parser);
 
-       return EXIT_SUCCESS;
+       return r;
 }
 
 int main(int argc, char** argv) {
index 03ba54ba285f61a789165496b71474f9c8b9ab34..0d0bc8286ac08bcf1106aa211f2bb36bbf6beadd 100644 (file)
@@ -27,7 +27,8 @@
 #include "../testsuite.h"
 
 static int test_run(const struct test* t) {
-       struct pakfire_progressbar* p;
+       struct pakfire_progressbar* p = NULL;
+       int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_progressbar_create(&p, NULL));
 
@@ -57,9 +58,14 @@ static int test_run(const struct test* t) {
 
        ASSERT_SUCCESS(pakfire_progressbar_finish(p));
 
-       ASSERT_NULL(pakfire_progressbar_unref(p));
+       // Everything passed
+       r = EXIT_SUCCESS;
 
-       return EXIT_SUCCESS;
+FAIL:
+       if (p)
+               pakfire_progressbar_unref(p);
+
+       return r;
 }
 
 int main(int argc, char** argv) {
index c28564f7f71f1b166fe8dc54eda94fa4264f5f4b..cbf06ae1ce6ac08af75f07fd7b8e925e299204d3 100644 (file)
 #include "../testsuite.h"
 
 static int test_scan(const struct test* t) {
+       struct pakfire_repo* repo = NULL;
        char baseurl[1024];
-       snprintf(baseurl, sizeof(baseurl) - 1, "file://%s/data", TEST_SRC_PATH);
+       int r = EXIT_FAILURE;
 
-       struct pakfire_repo* repo = NULL;
+       pakfire_string_format(baseurl, "file://%s/data", TEST_SRC_PATH);
 
        ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
        ASSERT(repo);
 
-       pakfire_repo_set_baseurl(repo, baseurl);
+       ASSERT_SUCCESS(pakfire_repo_set_baseurl(repo, baseurl));
 
-       int r = pakfire_repo_scan(repo, 0);
-       ASSERT(r == 0);
+       ASSERT_SUCCESS(pakfire_repo_scan(repo, 0));
 
        // There should be one package in this repository now
        ASSERT(pakfire_repo_count(repo) == 1);
 
-       pakfire_repo_unref(repo);
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (repo)
+               pakfire_repo_unref(repo);
 
-       return 0;
+       return r;
 }
 
 int main(int argc, char** argv) {
index 2f7f47ceac531f962a642848cba2dfc627d2b089..c36bb06ba91e2ec3d8f9704a888b270ae167925a 100644 (file)
@@ -35,6 +35,9 @@ static int test_basename(const struct test* t) {
        free(output);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_dirname(const struct test* t) {
@@ -45,18 +48,19 @@ static int test_dirname(const struct test* t) {
        free(output);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_string_startswith(const struct test* t) {
-       int r;
-
-       r = pakfire_string_startswith("ABC", "A");
-       ASSERT(r);
-
-       r = pakfire_string_startswith("ABC", "B");
-       ASSERT(!r);
+       ASSERT_SUCCESS(pakfire_string_startswith("ABC", "A"));
+       ASSERT_FAILURE(pakfire_string_startswith("ABC", "B"));
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_string_partition(const struct test* t) {
@@ -106,6 +110,9 @@ static int test_string_partition(const struct test* t) {
        free(part2);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_string_replace(const struct test* t) {
@@ -115,6 +122,9 @@ static int test_string_replace(const struct test* t) {
        ASSERT_STRING_EQUALS(result, "CCCCCCCCCCCC");
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 static int test_string_split(const struct test* t) {
@@ -150,6 +160,9 @@ static int test_string_split(const struct test* t) {
        ASSERT_NULL(result[4]);
 
        return EXIT_SUCCESS;
+
+FAIL:
+       return EXIT_FAILURE;
 }
 
 int main(int argc, char** argv) {
index 492f0bc5a1467c44a4295b933cb07c6d9c76ce5c..20594be8c36ee78c241a0bb142c854a6ad991f5a 100644 (file)
@@ -52,8 +52,6 @@ static int test_run(int i, struct test* t) {
                exit(1);
        }
 
-       ASSERT(t->pakfire);
-
        // Enable debug logging
        pakfire_log_set_priority(t->pakfire, LOG_DEBUG);
 
index ba7b95a71a8162f7259dd253e7946f2ae0f8a8be..2f4cb655e73188fc9f786b1e993b9c2868a4c71c 100644 (file)
@@ -60,7 +60,7 @@ int testsuite_run();
                if ((!(expr))) { \
                        LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -69,7 +69,7 @@ int testsuite_run();
                if (!((expr) == NULL)) { \
                        LOG_ERROR("Failed assertion: " #expr " == NULL %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -78,7 +78,7 @@ int testsuite_run();
                if ((expr)) { \
                        LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -87,7 +87,7 @@ int testsuite_run();
                if ((expr) > 0) { \
                        LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -96,13 +96,13 @@ int testsuite_run();
                if (!(expr)) { \
                        LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
                if (errno != e) { \
                        LOG_ERROR("Failed assertion: " #expr " failed with (%d - %s) " \
                                "but was expected to fail with (%d - %s) in %s:%d\n", \
                                errno, strerror(errno), e, strerror(e), __FILE__, __LINE__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -111,7 +111,7 @@ int testsuite_run();
                if (strcmp(string, value) != 0) { \
                        LOG_ERROR("Failed assertion: " #value " (%s) != " #string " %s:%d %s\n", \
                                value, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -120,7 +120,7 @@ int testsuite_run();
                if (strcmp(value1, value2) == 0) { \
                        LOG_ERROR("Failed assertion: " #value1 " (%s) != " #value2 " (%s) %s:%d %s\n", \
                                value1, value2, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)
 
@@ -129,7 +129,7 @@ int testsuite_run();
                if (strncmp(string, start, strlen(start)) != 0) { \
                        LOG_ERROR("Failed assertion: " #string " does not start with " #start " %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return EXIT_FAILURE; \
+                       goto FAIL; \
                } \
        } while (0)