diff options
author | sanine <sanine.not@pm.me> | 2022-06-14 20:53:14 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-06-14 20:53:14 -0500 |
commit | 31c6a0939a23b2ce1b450168b93c371f1a3e8d13 (patch) | |
tree | e9996748ae24278232fb6f670c15084d62499c8c /src | |
parent | 5d5af62d63c331245a1cb41433fabc0ac25754b6 (diff) |
do not log if log level is too low
Diffstat (limited to 'src')
-rw-r--r-- | src/logging/logging.c | 2 | ||||
-rw-r--r-- | src/logging/logging.test.c | 23 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/logging/logging.c b/src/logging/logging.c index cb720a4..255da4c 100644 --- a/src/logging/logging.c +++ b/src/logging/logging.c @@ -10,7 +10,7 @@ void honey_set_log_level(int level) void honey_log(int level, const char *fmt, ...) { - //if (level > _honey_log_level) return; + if (level > _honey_log_level) return; va_list args; va_start(args, fmt); diff --git a/src/logging/logging.test.c b/src/logging/logging.test.c index cc6a316..dfcbe4e 100644 --- a/src/logging/logging.test.c +++ b/src/logging/logging.test.c @@ -70,12 +70,16 @@ void clean_mock(lily_mock_t **m) } } -void test_log_fatal_succeeds(); +void level_fatal_log_fatal_succeeds(); +void level_neg_log_fatal_fails(); void suite_logging() { vfprintf_mock_data = NULL; - lily_run_test(test_log_fatal_succeeds); + + lily_run_test(level_neg_log_fatal_fails); + lily_run_test(level_fatal_log_fatal_succeeds); + if (vfprintf_mock_data != NULL) lily_mock_destroy(vfprintf_mock_data); } @@ -88,7 +92,7 @@ void suite_logging() * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void test_log_fatal_succeeds() +void level_fatal_log_fatal_succeeds() { clean_mock(&vfprintf_mock_data); vfprintf_mock_data = lily_mock_create(); @@ -106,6 +110,17 @@ void test_log_fatal_succeeds() lily_get_call(vfprintf_mock_data, args, 0); lily_assert_ptr_equal(file, stderr); - lily_assert_string_equal(fmt, "[FATAL] some message"); + lily_assert_string_equal((char*) fmt, "[FATAL] some message"); lily_assert_int_equal(n_strings, 0); } + + +void level_neg_log_fatal_fails() +{ + clean_mock(&vfprintf_mock_data); + vfprintf_mock_data = lily_mock_create(); + + honey_set_log_level(-1); + honey_fatal("some message"); + lily_assert_int_equal(vfprintf_mock_data->n_calls, 0); +} |