From 3a5ea19f35e4228cd782d69f21f52656c1e9a1b8 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 24 Oct 2015 04:12:43 -0200 Subject: error: improved error reporting for parsers it will now report the line and the approximate position of the error. --- tests/check_error.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'tests/check_error.c') diff --git a/tests/check_error.c b/tests/check_error.c index 68f287a..17e1c40 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -48,7 +48,28 @@ test_error_parser(void **state) blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); assert_int_equal(error->type, 1); - assert_string_equal(error->msg, "asd 10\nError occurred near to 'hunda'"); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 3, position 2: chunda"); + blogc_error_free(error); + a = "bola\nguda\nchunda"; + error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); + assert_non_null(error); + assert_int_equal(error->type, 1); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 3, position 2: chunda"); + blogc_error_free(error); + a = "bola\nguda\nchunda"; + error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); + assert_non_null(error); + assert_int_equal(error->type, 1); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 1, position 1: bola"); + blogc_error_free(error); + a = ""; + error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); + assert_non_null(error); + assert_int_equal(error->type, 1); + assert_string_equal(error->msg, "asd 10"); blogc_error_free(error); } @@ -60,7 +81,22 @@ test_error_parser_crlf(void **state) blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); assert_int_equal(error->type, 1); - assert_string_equal(error->msg, "asd 10\nError occurred near to 'hunda'"); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 3, position 2: chunda"); + blogc_error_free(error); + a = "bola\r\nguda\r\nchunda"; + error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); + assert_non_null(error); + assert_int_equal(error->type, 1); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 3, position 2: chunda"); + blogc_error_free(error); + a = "bola\r\nguda\r\nchunda"; + error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); + assert_non_null(error); + assert_int_equal(error->type, 1); + assert_string_equal(error->msg, + "asd 10\nError occurred near line 1, position 1: bola"); blogc_error_free(error); } -- cgit v1.2.3-18-g5258