Skip to content

Commit fa9c162

Browse files
committed
Enable C++ tests for the Emscripten tests
1 parent 48767d6 commit fa9c162

File tree

4 files changed

+72
-17
lines changed

4 files changed

+72
-17
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,18 @@ jobs:
247247
..
248248
emmake make -j ${{ env.ncpus }} install
249249
250-
- name: Jupyter Lite integration
250+
- name: Test xeus-cpp C++ Emscripten
251251
shell: bash -l {0}
252252
run: |
253253
micromamba create -n xeus-lite-host jupyterlite-core
254254
micromamba activate xeus-lite-host
255+
cd build/test
256+
node test_xeus_cpp.js
257+
timeout-minutes: 4
258+
259+
- name: Jupyter Lite integration
260+
shell: bash -l {0}
261+
run: |
255262
python -m pip install jupyterlite-xeus
256263
jupyter lite build --XeusAddon.prefix=${{ env.PREFIX }}
257264

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if(EMSCRIPTEN)
8282
set(XEUS_CPP_BUILD_EXECUTABLE OFF)
8383
set(XEUS_CPP_USE_SHARED_XEUS OFF)
8484
set(XEUS_CPP_USE_SHARED_XEUS_CPP OFF)
85-
set(XEUS_CPP_BUILD_TESTS OFF)
85+
set(XEUS_CPP_BUILD_TESTS ON)
8686
# ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
8787
set(EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \"EXPORTED_RUNTIME_METHODS=[ENV']\"")
8888
endif()

test/CMakeLists.txt

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ include(CheckCXXCompilerFlag)
2525
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
2626

2727
if(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Intel)
28-
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
28+
29+
if(NOT EMSCRIPTEN)
30+
add_compile_options(-Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion)
31+
endif()
2932

3033
CHECK_CXX_COMPILER_FLAG(-march=native HAS_MARCH_NATIVE)
3134
if (HAS_MARCH_NATIVE)
@@ -39,7 +42,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
3942
endif()
4043

4144
find_package(doctest)
42-
find_package(Threads)
4345

4446
set(XEUS_CPP_TESTS
4547
main.cpp
@@ -48,22 +50,54 @@ set(XEUS_CPP_TESTS
4850

4951
add_executable(test_xeus_cpp ${XEUS_CPP_TESTS})
5052

51-
if (APPLE)
52-
set_target_properties(test_xeus_cpp PROPERTIES
53-
MACOSX_RPATH ON
53+
if(EMSCRIPTEN)
54+
target_link_libraries(test_xeus_cpp PRIVATE xeus-cpp-static doctest::doctest)
55+
56+
target_compile_options(test_xeus_cpp
57+
PUBLIC "SHELL: -fexceptions"
58+
)
59+
60+
target_link_options(test_xeus_cpp
61+
PUBLIC "SHELL: -fexceptions"
62+
PUBLIC "SHELL: -s MAIN_MODULE=1"
63+
PUBLIC "SHELL: -s ASSERTIONS=0"
64+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
65+
PUBLIC "SHELL: -s EXIT_RUNTIME=1"
66+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
67+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
68+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
69+
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
70+
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
71+
)
72+
73+
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
74+
75+
add_custom_command(TARGET test_xeus_cpp POST_BUILD
76+
COMMAND ${CMAKE_COMMAND} -E copy
77+
${CMAKE_INSTALL_PREFIX}/lib/libclangCppInterOp.so
78+
${CMAKE_CURRENT_BINARY_DIR}/libclangCppInterOp.so
79+
COMMENT "Copying libclangCppInterOp.so to the test directory"
5480
)
5581
else()
82+
find_package(Threads)
83+
84+
if (APPLE)
85+
set_target_properties(test_xeus_cpp PROPERTIES
86+
MACOSX_RPATH ON
87+
)
88+
else()
89+
set_target_properties(test_xeus_cpp PROPERTIES
90+
BUILD_WITH_INSTALL_RPATH 1
91+
SKIP_BUILD_RPATH FALSE
92+
)
93+
endif()
94+
5695
set_target_properties(test_xeus_cpp PROPERTIES
57-
BUILD_WITH_INSTALL_RPATH 1
58-
SKIP_BUILD_RPATH FALSE
96+
INSTALL_RPATH_USE_LINK_PATH TRUE
5997
)
60-
endif()
61-
62-
set_target_properties(test_xeus_cpp PROPERTIES
63-
INSTALL_RPATH_USE_LINK_PATH TRUE
64-
)
6598

66-
target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
67-
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
99+
target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIBS_INIT})
100+
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})
68101

69-
add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
102+
add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)
103+
endif()

test/test_interpreter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ TEST_SUITE("execute_request")
169169

170170
TEST_SUITE("inspect_request")
171171
{
172+
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
173+
TEST_CASE("good_status"
174+
* doctest::should_fail(true)
175+
* doctest::description("TODO: Currently fails for the Emscripten build"))
176+
#else
172177
TEST_CASE("good_status")
178+
#endif
173179
{
174180
std::vector<const char*> Args = {/*"-v", "resource-dir", "....."*/};
175181
xcpp::interpreter interpreter((int)Args.size(), Args.data());
@@ -613,7 +619,13 @@ TEST_SUITE("xsystem_clone")
613619

614620
TEST_SUITE("xsystem_apply")
615621
{
622+
#if defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
623+
TEST_CASE("apply_xsystem"
624+
* doctest::should_fail(true)
625+
* doctest::description("TODO: Currently fails for the Emscripten build"))
626+
#else
616627
TEST_CASE("apply_xsystem")
628+
#endif
617629
{
618630
xcpp::xsystem system;
619631
std::string code = "!echo Hello, World!";
@@ -842,6 +854,7 @@ TEST_SUITE("xinspect"){
842854
}
843855
}
844856

857+
#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
845858
TEST_SUITE("xassist"){
846859

847860
TEST_CASE("model_not_found"){
@@ -980,6 +993,7 @@ TEST_SUITE("xassist"){
980993
}
981994

982995
}
996+
#endif
983997

984998

985999
TEST_SUITE("file") {

0 commit comments

Comments
 (0)