Compare commits

...

2 Commits

Author SHA1 Message Date
seeseemelk 0e826e05e1 Add log framework 2026-04-24 15:14:15 +02:00
seeseemelk 78899f32a6 Update copilot instructions 2026-04-24 14:59:53 +02:00
6 changed files with 69 additions and 1 deletions
+7
View File
@@ -31,3 +31,10 @@ Always check the `specs` directory.
If there is anything unclear, ask the user for clarification.
It is certainly possible that there are contradictions in the
spec that have to be solved first.
## Comitting
Often, the user modifies an interface (typically in a header file), and then asks
the agent to update the implementation.
When creating a commit, make sure that both the user's and the agent's modifications
are included in the commit.
+1 -1
View File
@@ -1,4 +1,4 @@
V0_SRC := v0/main.c v0/token.c v0/parser.c
V0_SRC := v0/main.c v0/token.c v0/parser.c v0/log.c
# V0_TEST must only include `v0/test.c` itself, as all other test Csource files are
# included directly into `v0/test.c` using `#include "test_xyz.c"`.
+16
View File
@@ -0,0 +1,16 @@
#include "log.h"
#include <stdio.h>
static LogError* s_logError = NULL;
void log_set_output(LogError* destination) {
s_logError = destination;
}
void log_error(const char* msg) {
if (s_logError != NULL) {
s_logError(msg);
} else {
fprintf(stderr, "Error: %s\n", msg);
}
}
+22
View File
@@ -0,0 +1,22 @@
/**
* Contains the logging framework used for logging errors during compilation.
*/
#ifndef LOG_H
#define LOG_H
/**
* A method that can log an error.
*/
typedef void LogError(const char* msg);
/**
* Sets the destination for log errors.
*/
void log_set_output(LogError* destination);
/**
* Logs an error to the destination.
*/
void log_error(const char* msg);
#endif
+2
View File
@@ -30,6 +30,7 @@ typedef struct {
#include "test_token.c"
#include "test_parser.c"
#include "test_log.c"
static int s_totalTests;
static int s_greenTests;
@@ -44,6 +45,7 @@ static TestCase s_tests[] = {
{"tokenstream_void_function_signature", test_tokenstream_void_function_signature},
{"tokenstream_info", test_tokenstream_info},
{"parser_module_name", test_parser_module_name},
{"log_error", test_log_error},
};
+21
View File
@@ -0,0 +1,21 @@
#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
}