Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbekarlsson committed May 4, 2023
1 parent 04a2671 commit e2feed3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compile_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
#- name: install dependencies
#run: sudo apt-get update -y && sudo apt-get install --yes libcmocka-dev libcmocka0
- name: tests
run: git submodule update; git submodule sync; cd tests && make && ./a.out
run: git submodule update; git submodule sync; mkdir -p build && cd build && cmake .. && make && cd tests && ./gpp_test
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,4 @@ init_gpp_deps(gpp)
init_gpp_deps(gpp_static)
init_gpp_deps(gpp_e)

if (UNIT_TEST)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.20)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/inputs DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/context.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)

set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules")

Expand All @@ -17,6 +18,9 @@ message(${source_files})
add_executable(gpp_test ${source_files})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)

include(FetchContent)

include(gpp_deps)

Expand Down
15 changes: 11 additions & 4 deletions tests/src/test_inputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
#include "include/utils.h"
#include <string.h>


//gpp_result_T *gpp_eval(char *source, unsigned int lazy, AST_T *parent,
// AST_T *context, GPPEnv* env, GPPEnv* global_env);

void test_inputs(char* argv[]) {


const char* filepath = "inputs/tmp.html";
GPPEnv env = (GPPEnv){ .base_path = "inputs" };
GPPEnv global_env = (GPPEnv){ .base_path = filepath };

{
printf("Running test: hello-world.html\n");
gpp_result_T *res =
gpp_eval(gpp_read_file("inputs/hello-world.html"), 0, 0, 0, &env);
gpp_eval(gpp_read_file("inputs/hello-world.html"), 0, 0, 0, &env, &global_env);


test_assert(!!res->res, "res->res exists");
Expand All @@ -21,7 +28,7 @@ void test_inputs(char* argv[]) {
{
printf("Running test: arrow-function.html\n");
gpp_result_T *res =
gpp_eval(gpp_read_file("inputs/arrow-function.html"), 0, 0, 0, &env);
gpp_eval(gpp_read_file("inputs/arrow-function.html"), 0, 0, 0, &env, &global_env);
test_assert(!!res->res, "res->res exists");
test_assert(strcmp(res->res, "<li>hello</li><li>world</li>") == 0,
"Receives correct output");
Expand All @@ -30,7 +37,7 @@ void test_inputs(char* argv[]) {
{
printf("Running test: map-context.html\n");
gpp_result_T *res =
gpp_eval(gpp_read_file("inputs/map-context.html"), 0, 0, 0, &env);
gpp_eval(gpp_read_file("inputs/map-context.html"), 0, 0, 0, &env, &global_env);
test_assert(!!res->res, "res->res exists");
test_assert(strcmp(res->res, "<li>Not</li>\n"
"<li>Made</li>\n"
Expand All @@ -46,7 +53,7 @@ void test_inputs(char* argv[]) {

{
printf("Running test: escape.html\n");
gpp_result_T *res = gpp_eval(gpp_read_file("inputs/escape.html"), 0, 0, 0, &env);
gpp_result_T *res = gpp_eval(gpp_read_file("inputs/escape.html"), 0, 0, 0, &env, &global_env);
test_assert(!!res->res, "res->res exists");
test_assert(strcmp(res->res, "&lt;h1&gt;Hello&lt;/h1&gt;") == 0,
"Receives correct output");
Expand Down

0 comments on commit e2feed3

Please sign in to comment.