diff --git a/src/cmdline.c b/src/cmdline.c index 5f390a7..1f94a67 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -462,7 +462,7 @@ static int tab_handling(opt_t *result, char *optarg) char *p; int width = (int) strtol(optarg, &p, 10); if (width < 1 || width > MAX_TABSTOP) { - fprintf(stderr, "%s: invalid tab stop distance -- %d\n", PROJECT, width); + bx_fprintf(stderr, "%s: invalid tab stop distance -- %d\n", PROJECT, width); return 1; } result->tabstop = width; @@ -490,7 +490,7 @@ static int tab_handling(opt_t *result, char *optarg) } } if (errfl) { - fprintf(stderr, "%s: invalid tab handling specification - %s\n", PROJECT, optarg); + bx_fprintf(stderr, "%s: invalid tab handling specification - %s\n", PROJECT, optarg); return 1; } return 0; diff --git a/utest/cmdline_test.c b/utest/cmdline_test.c index 7d15792..a8aa3b8 100644 --- a/utest/cmdline_test.c +++ b/utest/cmdline_test.c @@ -235,4 +235,76 @@ void test_padding_novalue(void **state) } +void test_tabstops_zero(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "0"); + + assert_null(actual); // invalid option, so we would need to exit with error + assert_int_equal(1, collect_err_size); + assert_string_equal("boxes: invalid tab stop distance -- 0\n", collect_err[0]); +} + + +void test_tabstops_500(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "500"); + + assert_null(actual); // invalid option, so we would need to exit with error + assert_int_equal(1, collect_err_size); + assert_string_equal("boxes: invalid tab stop distance -- 500\n", collect_err[0]); +} + + +void test_tabstops_4X(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "4X"); + + assert_null(actual); // invalid option, so we would need to exit with error + assert_int_equal(1, collect_err_size); + assert_string_equal("boxes: invalid tab handling specification - 4X\n", collect_err[0]); +} + + +void test_tabstops_4e(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "4e"); + + assert_non_null(actual); + assert_int_equal(4, actual->tabstop); + assert_int_equal((int) 'e', (int) actual->tabexp); +} + + +void test_tabstops_4ex(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "4ex"); + + assert_null(actual); // invalid option, so we would need to exit with error + assert_int_equal(1, collect_err_size); + assert_string_equal("boxes: invalid tab handling specification - 4ex\n", collect_err[0]); +} + + +void test_tabstops_7(void **state) +{ + (void) state; /* unused */ + + opt_t *actual = act(2, "-t", "7"); + + assert_non_null(actual); + assert_int_equal(7, actual->tabstop); + assert_int_equal((int) 'e', (int) actual->tabexp); +} + + /*EOF*/ /* vim: set cindent sw=4: */ diff --git a/utest/cmdline_test.h b/utest/cmdline_test.h index e7795bd..7b5b54c 100644 --- a/utest/cmdline_test.h +++ b/utest/cmdline_test.h @@ -44,6 +44,13 @@ void test_padding_notset(void **state); void test_padding_invalid_value(void **state); void test_padding_novalue(void **state); +void test_tabstops_zero(void **state); +void test_tabstops_500(void **state); +void test_tabstops_4X(void **state); +void test_tabstops_4e(void **state); +void test_tabstops_4ex(void **state); +void test_tabstops_7(void **state); + #endif diff --git a/utest/main.c b/utest/main.c index ef025e6..0110565 100644 --- a/utest/main.c +++ b/utest/main.c @@ -62,7 +62,13 @@ int main(void) cmocka_unit_test_setup(test_padding_negative, beforeTest), cmocka_unit_test_setup(test_padding_notset, beforeTest), cmocka_unit_test_setup(test_padding_invalid_value, beforeTest), - cmocka_unit_test_setup(test_padding_novalue, beforeTest) + cmocka_unit_test_setup(test_padding_novalue, beforeTest), + cmocka_unit_test_setup(test_tabstops_zero, beforeTest), + cmocka_unit_test_setup(test_tabstops_500, beforeTest), + cmocka_unit_test_setup(test_tabstops_4X, beforeTest), + cmocka_unit_test_setup(test_tabstops_4e, beforeTest), + cmocka_unit_test_setup(test_tabstops_4ex, beforeTest), + cmocka_unit_test_setup(test_tabstops_7, beforeTest) }; const struct CMUnitTest regulex_tests[] = {