From 1a2249a0da6f309fc06febe2bea30c259d53a227 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Mon, 20 Jan 2025 16:02:24 -0500 Subject: [PATCH] Fixed tests and Makefile for the last time. --- Makefile | 2 +- src/global.c | 6 ++++++ src/include/global.h | 4 ++++ src/main.c | 6 ++---- test/test_ast.c | 21 +++++++++++++++++++++ test/test_dstr.c | 3 +-- 6 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/global.c create mode 100644 src/include/global.h create mode 100644 test/test_ast.c diff --git a/Makefile b/Makefile index b232b06..fbe70c3 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ $(TEST_OBJ_DIR)/test_%.o: $(TEST_DIR)/test_%.c $(CC) $(CFLAGS) -c $< -o $@ # Link final test binary. -$(TEST_BUILD_DIR)/test_%.out: $(TEST_OBJ_DIR)/test_%.o $(OBJ_DIR)/%.o $(UNITY_OBJ) +$(TEST_BUILD_DIR)/test_%.out: $(TEST_OBJ_DIR)/test_%.o $(OBJ_DIR)/grammar.o $(OBJ_FILES_NOMAIN) $(UNITY_OBJ) @ mkdir -p $(TEST_BUILD_DIR) @ $(PRINT) "$(WHITE_BOLD)Linking test binary $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)" $(LINK) -o $@ $? $(LDFLAGS) diff --git a/src/global.c b/src/global.c new file mode 100644 index 0000000..39f9e21 --- /dev/null +++ b/src/global.c @@ -0,0 +1,6 @@ +#include "include/global.h" + +#include + +// Global input text. +char* inp = NULL; diff --git a/src/include/global.h b/src/include/global.h new file mode 100644 index 0000000..99c2ea9 --- /dev/null +++ b/src/include/global.h @@ -0,0 +1,4 @@ +#ifndef GLOBAL_H +#define GLOBAL_H + +#endif diff --git a/src/main.c b/src/main.c index dca3d01..527aa60 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include +#include "include/global.h" #include "include/ast.h" #include "include/dstr.h" #include "include/exec.h" @@ -11,10 +12,7 @@ // Global Abstract Syntax Tree. extern AST* root; - -// Global input text. -char* inp = NULL; - +extern char* inp; extern int yyparse(); int main(int argc, char** argv) { diff --git a/test/test_ast.c b/test/test_ast.c new file mode 100644 index 0000000..a878228 --- /dev/null +++ b/test/test_ast.c @@ -0,0 +1,21 @@ +#include "../src/include/ast.h" +#include "Unity/src/unity.h" +#include "Unity/src/unity_internals.h" + +void setUp() {} +void tearDown() {} + +void test_ast_num() { + ASTNumData* num = ast_num_data_init(12.0); + AST* ast = ast_init(AST_TYPE_NUM, num); + + TEST_ASSERT_EQUAL(AST_TYPE_NUM, ast->type); + TEST_ASSERT_EQUAL(12.0, *(ASTNumData*)ast->data); +} + + +int main() { + UNITY_BEGIN(); + RUN_TEST(test_ast_num); + return UNITY_END(); +} diff --git a/test/test_dstr.c b/test/test_dstr.c index 0d7881b..cd0bef3 100644 --- a/test/test_dstr.c +++ b/test/test_dstr.c @@ -69,8 +69,7 @@ void test_dstr_appendch() { TEST_ASSERT_EQUAL(DSTR_INITSZ * 2, dstr->sz); } -// not needed when using generate_test_runner.rb -int main(void) { +int main() { UNITY_BEGIN(); RUN_TEST(test_dstr_init); RUN_TEST(test_dstr_append);