mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-17 15:54:07 +10:00
Wrote some small tests
This commit is contained in:
@@ -12,7 +12,7 @@ OBJ = $(addprefix $(ODIR)/,$(TARGETS:../source/%.c=%.o)) $(addprefix $(ODIR)/,$(
|
||||
all: $(OBJ) $(TESTS:%.c=../$(OUTDIR)/%.exe)
|
||||
|
||||
../$(OUTDIR)/%.exe: $(ODIR)/%.o
|
||||
$(CC) -o $@ $< $(TARGETS:../source/%.c=$(ODIR)/%.o) $(CFLAGS) $(LIBS)
|
||||
@$(CC) -o $@ $< $(TARGETS:../source/%.c=$(ODIR)/%.o) $(CFLAGS) $(LIBS)
|
||||
$@
|
||||
|
||||
$(OBJ): | $(ODIR)
|
||||
@@ -21,10 +21,10 @@ $(ODIR):
|
||||
mkdir $(ODIR)
|
||||
|
||||
$(ODIR)/%.o: %.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
@$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
$(ODIR)/%.o: ../source/%.c
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
@$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
|
||||
50
test/test_literal.c
Normal file
50
test/test_literal.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "literal.h"
|
||||
|
||||
#include "memory.h"
|
||||
#include "console_colors.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
{
|
||||
//test a single null literal
|
||||
Literal literal = TO_NULL_LITERAL;
|
||||
|
||||
//
|
||||
if (!IS_NULL(literal)) {
|
||||
fprintf(stderr, ERROR "ERROR: null literal failed\n" RESET);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
//test boolean literals
|
||||
Literal t = TO_BOOLEAN_LITERAL(true);
|
||||
Literal f = TO_BOOLEAN_LITERAL(false);
|
||||
|
||||
//
|
||||
if (!IS_TRUTHY(t) || IS_TRUTHY(f)) {
|
||||
fprintf(stderr, ERROR "ERROR: boolean literal failed\n" RESET);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char* buffer = ALLOCATE(char, 128);
|
||||
|
||||
snprintf(buffer, 128, "Hello world");
|
||||
|
||||
Literal literal = TO_STRING_LITERAL(buffer, 128);
|
||||
|
||||
freeLiteral(literal);
|
||||
}
|
||||
|
||||
//check allocated memory
|
||||
if (getAllocatedMemoryCount() != 0) {
|
||||
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf(NOTICE "All good\n" RESET);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user