Wrote value, chunk, memory sections, tested value

chunk and memory remain untested for now
This commit is contained in:
2024-08-13 23:42:14 +10:00
parent 190294e5d9
commit e6ad46f1ff
11 changed files with 204 additions and 10 deletions

39
tests/cases/test_value.c Normal file
View File

@@ -0,0 +1,39 @@
#include "toy_value.h"
#include "toy_console_colors.h"
#include <assert.h>
#include <stdio.h>
int main() {
//test for the correct size
{
if (sizeof(Toy_Value) != 8) {
fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_Value' is an unexpected size in memory\n" TOY_CC_RESET);
return -1;
}
}
//test creating a null
{
Toy_Value v = TOY_VALUE_TO_NULL();
if (!TOY_VALUE_IS_NULL(v)) {
fprintf(stderr, TOY_CC_ERROR "ERROR: creating a 'null' value failed\n" TOY_CC_RESET);
return -1;
}
}
//test creating values
{
Toy_Value t = TOY_VALUE_TO_BOOLEAN(true);
Toy_Value f = TOY_VALUE_TO_BOOLEAN(false);
if (!TOY_VALUE_IS_TRUTHY(t) || TOY_VALUE_IS_TRUTHY(f)) {
fprintf(stderr, TOY_CC_ERROR "ERROR: 'boolean' value failed\n" TOY_CC_RESET);
return -1;
}
}
printf(TOY_CC_NOTICE "All good\n" TOY_CC_RESET);
return 0;
}

View File

@@ -3,14 +3,15 @@ CFLAGS=-g -Wall -Werror -Wno-unused-parameter -Wno-unused-function -Wno-unused-v
LIBS=-lm
#directories
TEST_SOURCEDIR=../$(TOY_SOURCEDIR)
TEST_ROOTDIR=..
TEST_SOURCEDIR=$(TEST_ROOTDIR)/$(TOY_SOURCEDIR)
TEST_CASESDIR=cases
TEST_OUTDIR=out
TEST_OBJDIR=obj
#file names
TEST_SOURCEFILES=$(wildcard $(TEST_SOURCEDIR)/*.c)
TEST_SOURCEFILES=$(addprefix $(TOY_ROOTDIR)/,$(TOY_SOURCEFILES))
TEST_CASESFILES=$(wildcard $(TEST_CASESDIR)/*.c)
#build the object files, compile the test cases, and run
@@ -39,7 +40,7 @@ $(TEST_OBJDIR)/%.o: $(TEST_CASESDIR)/%.c
#final linking step (with extra flags to strip dead code)
$(TEST_OUTDIR)/%.exe: $(TEST_OBJDIR)/%.o
@$(CC) -o $@ $(shell find $(TEST_OBJDIR) -name '*.o') $(CFLAGS) $(LIBS) -Wl,--gc-sections
@$(CC) -o $@ $< $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) $(CFLAGS) $(LIBS) -Wl,--gc-sections
$@
#util commands