test(tests/shell): add unit test for emscripten_shell
This commit is contained in:
parent
a6fe4cbce6
commit
a24b06254b
10 changed files with 76 additions and 7 deletions
|
@ -330,6 +330,7 @@ endif()
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_TESTCOV "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
set(CMAKE_EXE_LINKER_FLAGS_TESTCOV "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||||
set(ALL_LIBS ${LEAN_LIBS} ${EXTRA_LIBS})
|
set(ALL_LIBS ${LEAN_LIBS} ${EXTRA_LIBS})
|
||||||
add_subdirectory(shell)
|
add_subdirectory(shell)
|
||||||
|
set(LEAN_LIBS ${LEAN_LIBS} shell)
|
||||||
add_subdirectory(emacs)
|
add_subdirectory(emacs)
|
||||||
add_subdirectory(tests/util)
|
add_subdirectory(tests/util)
|
||||||
add_subdirectory(tests/util/numerics)
|
add_subdirectory(tests/util/numerics)
|
||||||
|
@ -338,6 +339,7 @@ add_subdirectory(tests/kernel)
|
||||||
add_subdirectory(tests/library)
|
add_subdirectory(tests/library)
|
||||||
add_subdirectory(tests/library/blast)
|
add_subdirectory(tests/library/blast)
|
||||||
add_subdirectory(tests/frontends/lean)
|
add_subdirectory(tests/frontends/lean)
|
||||||
|
add_subdirectory(tests/shell)
|
||||||
|
|
||||||
# Include style check
|
# Include style check
|
||||||
include(StyleCheck)
|
include(StyleCheck)
|
||||||
|
|
|
@ -12,6 +12,9 @@ else()
|
||||||
install(TARGETS lean DESTINATION bin)
|
install(TARGETS lean DESTINATION bin)
|
||||||
endif()
|
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_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_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")
|
# add_test(example1_stdin3 ${LEAN_SOURCE_DIR}/cmake/redirect.sh ${CMAKE_CURRENT_BINARY_DIR}/lean "--lean" "${LEAN_SOURCE_DIR}/../tests/lean/single.lean")
|
||||||
|
|
|
@ -66,14 +66,19 @@ public:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
lean::initializer* g_init;
|
static lean::initializer * g_init = nullptr;
|
||||||
lean::emscripten_shell* g_shell;
|
static lean::emscripten_shell * g_shell = nullptr;
|
||||||
|
|
||||||
void emscripten_init() {
|
void initialize_emscripten() {
|
||||||
g_init = new lean::initializer();
|
g_init = new lean::initializer();
|
||||||
g_shell = new lean::emscripten_shell();
|
g_shell = new lean::emscripten_shell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finalize_emscripten() {
|
||||||
|
delete g_shell;
|
||||||
|
delete g_init;
|
||||||
|
}
|
||||||
|
|
||||||
int emscripten_import_module(std::string mname) {
|
int emscripten_import_module(std::string mname) {
|
||||||
return g_shell->import_module(mname);
|
return g_shell->import_module(mname);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,7 @@ Author: Leonardo de Moura
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace lean {
|
void initialize_emscripten();
|
||||||
void emscripten_init();
|
void finalize_emscripten();
|
||||||
int emscripten_import_module(std::string mname);
|
int emscripten_import_module(std::string mname);
|
||||||
int emscripten_process_file(std::string input_filename);
|
int emscripten_process_file(std::string input_filename);
|
||||||
}
|
|
||||||
|
|
|
@ -234,7 +234,7 @@ options set_config_option(options const & opts, char const * in) {
|
||||||
#if defined(LEAN_EMSCRIPTEN)
|
#if defined(LEAN_EMSCRIPTEN)
|
||||||
#include <emscripten/bind.h>
|
#include <emscripten/bind.h>
|
||||||
EMSCRIPTEN_BINDINGS(LEAN_JS) {
|
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_import_module", &emscripten_import_module);
|
||||||
emscripten::function("lean_process_file", &emscripten_process_file);
|
emscripten::function("lean_process_file", &emscripten_process_file);
|
||||||
}
|
}
|
||||||
|
|
6
src/tests/shell/CMakeLists.txt
Normal file
6
src/tests/shell/CMakeLists.txt
Normal file
|
@ -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")
|
6
src/tests/shell/file1.lean
Normal file
6
src/tests/shell/file1.lean
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
check nat
|
||||||
|
check nat.add_zero
|
||||||
|
check nat.zero_add
|
||||||
|
check finset
|
||||||
|
inductive foo : Type :=
|
||||||
|
mk : foo → foo
|
10
src/tests/shell/file2.lean
Normal file
10
src/tests/shell/file2.lean
Normal file
|
@ -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
|
25
src/tests/shell/shell.cpp
Normal file
25
src/tests/shell/shell.cpp
Normal file
|
@ -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 <vector>
|
||||||
|
#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;
|
||||||
|
}
|
13
src/tests/shell/test.sh
Normal file
13
src/tests/shell/test.sh
Normal file
|
@ -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
|
Loading…
Reference in a new issue