Fixed tests and Makefile for the last time.

This commit is contained in:
Jacob Signorovitch 2025-01-20 16:02:24 -05:00
parent 3ab2696705
commit 1a2249a0da
6 changed files with 35 additions and 7 deletions

View File

@ -86,7 +86,7 @@ $(TEST_OBJ_DIR)/test_%.o: $(TEST_DIR)/test_%.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
# Link final test binary. # 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) @ mkdir -p $(TEST_BUILD_DIR)
@ $(PRINT) "$(WHITE_BOLD)Linking test binary $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)" @ $(PRINT) "$(WHITE_BOLD)Linking test binary $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)"
$(LINK) -o $@ $? $(LDFLAGS) $(LINK) -o $@ $? $(LDFLAGS)

6
src/global.c Normal file
View File

@ -0,0 +1,6 @@
#include "include/global.h"
#include <stdlib.h>
// Global input text.
char* inp = NULL;

4
src/include/global.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#endif

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "include/global.h"
#include "include/ast.h" #include "include/ast.h"
#include "include/dstr.h" #include "include/dstr.h"
#include "include/exec.h" #include "include/exec.h"
@ -11,10 +12,7 @@
// Global Abstract Syntax Tree. // Global Abstract Syntax Tree.
extern AST* root; extern AST* root;
extern char* inp;
// Global input text.
char* inp = NULL;
extern int yyparse(); extern int yyparse();
int main(int argc, char** argv) { int main(int argc, char** argv) {

21
test/test_ast.c Normal file
View File

@ -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();
}

View File

@ -69,8 +69,7 @@ void test_dstr_appendch() {
TEST_ASSERT_EQUAL(DSTR_INITSZ * 2, dstr->sz); TEST_ASSERT_EQUAL(DSTR_INITSZ * 2, dstr->sz);
} }
// not needed when using generate_test_runner.rb int main() {
int main(void) {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_dstr_init); RUN_TEST(test_dstr_init);
RUN_TEST(test_dstr_append); RUN_TEST(test_dstr_append);