feat: add api tests for returning double and null values from foreign functions

Introduce two new test suites under test/api/: return_double exercises wrenReturnDouble with integer and floating-point values, and return_null verifies that a foreign function returning nothing yields null. Refactor bindForeign dispatch in main.c to use a REGISTER_TEST macro, rename returnBoolBindForeign to return_boolBindForeign for consistency, and add an exit(1) on unknown foreign methods to prevent silent NULL returns.
This commit is contained in:
Bob Nystrom
2015-05-24 17:04:24 +00:00
parent 2961318302
commit 3297642b65
9 changed files with 66 additions and 7 deletions
+9 -4
View File
@@ -6,6 +6,11 @@
#include "wren.h"
#include "return_bool/return_bool.h"
#include "return_double/return_double.h"
#include "return_null/return_null.h"
#define REGISTER_TEST(name) \
if (strcmp(testName, #name) == 0) return name##BindForeign(fullName)
// The name of the currently executing API test.
const char* testName;
@@ -25,13 +30,13 @@ static WrenForeignMethodFn bindForeign(
strcat(fullName, ".");
strcat(fullName, signature);
if (strcmp(testName, "return_bool") == 0)
{
return returnBoolBindForeign(fullName);
}
REGISTER_TEST(return_bool);
REGISTER_TEST(return_double);
REGISTER_TEST(return_null);
fprintf(stderr,
"Unknown foreign method '%s' for test '%s'\n", fullName, testName);
exit(1);
return NULL;
}