feat: add C API test infrastructure with foreign method binding support
Add a new test framework for exercising the Wren C embedding API directly from C code, including a Makefile target, test runner modifications, and the first API test case for boolean return values. The build system now compiles test sources from `test/api/` into a separate test executable, and the CLI's `createVM` and `runFile` functions accept an optional `WrenBindForeignMethodFn` callback to enable foreign method binding in tests. The test runner (`script/test.py`) is refactored to support both script and API test types, passing the test name instead of the full path for API tests. The initial `return_bool` test verifies that `wrenReturnBool` correctly returns `true` and `false` from foreign methods.
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@
|
||||
|
||||
static int runRepl()
|
||||
{
|
||||
WrenVM* vm = createVM();
|
||||
WrenVM* vm = createVM(NULL);
|
||||
|
||||
printf("\\\\/\"-\n");
|
||||
printf(" \\_/ wren v0.0.0\n");
|
||||
@@ -50,7 +50,7 @@ int main(int argc, const char* argv[])
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
runFile(argv[1]);
|
||||
runFile(NULL, argv[1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
+4
-4
@@ -4,11 +4,11 @@
|
||||
#include "io.h"
|
||||
#include "vm.h"
|
||||
|
||||
WrenVM* createVM()
|
||||
WrenVM* createVM(WrenBindForeignMethodFn bindForeign)
|
||||
{
|
||||
WrenConfiguration config;
|
||||
|
||||
config.bindForeignMethodFn = NULL;
|
||||
config.bindForeignMethodFn = bindForeign;
|
||||
config.loadModuleFn = readModule;
|
||||
|
||||
// Since we're running in a standalone process, be generous with memory.
|
||||
@@ -22,7 +22,7 @@ WrenVM* createVM()
|
||||
return wrenNewVM(&config);
|
||||
}
|
||||
|
||||
void runFile(const char* path)
|
||||
void runFile(WrenBindForeignMethodFn bindForeign, const char* path)
|
||||
{
|
||||
// Use the directory where the file is as the root to resolve imports
|
||||
// relative to.
|
||||
@@ -42,7 +42,7 @@ void runFile(const char* path)
|
||||
exit(66);
|
||||
}
|
||||
|
||||
WrenVM* vm = createVM();
|
||||
WrenVM* vm = createVM(bindForeign);
|
||||
|
||||
WrenInterpretResult result = wrenInterpret(vm, path, source);
|
||||
|
||||
|
||||
+2
-2
@@ -4,11 +4,11 @@
|
||||
#include "wren.h"
|
||||
|
||||
// Creates a new Wren VM with the CLI's module loader and other configuration.
|
||||
WrenVM* createVM();
|
||||
WrenVM* createVM(WrenBindForeignMethodFn bindForeign);
|
||||
|
||||
// Executes the Wren script at [path] in a new VM.
|
||||
//
|
||||
// Exits if the script failed or could not be loaded.
|
||||
void runFile(const char* path);
|
||||
void runFile(WrenBindForeignMethodFn bindForeign, const char* path);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user