This commit is contained in:
2026-04-16 17:41:50 +10:00
2 changed files with 54 additions and 0 deletions

50
libs/tests/tests.c Normal file
View File

@@ -0,0 +1,50 @@
#include "uthash.h"
#include <stdio.h>
#include <groundvm.h>
#include <groundext.h>
#include <ansii.h>
GroundValue testsRun(GroundScope* scope, List args) {
GroundObject* testsStruct = args.values[0].data.customVal;
int totalTests = 0, successful = 0, fail = 0;
GroundObjectField* entry, *temp;
HASH_ITER(hh, testsStruct->fields, entry, temp) {
if (entry) {
totalTests++;
if (entry->value.type != FUNCTION) {
ERROR("The given tests struct can't have any struct fields, only methods!", "WrongType");
}
GroundValue success = groundRunFunction(entry->value.data.fnVal, 0);
if (success.type != BOOL) {
ERROR("Your tests should return a boolean.", "ReturnTypeMismatch");
}
if (success.data.boolVal) {
successful++;
printf(ESC_GREEN_FG ESC_BOLD ".");
} else {
fail++;
printf(ESC_RED_FG ESC_BOLD ".");
}
}
}
printf(ESC_RESET "\n\n/============================\\\n");
printf("- Total : %d\n", totalTests);
printf("- Successful: %d\n", successful);
printf("- Fail : %d\n", fail);
printf("\\============================/\n");
return groundCreateValue(INT, 0);
}
void ground_init(GroundScope* scope) {
groundAddNativeFunction(scope, "tests_Run", testsRun, INT, 1, CUSTOM, "testsStruct");
}

View File

@@ -1,5 +1,9 @@
#include "types.h" #include "types.h"
#ifdef GROUND_COMPILE_WITH_TRAM
#include <tram.h> #include <tram.h>
#endif
void compileGroundProgram(GroundProgram* program, char* name); void compileGroundProgram(GroundProgram* program, char* name);
#ifdef GROUND_COMPILE_WITH_TRAM
void compileGroundInstruction(GroundInstruction* instruction, Tram_Program* program); void compileGroundInstruction(GroundInstruction* instruction, Tram_Program* program);
#endif