forked from Mirror/wren
Simplify the API tests.
Use fewer test suites with more tests in each one since there's so much boilerplate for defining an API test.
This commit is contained in:
@ -21,9 +21,10 @@
|
||||
# Files.
|
||||
CLI_HEADERS := $(wildcard src/cli/*.h)
|
||||
VM_HEADERS := $(wildcard src/vm/*.h)
|
||||
TEST_HEADERS := $(wildcard test/api/*.h)
|
||||
CLI_SOURCES := $(wildcard src/cli/*.c)
|
||||
VM_SOURCES := $(wildcard src/vm/*.c)
|
||||
TEST_SOURCES := $(shell find test/api -name '*.c')
|
||||
TEST_SOURCES := $(wildcard test/api/*.c)
|
||||
BUILD_DIR := build
|
||||
|
||||
C_WARNINGS := -Wall -Wextra -Werror -Wno-unused-parameter
|
||||
@ -143,7 +144,7 @@ $(BUILD_DIR)/vm/%.o: src/vm/%.c $(VM_HEADERS)
|
||||
@$(CC) -c $(CFLAGS) -Isrc/include -o $@ $(FILE_FLAG) $<
|
||||
|
||||
# Test object files.
|
||||
$(BUILD_DIR)/test/%.o: test/api/%.c $(VM_HEADERS)
|
||||
$(BUILD_DIR)/test/%.o: test/api/%.c $(CLI_HEADERS) $(TEST_HEADERS) $(VM_HEADERS)
|
||||
@printf "%10s %-30s %s\n" $(CC) $< "$(C_OPTIONS)"
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) -c $(CFLAGS) -Isrc/include -Isrc/cli -o $@ $(FILE_FLAG) $<
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn getValueBindForeign(const char* signature);
|
||||
@ -5,10 +5,8 @@
|
||||
#include "vm.h"
|
||||
#include "wren.h"
|
||||
|
||||
#include "get_value/get_value.h"
|
||||
#include "return_bool/return_bool.h"
|
||||
#include "return_double/return_double.h"
|
||||
#include "return_null/return_null.h"
|
||||
#include "value.h"
|
||||
#include "returns.h"
|
||||
|
||||
#define REGISTER_TEST(name, camelCase) \
|
||||
if (strcmp(testName, #name) == 0) return camelCase##BindForeign(fullName)
|
||||
@ -31,10 +29,8 @@ static WrenForeignMethodFn bindForeign(
|
||||
strcat(fullName, ".");
|
||||
strcat(fullName, signature);
|
||||
|
||||
REGISTER_TEST(get_value, getValue);
|
||||
REGISTER_TEST(return_bool, returnBool);
|
||||
REGISTER_TEST(return_double, returnDouble);
|
||||
REGISTER_TEST(return_null, returnNull);
|
||||
REGISTER_TEST(returns, returns);
|
||||
REGISTER_TEST(value, value);
|
||||
|
||||
fprintf(stderr,
|
||||
"Unknown foreign method '%s' for test '%s'\n", fullName, testName);
|
||||
@ -52,12 +48,10 @@ int main(int argc, const char* argv[])
|
||||
|
||||
testName = argv[1];
|
||||
|
||||
// The test script is at "test/api/<test>/<test>.wren".
|
||||
// The test script is at "test/api/<test>.wren".
|
||||
char testPath[256];
|
||||
strcpy(testPath, "test/api/");
|
||||
strcat(testPath, testName);
|
||||
strcat(testPath, "/");
|
||||
strcat(testPath, testName);
|
||||
strcat(testPath, ".wren");
|
||||
|
||||
runFile(bindForeign, testPath);
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "return_bool.h"
|
||||
|
||||
static void returnTrue(WrenVM* vm)
|
||||
{
|
||||
wrenReturnBool(vm, true);
|
||||
}
|
||||
|
||||
static void returnFalse(WrenVM* vm)
|
||||
{
|
||||
wrenReturnBool(vm, false);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn returnBoolBindForeign(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Api.returnTrue") == 0) return returnTrue;
|
||||
if (strcmp(signature, "static Api.returnFalse") == 0) return returnFalse;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn returnBoolBindForeign(const char* signature);
|
||||
@ -1,7 +0,0 @@
|
||||
class Api {
|
||||
foreign static returnTrue
|
||||
foreign static returnFalse
|
||||
}
|
||||
|
||||
IO.print(Api.returnTrue) // expect: true
|
||||
IO.print(Api.returnFalse) // expect: false
|
||||
@ -1,21 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "return_double.h"
|
||||
|
||||
static void returnInt(WrenVM* vm)
|
||||
{
|
||||
wrenReturnDouble(vm, 123456);
|
||||
}
|
||||
|
||||
static void returnFloat(WrenVM* vm)
|
||||
{
|
||||
wrenReturnDouble(vm, 123.456);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn returnDoubleBindForeign(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Api.returnInt") == 0) return returnInt;
|
||||
if (strcmp(signature, "static Api.returnFloat") == 0) return returnFloat;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn returnDoubleBindForeign(const char* signature);
|
||||
@ -1,7 +0,0 @@
|
||||
class Api {
|
||||
foreign static returnInt
|
||||
foreign static returnFloat
|
||||
}
|
||||
|
||||
IO.print(Api.returnInt) // expect: 123456
|
||||
IO.print(Api.returnFloat) // expect: 123.456
|
||||
@ -1,15 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "return_null.h"
|
||||
|
||||
static void implicitNull(WrenVM* vm)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
WrenForeignMethodFn returnNullBindForeign(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Api.implicitNull") == 0) return implicitNull;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn returnNullBindForeign(const char* signature);
|
||||
@ -1,5 +0,0 @@
|
||||
class Api {
|
||||
foreign static implicitNull
|
||||
}
|
||||
|
||||
IO.print(Api.implicitNull == null) // expect: true
|
||||
39
test/api/returns.c
Normal file
39
test/api/returns.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "returns.h"
|
||||
|
||||
static void implicitNull(WrenVM* vm)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
static void returnInt(WrenVM* vm)
|
||||
{
|
||||
wrenReturnDouble(vm, 123456);
|
||||
}
|
||||
|
||||
static void returnFloat(WrenVM* vm)
|
||||
{
|
||||
wrenReturnDouble(vm, 123.456);
|
||||
}
|
||||
|
||||
static void returnTrue(WrenVM* vm)
|
||||
{
|
||||
wrenReturnBool(vm, true);
|
||||
}
|
||||
|
||||
static void returnFalse(WrenVM* vm)
|
||||
{
|
||||
wrenReturnBool(vm, false);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn returnsBindForeign(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Api.implicitNull") == 0) return implicitNull;
|
||||
if (strcmp(signature, "static Api.returnInt") == 0) return returnInt;
|
||||
if (strcmp(signature, "static Api.returnFloat") == 0) return returnFloat;
|
||||
if (strcmp(signature, "static Api.returnTrue") == 0) return returnTrue;
|
||||
if (strcmp(signature, "static Api.returnFalse") == 0) return returnFalse;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
3
test/api/returns.h
Normal file
3
test/api/returns.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn returnsBindForeign(const char* signature);
|
||||
17
test/api/returns.wren
Normal file
17
test/api/returns.wren
Normal file
@ -0,0 +1,17 @@
|
||||
class Api {
|
||||
foreign static implicitNull
|
||||
|
||||
foreign static returnInt
|
||||
foreign static returnFloat
|
||||
|
||||
foreign static returnTrue
|
||||
foreign static returnFalse
|
||||
}
|
||||
|
||||
IO.print(Api.implicitNull == null) // expect: true
|
||||
|
||||
IO.print(Api.returnInt) // expect: 123456
|
||||
IO.print(Api.returnFloat) // expect: 123.456
|
||||
|
||||
IO.print(Api.returnTrue) // expect: true
|
||||
IO.print(Api.returnFalse) // expect: false
|
||||
@ -1,6 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "get_value.h"
|
||||
#include "value.h"
|
||||
|
||||
static WrenValue* value;
|
||||
|
||||
@ -15,7 +15,7 @@ static void getValue(WrenVM* vm)
|
||||
wrenReleaseValue(vm, value);
|
||||
}
|
||||
|
||||
WrenForeignMethodFn getValueBindForeign(const char* signature)
|
||||
WrenForeignMethodFn valueBindForeign(const char* signature)
|
||||
{
|
||||
if (strcmp(signature, "static Api.value=(_)") == 0) return setValue;
|
||||
if (strcmp(signature, "static Api.value") == 0) return getValue;
|
||||
3
test/api/value.h
Normal file
3
test/api/value.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "wren.h"
|
||||
|
||||
WrenForeignMethodFn valueBindForeign(const char* signature);
|
||||
Reference in New Issue
Block a user