Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
project(gherkin-cpp)
cmake_minimum_required(VERSION 3.0)

option(BUILD_SHARED_LIBS "Build shared library." OFF)

LIST(APPEND GHERKIN_CPP_SRS
src/compiler.cpp
src/parser.cpp
)

ADD_LIBRARY(gherkin-cpp ${GHERKIN_CPP_SRS})
ADD_LIBRARY(gherkin-cpp::gherkin-cpp ALIAS gherkin-cpp)

TARGET_INCLUDE_DIRECTORIES(gherkin-cpp
PUBLIC ${PROJECT_SOURCE_DIR}/include
)

ADD_SUBDIRECTORY(libs/fmem)
TARGET_LINK_LIBRARIES(gherkin-cpp PUBLIC fmem)

ADD_SUBDIRECTORY(libs/gherkin-c)
TARGET_LINK_LIBRARIES(gherkin-cpp PUBLIC gherkin)

ADD_SUBDIRECTORY(test)
14 changes: 14 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ADD_EXECUTABLE(gherkin-cpp-test main.cpp)
TARGET_LINK_LIBRARIES(gherkin-cpp-test PUBLIC gherkin-cpp)

ADD_CUSTOM_TARGET(gherkin-cpp-test.run DEPENDS testgherkin-cpp-)

FILE(COPY testdata DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

ADD_CUSTOM_COMMAND(
TARGET gherkin-cpp-test.run
POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_tests.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running the tests"
)
64 changes: 64 additions & 0 deletions test/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/python3
import subprocess
import os

# prevent stack-trace on ctrl+c
import signal
import sys
signal.signal(signal.SIGINT, lambda x, y: sys.exit(0))

import filecmp

class bcolors:
OKGREEN = '\033[32m'
FAIL = '\033[91m'
ENDC = '\033[0m'

targets = []

# collect the list of all tests
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".feature"):
targets.append(os.path.join(root, file))

overal_result = True

for target in targets:
#print(target)
target_result = target+".result"
outfile = open(target_result, "w")
run_result = subprocess.run(["valgrind", "--leak-check=full", "--error-exitcode=-1", "./test", target], stdout=outfile, stderr=subprocess.DEVNULL)
#print(run_result.returncode)


# quick hack to keep the .out files untouched but still run from the test folder
fin = open(target_result, "rt")
data = fin.read()
data = data.replace('"uri":"./testdata/', '"uri":"test/testdata/')
fin.close()
fin = open(target_result, "wt")
fin.write(data)
fin.close()

target_out = target + ".out"
comp = filecmp.cmp(target_out, target_result)
#print("Test run result: " + str(comp))

fixed_target_string = "{0:>70}".format(target)
print(fixed_target_string + " -> ", end='', flush=True)

if comp == True:
colored_status_code = bcolors.OKGREEN + 'OK' + bcolors.ENDC
else:
colored_status_code = bcolors.FAIL + 'FAIL' + bcolors.ENDC
overal_result = False
print(colored_status_code)

if overal_result == True:
os._exit(0)
else:
print("Compare the *.feature.out to the *.feature.result for each failed test")
print("----------------------------------------------------------------------")
print("At least one test failed, so this script exits with an error (exit code 1)")
os._exit(1)