53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#include "test.h"
|
|
#include "log.h"
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "util.h"
|
|
|
|
static char* s_lastLoggedError = NULL;
|
|
|
|
static void mock_log(const char* msg) {
|
|
free(s_lastLoggedError);
|
|
s_lastLoggedError = format_string("%s", msg ? msg : "");
|
|
}
|
|
|
|
static void test_log_error(void) {
|
|
log_set_output(mock_log);
|
|
|
|
free(s_lastLoggedError);
|
|
s_lastLoggedError = NULL;
|
|
log_error("test error message");
|
|
|
|
assert_str("test error message", s_lastLoggedError, "expected 'test error message'");
|
|
|
|
log_set_output(NULL);
|
|
free(s_lastLoggedError);
|
|
s_lastLoggedError = NULL;
|
|
}
|
|
|
|
static void test_log_on_line(void) {
|
|
Location loc;
|
|
loc.filename = "v0/tests/log_on_line.c2";
|
|
loc.line_text.data = "int main() []";
|
|
loc.line_text.length = 13;
|
|
loc.line = 1;
|
|
loc.column_start = 12;
|
|
loc.column_end = 13;
|
|
|
|
log_on_line(&loc, 13, "unexpected token");
|
|
assert_log_file("expected formatted error message");
|
|
}
|
|
|
|
static void test_log_on_line_variadic(void) {
|
|
Location loc;
|
|
loc.filename = "v0/tests/log_on_line_variadic.c2";
|
|
loc.line_text.data = "int main() []";
|
|
loc.line_text.length = 13;
|
|
loc.line = 1;
|
|
loc.column_start = 12;
|
|
loc.column_end = 13;
|
|
|
|
log_on_line(&loc, 13, "unexpected token '%c'", 'x');
|
|
assert_log_file("expected formatted error message with variadic args");
|
|
}
|