diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-03 01:10:35 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-03-03 01:10:35 +0100 |
commit | 0c290f72a9101c196031c3bcf5ee1340b4328b80 (patch) | |
tree | 4ac5e096ffc79afbd830b6c478646f355e1156b8 /tests | |
parent | be39aad967f2243dd512ae9ab9510179d13abf16 (diff) | |
download | blogc-0c290f72a9101c196031c3bcf5ee1340b4328b80.tar.gz blogc-0c290f72a9101c196031c3bcf5ee1340b4328b80.tar.bz2 blogc-0c290f72a9101c196031c3bcf5ee1340b4328b80.zip |
make: reworked binary lookups, added them to ctx
Diffstat (limited to 'tests')
-rw-r--r-- | tests/blogc-make/check_atom.c | 2 | ||||
-rw-r--r-- | tests/blogc-make/check_exec.c | 110 | ||||
-rw-r--r-- | tests/blogc-make/check_rules.c | 2 | ||||
-rw-r--r-- | tests/blogc-make/check_settings.c | 2 |
4 files changed, 56 insertions, 60 deletions
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c index e487d30..6faa53e 100644 --- a/tests/blogc-make/check_atom.c +++ b/tests/blogc-make/check_atom.c @@ -20,8 +20,6 @@ #include "../../src/common/error.h" #include "../../src/common/utils.h" -const char *argv0 = NULL; - static void test_atom_file(void **state) diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c index 43ef161..febcfae 100644 --- a/tests/blogc-make/check_exec.c +++ b/tests/blogc-make/check_exec.c @@ -13,19 +13,60 @@ #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "../../src/blogc-make/exec.h" #include "../../src/blogc-make/settings.h" #include "../../src/common/utils.h" -const char *argv0 = NULL; + +int +__wrap_access(const char *pathname, int mode) +{ + assert_int_equal(mode, X_OK); + assert_string_equal(pathname, mock_type(const char*)); + return mock_type(int); +} static void -test_build_blogc_cmd_with_settings(void **state) +test_find_binary(void **state) { unsetenv("BLOGC"); + char *bin = bm_exec_find_binary(NULL, "blogc", "BLOGC"); + assert_string_equal(bin, "blogc"); + free(bin); + + will_return(__wrap_access, "../blogc"); + will_return(__wrap_access, 0); + bin = bm_exec_find_binary("../blogc", "blogc", "BLOGC"); + assert_string_equal(bin, "'../blogc'"); + free(bin); + + will_return(__wrap_access, "/usr/bin/blogc"); + will_return(__wrap_access, 0); + bin = bm_exec_find_binary("/usr/bin/blogc", "blogc", "BLOGC"); + assert_string_equal(bin, "'/usr/bin/blogc'"); + free(bin); + + will_return(__wrap_access, "../blogc"); + will_return(__wrap_access, 1); + bin = bm_exec_find_binary("../blogc", "blogc", "BLOGC"); + assert_string_equal(bin, "blogc"); + free(bin); + + setenv("BLOGC", "/path/to/blogc", 1); + bin = bm_exec_find_binary(NULL, "blogc", "BLOGC"); + assert_string_equal(bin, "'/path/to/blogc'"); + free(bin); + unsetenv("BLOGC"); +} + + +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")); @@ -35,45 +76,25 @@ test_build_blogc_cmd_with_settings(void **state) bc_trie_t *variables = bc_trie_new(free); bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - char *rv = bm_exec_build_blogc_cmd(settings, variables, true, "main.tmpl", - "foo.html", true); + char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, true, + "main.tmpl", "foo.html", true); assert_string_equal(rv, "LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE' -l " "-t 'main.tmpl' -o 'foo.html' -i"); free(rv); - rv = bm_exec_build_blogc_cmd(settings, variables, false, NULL, NULL, false); + rv = bm_exec_build_blogc_cmd("blogc", settings, variables, false, NULL, NULL, + false); assert_string_equal(rv, "LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ' -D LOL='HEHE'"); free(rv); - rv = bm_exec_build_blogc_cmd(settings, NULL, false, NULL, NULL, false); + rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, false, NULL, NULL, + false); assert_string_equal(rv, "LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ'"); free(rv); - setenv("BLOGC", "/path/to/blogc", 1); - - rv = bm_exec_build_blogc_cmd(settings, variables, true, "main.tmpl", - "foo.html", true); - assert_string_equal(rv, - "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ' " - "-D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i"); - free(rv); - - rv = bm_exec_build_blogc_cmd(settings, variables, false, NULL, NULL, false); - assert_string_equal(rv, - "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ' " - "-D LOL='HEHE'"); - free(rv); - - rv = bm_exec_build_blogc_cmd(settings, NULL, false, NULL, NULL, false); - assert_string_equal(rv, - "LC_ALL='en_US.utf8' '/path/to/blogc' -D FOO='BAR' -D BAR='BAZ'"); - free(rv); - - unsetenv("BLOGC"); - bc_trie_free(variables); bc_trie_free(settings->settings); bc_trie_free(settings->env); @@ -81,50 +102,30 @@ test_build_blogc_cmd_with_settings(void **state) } + static void test_build_blogc_cmd_without_settings(void **state) { - unsetenv("BLOGC"); - bc_trie_t *variables = bc_trie_new(free); bc_trie_insert(variables, "LOL", bc_strdup("HEHE")); - char *rv = bm_exec_build_blogc_cmd(NULL, variables, true, "main.tmpl", - "foo.html", true); + char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, true, + "main.tmpl", "foo.html", true); assert_string_equal(rv, "blogc -D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i"); free(rv); - rv = bm_exec_build_blogc_cmd(NULL, variables, false, NULL, NULL, false); + rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, false, NULL, NULL, + false); assert_string_equal(rv, "blogc -D LOL='HEHE'"); free(rv); - rv = bm_exec_build_blogc_cmd(NULL, NULL, false, NULL, NULL, false); + rv = bm_exec_build_blogc_cmd("blogc", NULL, NULL, false, NULL, NULL, false); assert_string_equal(rv, "blogc"); free(rv); - setenv("BLOGC", "/path/to/blogc", 1); - - rv = bm_exec_build_blogc_cmd(NULL, variables, true, "main.tmpl", "foo.html", - true); - assert_string_equal(rv, - "'/path/to/blogc' -D LOL='HEHE' -l -t 'main.tmpl' -o 'foo.html' -i"); - free(rv); - - rv = bm_exec_build_blogc_cmd(NULL, variables, false, NULL, NULL, false); - assert_string_equal(rv, - "'/path/to/blogc' -D LOL='HEHE'"); - free(rv); - - rv = bm_exec_build_blogc_cmd(NULL, NULL, false, NULL, NULL, false); - assert_string_equal(rv, - "'/path/to/blogc'"); - free(rv); - - unsetenv("BLOGC"); - bc_trie_free(variables); } @@ -133,6 +134,7 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_find_binary), unit_test(test_build_blogc_cmd_with_settings), unit_test(test_build_blogc_cmd_without_settings), }; diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c index 773ff06..c8bd9a8 100644 --- a/tests/blogc-make/check_rules.c +++ b/tests/blogc-make/check_rules.c @@ -17,8 +17,6 @@ #include "../../src/blogc-make/rules.h" #include "../../src/common/utils.h" -const char *argv0 = NULL; - static void test_rule_parse_args(void **state) diff --git a/tests/blogc-make/check_settings.c b/tests/blogc-make/check_settings.c index 3bdc9c5..93aed59 100644 --- a/tests/blogc-make/check_settings.c +++ b/tests/blogc-make/check_settings.c @@ -18,8 +18,6 @@ #include "../../src/common/error.h" #include "../../src/common/utils.h" -const char *argv0 = NULL; - static void test_settings_empty(void **state) |