]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Give better names to assertions
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Jan 2021 12:59:47 +0000 (12:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Jan 2021 12:59:47 +0000 (12:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/arch.c
tests/libpakfire/archive.c
tests/libpakfire/execute.c
tests/libpakfire/key.c
tests/libpakfire/main.c
tests/libpakfire/makefile.c
tests/libpakfire/parser.c
tests/libpakfire/util.c
tests/testsuite.c
tests/testsuite.h

index 3a7aa6e46d510c4305f13192e4d667ce4414e61b..6b2737578131da725ac06e484fe870f183f2bcf3 100644 (file)
 static int test_native(const struct test* t) {
        // First call
        const char* arch1 = pakfire_arch_native();
-       assert_return(arch1, EXIT_FAILURE);
+       ASSERT(arch1);
 
        // Second call
        const char* arch2 = pakfire_arch_native();
-       assert_return(arch2, EXIT_FAILURE);
+       ASSERT(arch2);
 
        // Must be the same pointer
-       assert_return(arch1 == arch2, EXIT_FAILURE);
+       ASSERT(arch1 == arch2);
 
        return EXIT_SUCCESS;
 }
@@ -44,14 +44,14 @@ static int test_supported(const struct test* t) {
        int r;
 
        r = pakfire_arch_supported("x86_64");
-       assert_return(r, EXIT_FAILURE);
+       ASSERT(r);
 
        r = pakfire_arch_supported("i686");
-       assert_return(r, EXIT_FAILURE);
+       ASSERT(r);
 
        // Check non-existant architecture
        r = pakfire_arch_supported("ABC");
-       assert_return(!r, EXIT_FAILURE);
+       ASSERT(!r);
 
        return EXIT_SUCCESS;
 }
@@ -61,23 +61,23 @@ static int test_compatible(const struct test* t) {
 
        // x86_64 can build i686
        r = pakfire_arch_is_compatible("x86_64", "i686");
-       assert_return(r, EXIT_FAILURE); 
+       ASSERT(r);
 
        // i686 can NOT build i686
        r = pakfire_arch_is_compatible("i686", "x86_64");
-       assert_return(!r, EXIT_FAILURE);        
+       ASSERT(!r);
 
        // x86_64 can build itself
        r = pakfire_arch_is_compatible("x86_64", "x86_64");
-       assert_return(r, EXIT_FAILURE);
+       ASSERT(r);
 
        // x86_64 can NOT build a non-existant architecture
        r = pakfire_arch_is_compatible("x86_64", "ABC");
-       assert_return(!r, EXIT_FAILURE);
+       ASSERT(!r);
 
        // A non-existant architecture cannot build anything
        r = pakfire_arch_is_compatible("ABC", "x86_64");
-       assert_return(!r, EXIT_FAILURE);
+       ASSERT(!r);
 
        return EXIT_SUCCESS;
 }
@@ -86,10 +86,10 @@ static int test_machine(const struct test* t) {
        char* machine;
 
        machine = pakfire_arch_machine("x86_64", "ipfire");
-       assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(machine, "x86_64-ipfire-linux-gnu");
 
        machine = pakfire_arch_machine("x86_64", "IPFIRE");
-       assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(machine, "x86_64-ipfire-linux-gnu");
 
        return EXIT_SUCCESS;
 }
index 8f910f2bcd16a9f6034c5d09d1cc5a657f93a8ae..82074e60191f6a13dc9f19a70c34a6c8821c66ff 100644 (file)
@@ -36,11 +36,11 @@ static int test_open(const struct test* t) {
 
        // Open the archive
        PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
-       assert_return(archive, EXIT_FAILURE);
+       ASSERT(archive);
 
        // Verify the archive
        pakfire_archive_verify_status_t verify = pakfire_archive_verify(archive);
-       assert_return(verify == PAKFIRE_ARCHIVE_VERIFY_OK, EXIT_FAILURE);
+       ASSERT(verify == PAKFIRE_ARCHIVE_VERIFY_OK);
 
        pakfire_archive_unref(archive);
        pakfire_free(path);
@@ -56,11 +56,11 @@ static int test_extract(const struct test* t) {
 
        // Extract the archive payload
        int r = pakfire_archive_extract(archive, NULL, PAKFIRE_ARCHIVE_USE_PAYLOAD);
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Check if test file from the archive exists
-       assert_return(pakfire_access(t->pakfire, pakfire_get_path(t->pakfire),
-               TEST_PKG1_FILE, F_OK) == 0, EXIT_FAILURE);
+       ASSERT(pakfire_access(t->pakfire, pakfire_get_path(t->pakfire),
+               TEST_PKG1_FILE, F_OK) == 0);
 
        pakfire_archive_unref(archive);
 
@@ -74,10 +74,10 @@ static int test_import(const struct test* t) {
        pakfire_free(path);
 
        PakfireRepo repo = pakfire_repo_create(t->pakfire, "tmp");
-       assert_return(repo, EXIT_FAILURE);
+       ASSERT(repo);
 
        PakfirePackage pkg = pakfire_repo_add_archive(repo, archive);
-       assert_return(pkg, EXIT_FAILURE);
+       ASSERT(pkg);
 
        pakfire_repo_unref(repo);
        pakfire_package_unref(pkg);
index e6ae7dcb5d157e88c06d05f37acf0f5907a0647b..5b8358aa91a08e9fefe3c92ecc28b06941a395f5 100644 (file)
@@ -29,7 +29,7 @@ static int test_does_not_exist(const struct test* t) {
        const char* cmd = "/usr/bin/does-not-exist";
 
        int r = pakfire_execute(t->pakfire, cmd, NULL, NULL, 0);
-       assert_return(r != 0, EXIT_FAILURE);
+       ASSERT(r != 0);
 
        return EXIT_SUCCESS;
 }
index 2da8c7edd0193460524bc6168c5539f0f8e5c891..2b615ecc8ca8b1325f89535cc5da3dfab1de026f 100644 (file)
@@ -40,7 +40,7 @@ static int test_init(const struct test* t) {
        keys = pakfire_key_list(t->pakfire);
 
        // Must be empty now
-       assert_return(keys == NULL, EXIT_FAILURE);
+       ASSERT(keys == NULL);
 
        return EXIT_SUCCESS;
 }
@@ -58,16 +58,16 @@ static int test_import(const struct test* t) {
        PakfireKey* keys = pakfire_key_import(t->pakfire, TEST_KEY_DATA);
 
        // We should have a list with precisely one key object
-       assert_return(keys, EXIT_FAILURE);
-       assert_return(keys[0] != NULL, EXIT_FAILURE);
-       assert_return(keys[1] == NULL, EXIT_FAILURE);
+       ASSERT(keys);
+       ASSERT(keys[0] != NULL);
+       ASSERT(keys[1] == NULL);
 
        // Get the imported key
        key = *keys;
 
        // Check the fingerprint
        const char* fingerprint = pakfire_key_get_fingerprint(key);
-       assert_return(strcmp(fingerprint, TEST_KEY_FINGERPRINT) == 0, EXIT_FAILURE);
+       ASSERT(strcmp(fingerprint, TEST_KEY_FINGERPRINT) == 0);
 
        pakfire_key_unref(key);
 
@@ -76,16 +76,16 @@ static int test_import(const struct test* t) {
 
 static int test_export(const struct test* t) {
        PakfireKey key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
-       assert_return(key, EXIT_FAILURE);
+       ASSERT(key);
 
        // Dump key description
        char* dump = pakfire_key_dump(key);
-       assert_return(dump, EXIT_FAILURE);
+       ASSERT(dump);
        LOG("%s\n", dump);
        pakfire_free(dump);
 
        char* data = pakfire_key_export(key, 0);
-       assert_return(data, EXIT_FAILURE);
+       ASSERT(data);
 
        LOG("Exported key:\n%s\n", data);
        pakfire_free(data);
index 315a46578a7d2812a7a731ccf3a8fb6b03942042..001edf3ad966e82f27c2f561bae7d0ff4f5d7f65 100644 (file)
@@ -18,8 +18,6 @@
 #                                                                             #
 #############################################################################*/
 
-#include <string.h>
-
 #include <pakfire/pakfire.h>
 
 #include "../testsuite.h"
@@ -32,7 +30,7 @@ static int test_init(const struct test* t) {
 
 static int test_path(const struct test* t) {
        const char* path = pakfire_get_path(t->pakfire);
-       assert_return(strcmp(path, TEST_ROOTFS) == 0, EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(path, TEST_ROOTFS);
 
        return EXIT_SUCCESS;
 }
index 5dadedef99089ba9989c47ed930113a3905ac5c8..02205b0c09e946ab56cf9e0e48102768b7df1d4a 100644 (file)
@@ -30,16 +30,16 @@ static int test_parse(const struct test* t) {
 
        // Open file
        FILE* f = fopen(path, "r");
-       assert_return(f, EXIT_FAILURE);
+       ASSERT(f);
 
        PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
 
        int r = pakfire_parser_read(parser, f);
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Try to retrieve some value
        char* value = pakfire_parser_get(parser, "sources");
-       assert_return(value, EXIT_FAILURE);
+       ASSERT(value);
 
        printf("VALUE: sources = %s\n", value);
        pakfire_free(value);
index 32c22629dca5cbce834e2c08bf904df789ac71c9..cb23b2fede574b133e5acd68e6adc3125bc22c6f 100644 (file)
@@ -33,62 +33,62 @@ static int test_parser(const struct test* t) {
 
        // Retrieve a value that does not exist
        value = pakfire_parser_get(parser, "null");
-       assert_return(!value, EXIT_FAILURE);
+       ASSERT(!value);
 
        // Set a value
        int r = pakfire_parser_set(parser, "a", "a");
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Retrieve the value again
        value = pakfire_parser_get(parser, "a");
-       assert_compare(value, "a", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a");
 
        // Append something to the value
        r = pakfire_parser_append(parser, "a", "b");
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Retrieve the value again
        value = pakfire_parser_get(parser, "a");
-       assert_compare(value, "a b", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a b");
 
        // Make a child parser
        PakfireParser subparser = pakfire_parser_create_child(parser, "child");
-       assert_return(subparser, EXIT_FAILURE);
+       ASSERT(subparser);
 
        // Try to get a again
        value = pakfire_parser_get(subparser, "a");
-       assert_compare(value, "a b", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a b");
 
        // Append something to the subparser
        r = pakfire_parser_append(subparser, "a", "c");
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // The subparser should return "a b c"
        value = pakfire_parser_get(subparser, "a");
-       assert_compare(value, "a b c", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a b c");
 
        // The original parser should remain unchanged
        value = pakfire_parser_get(parser, "a");
-       assert_compare(value, "a b", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a b");
 
        // Set another value
        r = pakfire_parser_append(subparser, "b", "1");
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Merge the two parsers
        pakfire_parser_merge(parser, subparser);
 
        // Now a should have changed to "a b c"
        value = pakfire_parser_get(parser, "a");
-       assert_compare(value, "a b c", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "a b c");
 
        // Set a variable
        r = pakfire_parser_set(parser, "c", "%{b}");
-       assert_return(r == 0, EXIT_FAILURE);
+       ASSERT(r == 0);
 
        // Get the value of c
        value = pakfire_parser_get(parser, "c");
-       assert_compare(value, "1", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(value, "1");
 
        // Dump the parser
        char* s = pakfire_parser_dump(parser);
index 32b4fec1ac56d1d75b484f31bc8109379ec883e1..5021801a43cc7c9bbca98caf4851e13f186f5566 100644 (file)
@@ -29,7 +29,7 @@ static int test_basename(const struct test* t) {
        const char* dir = "/a/b/c";
 
        char* output = pakfire_basename(dir);
-       assert_compare(output, "c", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(output, "c");
        pakfire_free(output);
 
        return EXIT_SUCCESS;
@@ -39,7 +39,7 @@ static int test_dirname(const struct test* t) {
        const char* dir = "/a/b/c";
 
        char* output = pakfire_dirname(dir);
-       assert_compare(output, "/a/b", EXIT_FAILURE);
+       ASSERT_STRING_EQUALS(output, "/a/b");
        pakfire_free(output);
 
        return EXIT_SUCCESS;
@@ -49,10 +49,10 @@ static int test_string_startswith(const struct test* t) {
        int r;
 
        r = pakfire_string_startswith("ABC", "A");
-       assert_return(r, EXIT_FAILURE);
+       ASSERT(r);
 
        r = pakfire_string_startswith("ABC", "B");
-       assert_return(!r, EXIT_FAILURE);
+       ASSERT(!r);
 
        return EXIT_SUCCESS;
 }
index 72d2e36ab537e85a9148c23b35dbbf7bfe05c0be..e21d7625158eb7a4039badf2bdfa60fcc25898c8 100644 (file)
@@ -31,7 +31,7 @@ static int test_run(struct test* t) {
        LOG("running %s\n", t->name);
 
        t->pakfire = pakfire_create(TEST_ROOTFS, NULL);
-       assert_return(t->pakfire, EXIT_FAILURE);
+       ASSERT(t->pakfire);
 
        // Log to stderr
        pakfire_log_set_function(t->pakfire, pakfire_log_stderr);
index 33d4c9a20dae3d66814d329d7946a4e55670afc2..2723314ba092f6b6988ae354820e9f5c2dcc74cf 100644 (file)
@@ -54,21 +54,21 @@ int testsuite_run();
 
 #define testsuite_add_test(func) __testsuite_add_test(#func, func)
 
-#define assert_return(expr, r) \
+#define ASSERT(expr) \
        do { \
                if ((!(expr))) { \
                        LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return r; \
+                       return EXIT_FAILURE; \
                } \
        } while (0)
 
-#define assert_compare(string, value, r) \
+#define ASSERT_STRING_EQUALS(string, value) \
        do { \
                if (strcmp(string, value) != 0) { \
                        LOG_ERROR("Failed assertion: " #string " != " #value " %s:%d %s\n", \
                                __FILE__, __LINE__, __PRETTY_FUNCTION__); \
-                       return r; \
+                       return EXIT_FAILURE; \
                } \
        } while (0)