Refactor test interface

This commit is contained in:
2026-04-29 10:59:06 +02:00
parent 34b7939f76
commit 3288efdfd7
5 changed files with 98 additions and 75 deletions
+23 -1
View File
@@ -5,6 +5,7 @@
#define TEST_H
#include "token.h"
#include "ast.h"
typedef void (*Test)(void);
@@ -35,6 +36,17 @@ void assert_not_null(void* ptr, const char* msg);
*/
void assert_str(const char* expected, const char* actual, const char* msg);
/**
* Asserts that a string has the expected value.
*
* Calls `fail` if the assertion does not hold.
*
* @param expected The expected value. This is typically a string literal.
* @param actual The actual value. This is typically an expression.
* @param msg The message to print if these do not match.
*/
void assert_string(const char* expected, String actual, const char* msg);
/**
* Asserts that the logged output matches the expected value.
*/
@@ -66,7 +78,17 @@ void assert_false(bool condition, const char* msg);
/**
* Get the token stream used for this test.
* It reads from the `v0/tests/xyz.c2` file, where xyz is the test name.
*
* At the end of the test, the tokenstream will be freed automatically by the test harness.
*/
TokenStream* tokenstream_get_test(void);
TokenStream* test_get_tokenstream(void);
/**
* Gets a parsed module for the this test.
* It reads from the `v0/tests/xyz.c2` file, where xyz is the test name.
*
* At the end of the test, the AST will be freed automatically by the test harness.
*/
Module* test_get_ast(void);
#endif