diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b18bb37db..e3ca9d5fc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -330,6 +330,7 @@ endif() set(CMAKE_EXE_LINKER_FLAGS_TESTCOV "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") set(ALL_LIBS ${LEAN_LIBS} ${EXTRA_LIBS}) add_subdirectory(shell) +set(LEAN_LIBS ${LEAN_LIBS} shell) add_subdirectory(emacs) add_subdirectory(tests/util) add_subdirectory(tests/util/numerics) @@ -338,6 +339,7 @@ add_subdirectory(tests/kernel) add_subdirectory(tests/library) add_subdirectory(tests/library/blast) add_subdirectory(tests/frontends/lean) +add_subdirectory(tests/shell) # Include style check include(StyleCheck) diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 4e2f3c884e..62eb1b05d4 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -12,6 +12,9 @@ else() install(TARGETS lean DESTINATION bin) endif() +add_library(shell emscripten.cpp) +target_link_libraries(shell ${LEAN_LIBS}) + # add_test(example1_stdin1 ${LEAN_SOURCE_DIR}/cmake/redirect.sh ${CMAKE_CURRENT_BINARY_DIR}/lean "${LEAN_SOURCE_DIR}/../tests/lean/single.lean") # add_test(example1_stdin2 ${LEAN_SOURCE_DIR}/cmake/redirect.sh ${CMAKE_CURRENT_BINARY_DIR}/lean "-l" "${LEAN_SOURCE_DIR}/../tests/lean/single.lean") # add_test(example1_stdin3 ${LEAN_SOURCE_DIR}/cmake/redirect.sh ${CMAKE_CURRENT_BINARY_DIR}/lean "--lean" "${LEAN_SOURCE_DIR}/../tests/lean/single.lean") diff --git a/src/shell/emscripten.cpp b/src/shell/emscripten.cpp index f5e020f017..9765fc2ca5 100644 --- a/src/shell/emscripten.cpp +++ b/src/shell/emscripten.cpp @@ -66,14 +66,19 @@ public: }; } -lean::initializer* g_init; -lean::emscripten_shell* g_shell; +static lean::initializer * g_init = nullptr; +static lean::emscripten_shell * g_shell = nullptr; -void emscripten_init() { +void initialize_emscripten() { g_init = new lean::initializer(); g_shell = new lean::emscripten_shell(); } +void finalize_emscripten() { + delete g_shell; + delete g_init; +} + int emscripten_import_module(std::string mname) { return g_shell->import_module(mname); } diff --git a/src/shell/emscripten.h b/src/shell/emscripten.h index ce0a18ae45..7f5fea9830 100644 --- a/src/shell/emscripten.h +++ b/src/shell/emscripten.h @@ -6,8 +6,7 @@ Author: Leonardo de Moura */ #pragma once #include -namespace lean { -void emscripten_init(); +void initialize_emscripten(); +void finalize_emscripten(); int emscripten_import_module(std::string mname); int emscripten_process_file(std::string input_filename); -} diff --git a/src/shell/lean.cpp b/src/shell/lean.cpp index c8f0476051..d21aa6e9cf 100644 --- a/src/shell/lean.cpp +++ b/src/shell/lean.cpp @@ -234,7 +234,7 @@ options set_config_option(options const & opts, char const * in) { #if defined(LEAN_EMSCRIPTEN) #include EMSCRIPTEN_BINDINGS(LEAN_JS) { - emscripten::function("lean_init", &emscripten_init); + emscripten::function("lean_init", &initialize_emscripten); emscripten::function("lean_import_module", &emscripten_import_module); emscripten::function("lean_process_file", &emscripten_process_file); } diff --git a/src/tests/shell/CMakeLists.txt b/src/tests/shell/CMakeLists.txt new file mode 100644 index 0000000000..1312b9b416 --- /dev/null +++ b/src/tests/shell/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(shell_test shell.cpp) +target_link_libraries(shell_test "init" "lean_frontend" "library" "kernel" "util" "shell" ${EXTRA_LIBS}) + +add_test(NAME "emscripten_test" + WORKING_DIRECTORY "${LEAN_SOURCE_DIR}/tests/shell" + COMMAND bash "${LEAN_SOURCE_DIR}/tests/shell/test.sh" "${CMAKE_CURRENT_BINARY_DIR}/shell_test") diff --git a/src/tests/shell/file1.lean b/src/tests/shell/file1.lean new file mode 100644 index 0000000000..b66f5b9399 --- /dev/null +++ b/src/tests/shell/file1.lean @@ -0,0 +1,6 @@ +check nat +check nat.add_zero +check nat.zero_add +check finset +inductive foo : Type := +mk : foo → foo diff --git a/src/tests/shell/file2.lean b/src/tests/shell/file2.lean new file mode 100644 index 0000000000..e05aeb57f7 --- /dev/null +++ b/src/tests/shell/file2.lean @@ -0,0 +1,10 @@ +check nat +check nat.add_zero +check nat.zero_add +check finset + +open nat +example (a b : nat) : a = 0 → b = 0 → a = b := +begin + intros, substvars +end diff --git a/src/tests/shell/shell.cpp b/src/tests/shell/shell.cpp new file mode 100644 index 0000000000..30db9992d9 --- /dev/null +++ b/src/tests/shell/shell.cpp @@ -0,0 +1,25 @@ +/* +Copyright (c) 2015 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. + +Author: Leonardo de Moura +*/ +#include +#include "util/test.h" +#include "shell/emscripten.h" +using namespace lean; + +int main() { + save_stack_info(); + initialize_emscripten(); + emscripten_import_module("standard"); + int r = emscripten_process_file("file1.lean"); + if (r != 0) + return r; + r = emscripten_process_file("file2.lean"); + if (r != 0) + return r; + r = has_violations() ? 1 : 0; + finalize_emscripten(); + return r; +} diff --git a/src/tests/shell/test.sh b/src/tests/shell/test.sh new file mode 100644 index 0000000000..a61abdd5ae --- /dev/null +++ b/src/tests/shell/test.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e +if [ $# -ne 1 ]; then + echo "Usage: test.sh [shell_test-path]" + exit 1 +fi +SHELL_TEST=$1 + +export LEAN_PATH=../../../library:. +if ! $SHELL_TEST; then + echo "FAILED" + exit 1 +fi