aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/blogc/file.c11
-rw-r--r--src/blogc/file.h2
-rw-r--r--src/blogc/loader.c13
-rw-r--r--tests/blogc/check_loader.c30
4 files changed, 15 insertions, 41 deletions
diff --git a/src/blogc/file.c b/src/blogc/file.c
index 71598b8..518c665 100644
--- a/src/blogc/file.c
+++ b/src/blogc/file.c
@@ -68,14 +68,3 @@ blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err)
return bc_string_free(str, false);
}
-
-
-int
-blogc_fprintf(FILE *stream, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- int rv = vfprintf(stream, format, ap);
- va_end(ap);
- return rv;
-}
diff --git a/src/blogc/file.h b/src/blogc/file.h
index 8213573..6a0e094 100644
--- a/src/blogc/file.h
+++ b/src/blogc/file.h
@@ -10,12 +10,10 @@
#define _FILE_H
#include <stddef.h>
-#include <stdio.h>
#include "../common/error.h"
#define BLOGC_FILE_CHUNK_SIZE 1024
char* blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err);
-int blogc_fprintf(FILE *stream, const char *format, ...);
#endif /* _FILE_H */
diff --git a/src/blogc/loader.c b/src/blogc/loader.c
index e8de75d..754723b 100644
--- a/src/blogc/loader.c
+++ b/src/blogc/loader.c
@@ -166,12 +166,13 @@ blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, bc_error_t **err)
rv = bc_slist_append(rv, s);
}
- if (with_date > 0 && with_date < bc_slist_length(rv))
- // fatal error, maybe?
- blogc_fprintf(stderr,
- "blogc: warning: 'DATE' variable provided for at least one source "
- "file, but not for all source files. This means that you may get "
- "wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
+ if (with_date > 0 && with_date < bc_slist_length(rv)) {
+ *err = bc_error_new_printf(BLOGC_ERROR_LOADER,
+ "'DATE' variable provided for at least one source file, but not "
+ "for all source files. It must be provided for all files.\n");
+ bc_slist_free_full(rv, (bc_free_func_t) bc_trie_free);
+ rv = NULL;
+ }
bool first = true;
for (bc_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
diff --git a/tests/blogc/check_loader.c b/tests/blogc/check_loader.c
index 0ec0a09..5257e1d 100644
--- a/tests/blogc/check_loader.c
+++ b/tests/blogc/check_loader.c
@@ -64,15 +64,6 @@ __wrap_blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err)
}
-int
-__wrap_blogc_fprintf(FILE *stream, const char *format, ...)
-{
- assert_true(stream == mock_type(FILE*));
- assert_string_equal(format, mock_type(const char*));
- return strlen(format);
-}
-
-
static void
test_template_parse_from_file(void **state)
{
@@ -688,11 +679,6 @@ test_source_parse_from_files_filter_by_page_invalid2(void **state)
static void
test_source_parse_from_files_without_all_dates(void **state)
{
- will_return(__wrap_blogc_fprintf, stderr);
- will_return(__wrap_blogc_fprintf,
- "blogc: warning: 'DATE' variable provided for at least one source "
- "file, but not for all source files. This means that you may get wrong "
- "values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
will_return(__wrap_blogc_file_get_contents, bc_strdup(
"ASD: 123\n"
@@ -717,16 +703,16 @@ test_source_parse_from_files_without_all_dates(void **state)
s = bc_slist_append(s, bc_strdup("bola3.txt"));
bc_trie_t *c = bc_trie_new(free);
bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
- assert_null(err);
- assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 3);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ assert_null(t);
+ assert_non_null(err);
+ assert_int_equal(err->type, BLOGC_ERROR_LOADER);
+ assert_string_equal(err->msg,
+ "'DATE' variable provided for at least one source file, but not for "
+ "all source files. It must be provided for all files.\n");
+ bc_error_free(err);
+ assert_int_equal(bc_trie_size(c), 0);
bc_trie_free(c);
bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
}