39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
#include "test.h"
|
|
#include "log.h"
|
|
#include <string.h>
|
|
|
|
static char s_lastLoggedError[256];
|
|
|
|
static void mock_log(const char* msg) {
|
|
strncpy(s_lastLoggedError, msg, sizeof(s_lastLoggedError) - 1);
|
|
s_lastLoggedError[sizeof(s_lastLoggedError) - 1] = '\0';
|
|
}
|
|
|
|
static void test_log_error(void) {
|
|
log_set_output(mock_log);
|
|
|
|
memset(s_lastLoggedError, 0, sizeof(s_lastLoggedError));
|
|
log_error("test error message");
|
|
|
|
assert_str("test error message", s_lastLoggedError, "expected 'test error message'");
|
|
|
|
log_set_output(NULL); // Reset to default
|
|
}
|
|
|
|
static void test_log_on_line(void) {
|
|
Location loc = {
|
|
.filename = "test.c",
|
|
.line_text = "int main() []",
|
|
.line_text_length = 13,
|
|
.line = 1,
|
|
.column = 12
|
|
};
|
|
|
|
log_on_line(&loc, 13, "unexpected token");
|
|
assert_log_file("v0/tests/log_on_line.txt", "expected formatted error message");
|
|
|
|
log_clear();
|
|
log_on_line(&loc, 13, "unexpected token '%c'", 'x');
|
|
assert_log_file("v0/tests/log_on_line_variadic.txt", "expected formatted error message with variadic args");
|
|
}
|