Refactor parser
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
static jmp_buf s_testJmp;
|
||||
static const char* s_failMsg = NULL;
|
||||
static char s_failMsg[1024];
|
||||
static char* s_logOutput = NULL;
|
||||
static const char* s_currentTestName = NULL;
|
||||
static char* s_testSource = NULL;
|
||||
@@ -18,7 +18,12 @@ static Module* s_currentModule = NULL;
|
||||
static TokenStream* s_currentTokenStream = NULL;
|
||||
|
||||
void fail(const char* msg) {
|
||||
s_failMsg = msg;
|
||||
if (msg) {
|
||||
strncpy(s_failMsg, msg, sizeof(s_failMsg) - 1);
|
||||
s_failMsg[sizeof(s_failMsg) - 1] = '\0';
|
||||
} else {
|
||||
s_failMsg[0] = '\0';
|
||||
}
|
||||
longjmp(s_testJmp, 1);
|
||||
}
|
||||
|
||||
@@ -211,6 +216,7 @@ static TestCase s_tests[] = {
|
||||
TEST(test_tokenstream_keywords_and_symbols)
|
||||
TEST(test_tokenstream_open_fail)
|
||||
TEST(test_tokenstream_parentheses_and_brackets)
|
||||
TEST(test_tokenstream_primitive_types)
|
||||
TEST(test_tokenstream_simple_keyword)
|
||||
TEST(test_tokenstream_unknown_token)
|
||||
TEST(test_tokenstream_void_function_signature)
|
||||
@@ -238,7 +244,7 @@ int main(int argc, char** argv) {
|
||||
log_set_output(log_append);
|
||||
printf("%s...", s_tests[i].name);
|
||||
fflush(stdout);
|
||||
s_failMsg = NULL;
|
||||
s_failMsg[0] = '\0';
|
||||
|
||||
if (setjmp(s_testJmp) == 0) {
|
||||
log_clear();
|
||||
@@ -252,8 +258,14 @@ int main(int argc, char** argv) {
|
||||
} else {
|
||||
printf(" [FAIL]: %s\n", s_failMsg[0] ? s_failMsg : "");
|
||||
failedTests[failedCount++] = s_tests[i].name;
|
||||
|
||||
// Log output on failure
|
||||
if (s_logOutput && s_logOutput[0]) {
|
||||
printf("%s\n", s_logOutput);
|
||||
}
|
||||
}
|
||||
|
||||
// Free AST and TokenStream after each test
|
||||
if (s_currentModule) {
|
||||
parser_free(s_currentModule);
|
||||
s_currentModule = NULL;
|
||||
|
||||
Reference in New Issue
Block a user