diff options
Diffstat (limited to 'tests/blogc-make')
-rw-r--r-- | tests/blogc-make/check_atom.c | 195 | ||||
-rw-r--r-- | tests/blogc-make/check_exec.c | 115 | ||||
-rw-r--r-- | tests/blogc-make/check_rules.c | 81 | ||||
-rw-r--r-- | tests/blogc-make/check_settings.c | 187 | ||||
-rw-r--r-- | tests/blogc-make/check_utils.c | 3 |
5 files changed, 284 insertions, 297 deletions
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c index 94c9a37..e9e24d3 100644 --- a/tests/blogc-make/check_atom.c +++ b/tests/blogc-make/check_atom.c @@ -10,26 +10,23 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> - #include <stdlib.h> #include <string.h> +#include <squareball.h> #include "../../src/blogc-make/atom.h" #include "../../src/blogc-make/settings.h" -#include "../../src/common/file.h" -#include "../../src/common/error.h" -#include "../../src/common/utils.h" static void test_atom_generate_empty_file(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); char *cmp = bm_atom_generate(settings); @@ -68,7 +65,7 @@ test_atom_generate_empty_file(void **state) "</feed>\n"); free(cmp); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -76,12 +73,12 @@ test_atom_generate_empty_file(void **state) static void test_atom_generate_empty_dir(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html")); char *cmp = bm_atom_generate(settings); @@ -120,7 +117,7 @@ test_atom_generate_empty_dir(void **state) "</feed>\n"); free(cmp); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -128,12 +125,12 @@ test_atom_generate_empty_dir(void **state) static void test_atom_generate_file(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); char *cmp = bm_atom_generate(settings); @@ -172,7 +169,7 @@ test_atom_generate_file(void **state) "</feed>\n"); free(cmp); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -180,12 +177,12 @@ test_atom_generate_file(void **state) static void test_atom_generate_dir(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html")); char *cmp = bm_atom_generate(settings); @@ -224,7 +221,7 @@ test_atom_generate_dir(void **state) "</feed>\n"); free(cmp); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -232,21 +229,21 @@ test_atom_generate_dir(void **state) static void test_atom_empty_file(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_non_null(rv); assert_null(err); size_t cmp_len; - char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err); assert_non_null(cmp); assert_null(err); @@ -286,7 +283,7 @@ test_atom_empty_file(void **state) free(cmp); bm_atom_destroy(rv); free(rv); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -294,21 +291,21 @@ test_atom_empty_file(void **state) static void test_atom_empty_dir(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_non_null(rv); assert_null(err); size_t cmp_len; - char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err); assert_non_null(cmp); assert_null(err); @@ -348,7 +345,7 @@ test_atom_empty_dir(void **state) free(cmp); bm_atom_destroy(rv); free(rv); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -356,21 +353,21 @@ test_atom_empty_dir(void **state) static void test_atom_file(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_non_null(rv); assert_null(err); size_t cmp_len; - char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err); assert_non_null(cmp); assert_null(err); @@ -410,7 +407,7 @@ test_atom_file(void **state) free(cmp); bm_atom_destroy(rv); free(rv); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -418,21 +415,21 @@ test_atom_file(void **state) static void test_atom_dir(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_non_null(rv); assert_null(err); size_t cmp_len; - char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err); + char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err); assert_non_null(cmp); assert_null(err); @@ -472,7 +469,7 @@ test_atom_dir(void **state) free(cmp); bm_atom_destroy(rv); free(rv); - bc_trie_free(settings->settings); + sb_trie_free(settings->settings); free(settings); } @@ -480,27 +477,26 @@ test_atom_dir(void **state) static void test_atom_legacy_entry_id_empty(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); - bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); + sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_null(rv); assert_non_null(err); - assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM); - assert_string_equal(err->msg, - "'atom_legacy_entry_id' setting is not supported anymore. see " + assert_string_equal(sb_error_to_string(err), + "atom: 'atom_legacy_entry_id' setting is not supported anymore. see " "https://blogc.rgm.io/news/blogc-0.16.1/ for details"); - bc_error_free(err); - bc_trie_free(settings->settings); + sb_error_free(err); + sb_trie_free(settings->settings); free(settings); } @@ -508,27 +504,26 @@ test_atom_legacy_entry_id_empty(void **state) static void test_atom_legacy_entry_id(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom")); - bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml")); - bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post")); - bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html")); - bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1")); - - bc_error_t *err = NULL; + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom")); + sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml")); + sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post")); + sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html")); + sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1")); + + sb_error_t *err = NULL; char *rv = bm_atom_deploy(settings, &err); assert_null(rv); assert_non_null(err); - assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM); - assert_string_equal(err->msg, - "'atom_legacy_entry_id' setting is not supported anymore. see " + assert_string_equal(sb_error_to_string(err), + "atom: 'atom_legacy_entry_id' setting is not supported anymore. see " "https://blogc.rgm.io/news/blogc-0.16.1/ for details"); - bc_error_free(err); - bc_trie_free(settings->settings); + sb_error_free(err); + sb_trie_free(settings->settings); free(settings); } diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c index 6812496..c5d1d4e 100644 --- a/tests/blogc-make/check_exec.c +++ b/tests/blogc-make/check_exec.c @@ -14,14 +14,13 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> - #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <squareball.h> #include "../../src/blogc-make/exec.h" #include "../../src/blogc-make/settings.h" -#include "../../src/common/utils.h" int @@ -75,16 +74,16 @@ test_find_binary(void **state) static void test_build_blogc_cmd_with_settings(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8")); - settings->global = bc_trie_new(free); - bc_trie_insert(settings->global, "FOO", bc_strdup("BAR")); - bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ")); - bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - bc_trie_t *local = bc_trie_new(free); - bc_trie_insert(local, "ASD", bc_strdup("QWE")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8")); + settings->global = sb_trie_new(free); + sb_trie_insert(settings->global, "FOO", sb_strdup("BAR")); + sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ")); + sb_trie_t *variables = sb_trie_new(free); + sb_trie_insert(variables, "LOL", sb_strdup("HEHE")); + sb_trie_t *local = sb_trie_new(free); + sb_trie_insert(local, "ASD", sb_strdup("QWE")); settings->tags = NULL; char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, @@ -113,10 +112,10 @@ test_build_blogc_cmd_with_settings(void **state) "LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ'"); free(rv); - bc_trie_free(local); - bc_trie_free(variables); - bc_trie_free(settings->settings); - bc_trie_free(settings->global); + sb_trie_free(local); + sb_trie_free(variables); + sb_trie_free(settings->settings); + sb_trie_free(settings->global); free(settings); } @@ -124,16 +123,16 @@ test_build_blogc_cmd_with_settings(void **state) static void test_build_blogc_cmd_with_settings_and_dev(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8")); - settings->global = bc_trie_new(free); - bc_trie_insert(settings->global, "FOO", bc_strdup("BAR")); - bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ")); - bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - bc_trie_t *local = bc_trie_new(free); - bc_trie_insert(local, "ASD", bc_strdup("QWE")); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8")); + settings->global = sb_trie_new(free); + sb_trie_insert(settings->global, "FOO", sb_strdup("BAR")); + sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ")); + sb_trie_t *variables = sb_trie_new(free); + sb_trie_insert(variables, "LOL", sb_strdup("HEHE")); + sb_trie_t *local = sb_trie_new(free); + sb_trie_insert(local, "ASD", sb_strdup("QWE")); settings->tags = NULL; char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, @@ -166,10 +165,10 @@ test_build_blogc_cmd_with_settings_and_dev(void **state) "-D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'"); free(rv); - bc_trie_free(local); - bc_trie_free(variables); - bc_trie_free(settings->settings); - bc_trie_free(settings->global); + sb_trie_free(local); + sb_trie_free(variables); + sb_trie_free(settings->settings); + sb_trie_free(settings->global); free(settings); } @@ -177,17 +176,17 @@ test_build_blogc_cmd_with_settings_and_dev(void **state) static void test_build_blogc_cmd_with_settings_and_tags(void **state) { - bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t)); - settings->settings = bc_trie_new(free); - bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8")); - settings->global = bc_trie_new(free); - bc_trie_insert(settings->global, "FOO", bc_strdup("BAR")); - bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ")); - bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - bc_trie_t *local = bc_trie_new(free); - bc_trie_insert(local, "ASD", bc_strdup("QWE")); - settings->tags = bc_str_split("asd foo bar", ' ', 0); + bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t)); + settings->settings = sb_trie_new(free); + sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8")); + settings->global = sb_trie_new(free); + sb_trie_insert(settings->global, "FOO", sb_strdup("BAR")); + sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ")); + sb_trie_t *variables = sb_trie_new(free); + sb_trie_insert(variables, "LOL", sb_strdup("HEHE")); + sb_trie_t *local = sb_trie_new(free); + sb_trie_insert(local, "ASD", sb_strdup("QWE")); + settings->tags = sb_str_split("asd foo bar", ' ', 0); char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL, true, NULL, "main.tmpl", "foo.html", true, true); @@ -219,11 +218,11 @@ test_build_blogc_cmd_with_settings_and_tags(void **state) "-D BAR='BAZ' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'"); free(rv); - bc_trie_free(local); - bc_trie_free(variables); - bc_trie_free(settings->settings); - bc_trie_free(settings->global); - bc_strv_free(settings->tags); + sb_trie_free(local); + sb_trie_free(variables); + sb_trie_free(settings->settings); + sb_trie_free(settings->global); + sb_strv_free(settings->tags); free(settings); } @@ -231,10 +230,10 @@ test_build_blogc_cmd_with_settings_and_tags(void **state) static void test_build_blogc_cmd_without_settings(void **state) { - bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - bc_trie_t *local = bc_trie_new(free); - bc_trie_insert(local, "ASD", bc_strdup("QWE")); + sb_trie_t *variables = sb_trie_new(free); + sb_trie_insert(variables, "LOL", sb_strdup("HEHE")); + sb_trie_t *local = sb_trie_new(free); + sb_trie_insert(local, "ASD", sb_strdup("QWE")); char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, NULL, true, NULL, "main.tmpl", "foo.html", false, true); @@ -261,18 +260,18 @@ test_build_blogc_cmd_without_settings(void **state) "blogc"); free(rv); - bc_trie_free(local); - bc_trie_free(variables); + sb_trie_free(local); + sb_trie_free(variables); } static void test_build_blogc_cmd_print(void **state) { - bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - bc_trie_t *local = bc_trie_new(free); - bc_trie_insert(local, "ASD", bc_strdup("QWE")); + sb_trie_t *variables = sb_trie_new(free); + sb_trie_insert(variables, "LOL", sb_strdup("HEHE")); + sb_trie_t *local = sb_trie_new(free); + sb_trie_insert(local, "ASD", sb_strdup("QWE")); char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, "LOL", false, NULL, NULL, NULL, false, true); @@ -296,8 +295,8 @@ test_build_blogc_cmd_print(void **state) "blogc -p LOL"); free(rv); - bc_trie_free(local); - bc_trie_free(variables); + sb_trie_free(local); + sb_trie_free(variables); } diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c index ed2e46a..25ba0e1 100644 --- a/tests/blogc-make/check_rules.c +++ b/tests/blogc-make/check_rules.c @@ -10,73 +10,72 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> - #include <stdlib.h> #include <string.h> +#include <squareball.h> #include "../../src/blogc-make/rules.h" -#include "../../src/common/utils.h" static void test_rule_parse_args(void **state) { - bc_trie_t *t = bm_rule_parse_args("bola:foo=" + 4); + sb_trie_t *t = bm_rule_parse_args("bola:foo=" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 1); - assert_string_equal(bc_trie_lookup(t, "foo"), ""); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 1); + assert_string_equal(sb_trie_lookup(t, "foo"), ""); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 1); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 1); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=,baz=lol" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 2); - assert_string_equal(bc_trie_lookup(t, "foo"), ""); - assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 2); + assert_string_equal(sb_trie_lookup(t, "foo"), ""); + assert_string_equal(sb_trie_lookup(t, "baz"), "lol"); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar,baz=" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 2); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - assert_string_equal(bc_trie_lookup(t, "baz"), ""); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 2); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + assert_string_equal(sb_trie_lookup(t, "baz"), ""); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar,baz=lol" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 2); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 2); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + assert_string_equal(sb_trie_lookup(t, "baz"), "lol"); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=,baz=lol,asd=qwe" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 3); - assert_string_equal(bc_trie_lookup(t, "foo"), ""); - assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); - assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 3); + assert_string_equal(sb_trie_lookup(t, "foo"), ""); + assert_string_equal(sb_trie_lookup(t, "baz"), "lol"); + assert_string_equal(sb_trie_lookup(t, "asd"), "qwe"); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar,baz=,asd=qwe" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 3); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - assert_string_equal(bc_trie_lookup(t, "baz"), ""); - assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 3); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + assert_string_equal(sb_trie_lookup(t, "baz"), ""); + assert_string_equal(sb_trie_lookup(t, "asd"), "qwe"); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 3); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); - assert_string_equal(bc_trie_lookup(t, "asd"), ""); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 3); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + assert_string_equal(sb_trie_lookup(t, "baz"), "lol"); + assert_string_equal(sb_trie_lookup(t, "asd"), ""); + sb_trie_free(t); t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=qwe" + 4); assert_non_null(t); - assert_int_equal(bc_trie_size(t), 3); - assert_string_equal(bc_trie_lookup(t, "foo"), "bar"); - assert_string_equal(bc_trie_lookup(t, "baz"), "lol"); - assert_string_equal(bc_trie_lookup(t, "asd"), "qwe"); - bc_trie_free(t); + assert_int_equal(sb_trie_size(t), 3); + assert_string_equal(sb_trie_lookup(t, "foo"), "bar"); + assert_string_equal(sb_trie_lookup(t, "baz"), "lol"); + assert_string_equal(sb_trie_lookup(t, "asd"), "qwe"); + sb_trie_free(t); } diff --git a/tests/blogc-make/check_settings.c b/tests/blogc-make/check_settings.c index 7cebedc..3f091dd 100644 --- a/tests/blogc-make/check_settings.c +++ b/tests/blogc-make/check_settings.c @@ -10,27 +10,24 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> - #include <stdlib.h> #include <string.h> +#include <squareball.h> #include "../../src/blogc-make/settings.h" -#include "../../src/common/error.h" -#include "../../src/common/utils.h" static void test_settings_empty(void **state) { const char *a = ""; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_non_null(err); assert_null(s); - assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS); - assert_string_equal(err->msg, - "[global] key required but not found or empty: AUTHOR_NAME"); - bc_error_free(err); + assert_string_equal(sb_error_to_string(err), + "settings: [global] key required but not found or empty: AUTHOR_NAME"); + sb_error_free(err); } @@ -45,14 +42,13 @@ test_settings(void **state) "[global]\n" "BOLA = asd\n" "GUDA = qwe\n"; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_non_null(err); assert_null(s); - assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS); - assert_string_equal(err->msg, - "[global] key required but not found or empty: AUTHOR_NAME"); - bc_error_free(err); + assert_string_equal(sb_error_to_string(err), + "settings: [global] key required but not found or empty: AUTHOR_NAME"); + sb_error_free(err); } @@ -67,14 +63,13 @@ test_settings_env(void **state) "[environment]\n" "BOLA = asd\n" "GUDA = qwe\n"; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_non_null(err); assert_null(s); - assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS); - assert_string_equal(err->msg, - "[environment] key required but not found or empty: AUTHOR_NAME"); - bc_error_free(err); + assert_string_equal(sb_error_to_string(err), + "settings: [environment] key required but not found or empty: AUTHOR_NAME"); + sb_error_free(err); } @@ -113,36 +108,36 @@ test_settings2(void **state) "jjjj\n" "kkkk\n" "llll\n"; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_null(err); assert_non_null(s); - assert_int_equal(bc_trie_size(s->global), 7); - assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd"); - assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); - assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); - assert_int_equal(bc_trie_size(s->settings), 16); - assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt"); - assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html"); - assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda"); - assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates"); - assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl"); - assert_string_equal(bc_trie_lookup(s->settings, "date_format"), + assert_int_equal(sb_trie_size(s->global), 7); + assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd"); + assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); + assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); + assert_int_equal(sb_trie_size(s->settings), 16); + assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt"); + assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html"); + assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda"); + assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates"); + assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl"); + assert_string_equal(sb_trie_lookup(s->settings, "date_format"), "%b %d, %Y, %I:%M %p GMT"); - assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page"); - assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post"); - assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag"); - assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), ""); + assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page"); + assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post"); + assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag"); + assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), ""); assert_non_null(s->posts); assert_string_equal(s->posts[0], "aaaa"); assert_string_equal(s->posts[1], "bbbb"); @@ -202,36 +197,36 @@ test_settings_env2(void **state) "jjjj\n" "kkkk\n" "llll\n"; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_null(err); assert_non_null(s); - assert_int_equal(bc_trie_size(s->global), 7); - assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd"); - assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); - assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); - assert_int_equal(bc_trie_size(s->settings), 16); - assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt"); - assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html"); - assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda"); - assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates"); - assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl"); - assert_string_equal(bc_trie_lookup(s->settings, "date_format"), + assert_int_equal(sb_trie_size(s->global), 7); + assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd"); + assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); + assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); + assert_int_equal(sb_trie_size(s->settings), 16); + assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt"); + assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html"); + assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda"); + assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates"); + assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl"); + assert_string_equal(sb_trie_lookup(s->settings, "date_format"), "%b %d, %Y, %I:%M %p GMT"); - assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page"); - assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post"); - assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag"); - assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), ""); + assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page"); + assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post"); + assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag"); + assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), ""); assert_non_null(s->posts); assert_string_equal(s->posts[0], "aaaa"); assert_string_equal(s->posts[1], "bbbb"); @@ -291,36 +286,36 @@ test_settings_copy_files(void **state) "jjjj\n" "kkkk\n" "llll\n"; - bc_error_t *err = NULL; + sb_error_t *err = NULL; bm_settings_t *s = bm_settings_parse(a, strlen(a), &err); assert_null(err); assert_non_null(s); - assert_int_equal(bc_trie_size(s->global), 7); - assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd"); - assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); - assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); - assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); - assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); - assert_int_equal(bc_trie_size(s->settings), 16); - assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt"); - assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html"); - assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda"); - assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates"); - assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl"); - assert_string_equal(bc_trie_lookup(s->settings, "date_format"), + assert_int_equal(sb_trie_size(s->global), 7); + assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd"); + assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda"); + assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu"); + assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline"); + assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com"); + assert_int_equal(sb_trie_size(s->settings), 16); + assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt"); + assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html"); + assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda"); + assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates"); + assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl"); + assert_string_equal(sb_trie_lookup(s->settings, "date_format"), "%b %d, %Y, %I:%M %p GMT"); - assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10"); - assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page"); - assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post"); - assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag"); - assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC"); - assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), ""); + assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10"); + assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page"); + assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post"); + assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag"); + assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC"); + assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), ""); assert_non_null(s->posts); assert_string_equal(s->posts[0], "aaaa"); assert_string_equal(s->posts[1], "bbbb"); diff --git a/tests/blogc-make/check_utils.c b/tests/blogc-make/check_utils.c index 5b3614d..852c0f7 100644 --- a/tests/blogc-make/check_utils.c +++ b/tests/blogc-make/check_utils.c @@ -10,11 +10,10 @@ #include <stddef.h> #include <setjmp.h> #include <cmocka.h> - #include <stdlib.h> +#include <squareball.h> #include "../../src/blogc-make/utils.h" -#include "../../src/common/utils.h" static void |