Compare commits

..

3 Commits

Author SHA1 Message Date
35322de3ac Added validation tests to Makefile. 2025-01-04 10:48:01 -05:00
c3d8d6f8e5 Validation tests. 2025-01-04 10:45:34 -05:00
1f2bca5028 Not sure. 2025-01-04 10:45:11 -05:00
3 changed files with 72 additions and 1 deletions

View File

@ -15,6 +15,7 @@ CC = clang
LINK = clang LINK = clang
CFLAGS = -Wall -DDBG -ggdb CFLAGS = -Wall -DDBG -ggdb
LDFLAGS = -lm LDFLAGS = -lm
BATS = bats
SRC_FILES = $(wildcard $(SRC_DIR)/*.c) SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES)) OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
@ -27,6 +28,7 @@ UNITY_OBJ = $(TEST_BUILD_DIR)/unity.o
TEST_SRC_FILES = $(wildcard $(TEST_DIR)/*.c) TEST_SRC_FILES = $(wildcard $(TEST_DIR)/*.c)
TEST_OBJ_FILES = $(patsubst $(TEST_DIR)/%.c, $(TEST_OBJ_DIR)/%.o, $(TEST_SRC_FILES)) TEST_OBJ_FILES = $(patsubst $(TEST_DIR)/%.c, $(TEST_OBJ_DIR)/%.o, $(TEST_SRC_FILES))
TEST_BIN_FILES = $(patsubst $(TEST_DIR)/%.c, $(TEST_BUILD_DIR)/%.out, $(TEST_SRC_FILES)) TEST_BIN_FILES = $(patsubst $(TEST_DIR)/%.c, $(TEST_BUILD_DIR)/%.out, $(TEST_SRC_FILES))
TEST_VAL_DIR = $(TEST_DIR)/validation
RESETCOLOR = \033[0m RESETCOLOR = \033[0m
WHITE = $(RESETCOLOR)\033[37m WHITE = $(RESETCOLOR)\033[37m
@ -87,8 +89,11 @@ $(TEST_BUILD_DIR)/test_%.out: $(TEST_OBJ_DIR)/test_%.o $(OBJ_DIR)/%.o $(UNITY_OB
# Run the test files. # Run the test files.
test: $(TEST_BIN_FILES) test: $(TEST_BIN_FILES)
@ echo -e "$(WHITE_BOLD)Running tests...$(RESETCOLOR)" @ echo -e "$(WHITE_BOLD)Running unit tests...$(RESETCOLOR)"
for test in $<; do ./$${test}; done for test in $<; do ./$${test}; done
@ echo -e "$(WHITE_BOLD)Running validation tests...$(RESETCOLOR)"
$(BATS) $(TEST_VAL_DIR)
clean: clean:
@ echo -e "$(WHITE_BOLD)Cleaning up...$(RESETCOLOR)" @ echo -e "$(WHITE_BOLD)Cleaning up...$(RESETCOLOR)"

View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "include/ast.h" #include "include/ast.h"
#include "include/dstr.h" #include "include/dstr.h"
@ -18,6 +19,12 @@ extern int yyparse();
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (argc - 1 && strlen(argv[1]) > 0 && (inp = argv[1]) && !yyparse()) {
log_dbg("Parsed successfully!\n");
exec_print(exec_expr(root));
exit(0);
}
while (1) { while (1) {
Dstr* ln = dstr_init(); Dstr* ln = dstr_init();
char c; char c;

59
test/validation/test.bats Normal file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env bats
bin() { ./scl.out $1 | tail -n1; }
@test "simple addition" {
run bin "1+1"
[ "$output" = "= 2.000000" ]
run bin "-1+1"
[ "$output" = "= 0.000000" ]
run bin "1+-1"
[ "$output" = "= 0.000000" ]
run bin "-1+-1"
[ "$output" = "= -2.000000" ]
}
@test "simple subtraction" {
run bin "1-1"
[ "$output" = "= 0.000000" ]
run bin "-1-1"
[ "$output" = "= -2.000000" ]
run bin "1--1"
[ "$output" = "= 2.000000" ]
run bin "-1--1"
[ "$output" = "= 0.000000" ]
}
@test "simple multiplication" {
run bin "1*2"
[ "$output" = "= 2.000000" ]
run bin "-1*2"
[ "$output" = "= -2.000000" ]
run bin "1*-1"
[ "$output" = "= -1.000000" ]
run bin "-1*-1"
[ "$output" = "= 1.000000" ]
}
@test "simple division" {
run bin "1/2"
[ "$output" = "= 0.500000" ]
run bin "-1/2"
[ "$output" = "= -0.500000" ]
run bin "1/-1"
[ "$output" = "= -1.000000" ]
run bin "-1/-1"
[ "$output" = "= 1.000000" ]
}