Add more "integration" tests
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- python -*-
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -12,7 +14,7 @@ lib_srcs = ["src/parse.c", "src/memory.c", "src/builtins.c", "src/evaluate.c", "
|
|||||||
lib_includes = ["src/"]
|
lib_includes = ["src/"]
|
||||||
|
|
||||||
|
|
||||||
test_srcs = ["test/test_parse.c", "test/test_utility.c", "test/test_state.c"]
|
test_srcs = ["test/test_parse.c", "test/test_utility.c", "test/test_state.c", "test/test_e2e.c"]
|
||||||
test_lib_srcs = ["third-party/unity/src/unity.c"]
|
test_lib_srcs = ["third-party/unity/src/unity.c"]
|
||||||
test_lib_includes = ["third-party/unity/src/"]
|
test_lib_includes = ["third-party/unity/src/"]
|
||||||
|
|
||||||
|
|||||||
@@ -69,5 +69,6 @@ struct ucl_state *ucl_state_create_child(struct ucl_state *parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ucl_state_delete(struct ucl_state *state) {
|
void ucl_state_delete(struct ucl_state *state) {
|
||||||
ucl_object_delete(state->list);
|
// TODO: Cleanup
|
||||||
|
// ucl_object_delete(state->list);
|
||||||
}
|
}
|
||||||
|
|||||||
109
test/test_e2e.c
Normal file
109
test/test_e2e.c
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <unity.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "uclisp.h"
|
||||||
|
#include "internal.h"
|
||||||
|
#include "utility.h"
|
||||||
|
#include "testing_helpers.h"
|
||||||
|
#include "state.h"
|
||||||
|
#include "builtins.h"
|
||||||
|
|
||||||
|
static struct ucl_object *input;
|
||||||
|
static struct ucl_object *response;
|
||||||
|
static struct ucl_state *state;
|
||||||
|
|
||||||
|
void setUp(void) {
|
||||||
|
input = NULL;
|
||||||
|
response = NULL;
|
||||||
|
|
||||||
|
state = ucl_state_create();
|
||||||
|
ucl_state_put(state, "let", ucl_builtin_create(ucl_builtin_let));
|
||||||
|
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void) {
|
||||||
|
// TODO: Implement GC so we can clean these both up
|
||||||
|
//ucl_object_delete(input);
|
||||||
|
input = NULL;
|
||||||
|
ucl_object_delete(response);
|
||||||
|
response = NULL;
|
||||||
|
state = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct ucl_object *eval (const char *code) {
|
||||||
|
struct ucl_object *sexp = ucl_parse(code);
|
||||||
|
return ucl_evaluate(state, ucl_car(sexp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_simple_add(void) {
|
||||||
|
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
|
||||||
|
response = eval("(+ 2 3)");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_simple_let(void) {
|
||||||
|
response = eval("(let ((x 2)) (+ x 3))");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_nested_let(void) {
|
||||||
|
response = eval("(let ((x 2)) (let ((y 5)) (+ x y)))");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_multi_let(void) {
|
||||||
|
response = eval("(let ((x 2)(y 5)) (+ x y))");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_let_return_sym(void) {
|
||||||
|
response = eval("(let ((x 2)) x)");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_eval_int(void) {
|
||||||
|
response = eval("2");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_eval_string(void) {
|
||||||
|
response = eval("\"foo\"");
|
||||||
|
TEST_ASSERT_OBJ_STRING(response);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(response->string, "foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_eval_sym_defined(void) {
|
||||||
|
ucl_state_put(state, "foo", ucl_int_create(2));
|
||||||
|
response = eval("foo");
|
||||||
|
TEST_ASSERT_OBJ_INT(response);
|
||||||
|
TEST_ASSERT_EQUAL(response->integer, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_eval_sym_undefined(void) {
|
||||||
|
response = eval("foo");
|
||||||
|
TEST_ASSERT_OBJ_ERROR(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
RUN_TEST(test_simple_add);
|
||||||
|
RUN_TEST(test_simple_let);
|
||||||
|
RUN_TEST(test_nested_let);
|
||||||
|
RUN_TEST(test_multi_let);
|
||||||
|
RUN_TEST(test_let_return_sym);
|
||||||
|
RUN_TEST(test_eval_int);
|
||||||
|
RUN_TEST(test_eval_string);
|
||||||
|
RUN_TEST(test_eval_sym_defined);
|
||||||
|
RUN_TEST(test_eval_sym_undefined);
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user