added test for compile time log level filter

This commit is contained in:
Sven Vogel 2024-05-02 10:50:24 +02:00
parent ebf526d6da
commit c099a60ecf
3 changed files with 56 additions and 0 deletions

View File

@ -46,3 +46,18 @@ set_target_properties(logging_streams
add_test(NAME logging_streams
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_stream)
# ------------------------------------------------------- #
# CTEST 4
# test compile time log level switch
add_executable(logging_level
${PROJECT_SOURCE_DIR}/src/sys/log.c
level.c)
set_target_properties(logging_level
PROPERTIES
OUTPUT_NAME "level"
RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/logging)
add_test(NAME logging_level
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND python ${GEMSTONE_TEST_DIR}/logging/test_logging.py check_level)

18
tests/logging/level.c Normal file
View File

@ -0,0 +1,18 @@
//
// Created by servostar on 5/2/24.
//
#include "sys/log.h"
#define LOG_LEVEL LOG_LEVEL_WARNING
int main(void) {
log_init();
DEBUG("logging some debug...");
INFO("logging some info...");
WARN("logging some warning...");
ERROR("logging some error...");
return 0;
}

View File

@ -28,6 +28,27 @@ def run_check_output():
assert "logging some error..." in output
def run_check_level():
info("started check level...")
p = subprocess.run(BIN_DIR + "level", capture_output=True, text=True)
info("checking exit code...")
# check exit code
assert p.returncode == 0
output = p.stderr
# check if logs appear in default log output (stderr)
info("checking stderr...")
assert "logging some debug..." not in output
assert "logging some info..." not in output
assert "logging some warning..." in output
assert "logging some error..." in output
def run_check_panic():
info("started check panic...")
@ -96,6 +117,8 @@ if __name__ == "__main__":
run_check_panic()
case "check_stream":
run_check_stream()
case "check_level":
run_check_level()
case _:
error(f"unknown target: {target}")
exit(1)