Update test paths after flattening v0 layout

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-24 08:20:54 +02:00
parent 7ff3f76de5
commit 4939a74752
8 changed files with 107 additions and 3 deletions
-65
View File
@@ -1,65 +0,0 @@
#include "test.h"
#include "../src/buffer.h"
#include <setjmp.h>
#include <stdio.h>
static jmp_buf s_testJmp;
static const char* s_failMsg;
void fail(const char* msg) {
s_failMsg = msg;
longjmp(s_testJmp, 1);
}
typedef struct {
const char* name;
Test func;
} TestCase;
#include "test_buffer.c"
static int s_totalTests;
static int s_greenTests;
static TestCase s_tests[] = {
{"buffer_string_reads_chars", test_buffer_string_reads_chars},
{"buffer_string_eof", test_buffer_string_eof},
{"buffer_string_eof_after_content", test_buffer_string_eof_after_content},
{"buffer_file_reads_chars", test_buffer_file_reads_chars},
{"buffer_file_open_fail", test_buffer_file_open_fail},
};
int main(int argc, char** argv) {
(void)argc;
(void)argv;
s_totalTests = sizeof(s_tests) / sizeof(s_tests[0]);
s_greenTests = 0;
const char* failedTests[s_totalTests + 1];
int failedCount = 0;
for (int i = 0; i < s_totalTests; i++) {
printf("%s...", s_tests[i].name);
s_failMsg = NULL;
if (setjmp(s_testJmp) == 0) {
s_tests[i].func();
printf(" [OK]\n");
s_greenTests++;
} else {
printf(" [FAIL]: %s\n", s_failMsg ? s_failMsg : "");
failedTests[failedCount++] = s_tests[i].name;
}
}
if (failedCount > 0) {
printf("\nFailed tests:\n");
for (int i = 0; i < failedCount; i++) {
printf(" - %s\n", failedTests[i]);
}
}
printf("\n%d/%d tests passed.\n", s_greenTests, s_totalTests);
return failedCount > 0 ? 1 : 0;
}
-15
View File
@@ -1,15 +0,0 @@
/**
* Contains test assertions routines.
*/
#ifndef TEST_H
#define TEST_H
typedef void (*Test)(void);
/**
* Fails a test.
* @param msg The message to print to the console.
*/
void fail(const char* msg);
#endif
-43
View File
@@ -1,43 +0,0 @@
#include "test.h"
#include "../src/buffer.h"
#include <stdio.h>
// @copilot add test for reading from a file.
// Create test_buffer_xyz.txt if you need multiple,
// otherwise simply test_buffer.txt
static void test_buffer_string_reads_chars(void) {
Buffer* buf = buffer_open_string("hi");
if (buffer_read(buf) != 'h') fail("expected 'h'");
if (buffer_read(buf) != 'i') fail("expected 'i'");
buffer_close(buf);
}
static void test_buffer_string_eof(void) {
Buffer* buf = buffer_open_string("");
if (buffer_read(buf) != (char)-1) fail("expected -1 on empty string");
buffer_close(buf);
}
static void test_buffer_string_eof_after_content(void) {
Buffer* buf = buffer_open_string("a");
buffer_read(buf);
if (buffer_read(buf) != (char)-1) fail("expected -1 after end of string");
buffer_close(buf);
}
static void test_buffer_file_reads_chars(void) {
Buffer* buf = buffer_open_file("v0/tests/test_buffer.txt");
if (buf == NULL) fail("could not open file");
if (buffer_read(buf) != 'a') fail("expected 'a'");
if (buffer_read(buf) != 'b') fail("expected 'b'");
if (buffer_read(buf) != 'c') fail("expected 'c'");
if (buffer_read(buf) != '\n') fail("expected newline after content");
if (buffer_read(buf) != (char)-1) fail("expected -1 after file");
buffer_close(buf);
}
static void test_buffer_file_open_fail(void) {
Buffer* buf = buffer_open_file("v0/tests/does_not_exist.txt");
if (buf != NULL) fail("expected NULL for non-existent file");
}
-1
View File
@@ -1 +0,0 @@
abc