summaryrefslogtreecommitdiffhomepage
path: root/tests/cram
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-04-27 12:43:38 +0200
committerGitHub <noreply@github.com>2021-04-27 12:43:38 +0200
commit8469c4b1be228f42c46f08852f028f7801b93cc9 (patch)
treef61121e8f89e39787a960e621fc8492e57fc4bc0 /tests/cram
parentf360350bd874aeec0806c8df02c7a20a54c44406 (diff)
parent64eec7f90e945696572ee076b75d1f35e8f2248a (diff)
Merge pull request #5 from jow-/new-type-system
New type system
Diffstat (limited to 'tests/cram')
-rw-r--r--tests/cram/CMakeLists.txt27
-rw-r--r--tests/cram/test_basic.t59
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/cram/CMakeLists.txt b/tests/cram/CMakeLists.txt
new file mode 100644
index 0000000..a93add5
--- /dev/null
+++ b/tests/cram/CMakeLists.txt
@@ -0,0 +1,27 @@
+FIND_PACKAGE(PythonInterp 3 REQUIRED)
+FILE(GLOB test_cases "test_*.t")
+
+SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv")
+SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip")
+SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram")
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${PYTHON_VENV_CRAM}
+ COMMAND ${PYTHON_EXECUTABLE} -m venv ${PYTHON_VENV_DIR}
+ COMMAND ${PYTHON_VENV_PIP} install cram
+)
+ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM})
+
+ADD_TEST(
+ NAME cram
+ COMMAND ${PYTHON_VENV_CRAM} ${test_cases} ${test_cases_san}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "BUILD_BIN_DIR=$<TARGET_FILE_DIR:ucode>")
+
+IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "UCODE_BIN=$<TARGET_FILE:ucode-san>")
+ELSE()
+ SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "UCODE_BIN=valgrind --quiet --leak-check=full $<TARGET_FILE:ucode>")
+ENDIF()
diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t
new file mode 100644
index 0000000..3d4cd9e
--- /dev/null
+++ b/tests/cram/test_basic.t
@@ -0,0 +1,59 @@
+setup common environment:
+
+ $ [ -n "$BUILD_BIN_DIR" ] && export PATH="$BUILD_BIN_DIR:$PATH"
+ $ alias ucode="$UCODE_BIN"
+
+ $ for m in $BUILD_BIN_DIR/*.so; do
+ > ln -s "$m" "$(pwd)/$(basename $m)"; \
+ > done
+
+check that ucode provides exepected help:
+
+ $ ucode | sed 's/ucode-san/ucode/'
+ == Usage ==
+
+ # ucode [-d] [-l] [-r] [-S] [-e '[prefix=]{"var": ...}'] [-E [prefix=]env.json] {-i <file> | -s "ucode script..."}
+ -h, --help\tPrint this help (esc)
+ -i file\tSpecify an ucode script to parse (esc)
+ -s "ucode script..."\tSpecify an ucode fragment to parse (esc)
+ -d Instead of executing the script, dump the resulting AST as dot
+ -l Do not strip leading block whitespace
+ -r Do not trim trailing block newlines
+ -S Enable strict mode
+ -e Set global variables from given JSON object
+ -E Set global variables from given JSON file
+ -m Preload given module
+
+check that ucode prints greetings:
+
+ $ ucode -s "{% print('hello world') %}"
+ hello world (no-eol)
+
+check that ucode provides proper error messages:
+
+ $ ucode -m foo
+ One of -i or -s is required
+ [1]
+
+ $ ucode -m foo -s ' '
+ Runtime error: No module named 'foo' could be found
+ At start of program
+
+ [1]
+
+ $ touch moo; ucode -m foo -i moo
+ Runtime error: No module named 'foo' could be found
+ At start of program
+
+ [1]
+
+check that ucode can load fs module:
+
+ $ ucode -m fs
+ One of -i or -s is required
+ [1]
+
+ $ ucode -m fs -s ' '
+ (no-eol)
+
+ $ touch moo; ucode -m fs -i moo