Вот воспроизведение моего набора тестов, который выдает ошибку
Код: Выделить всё
#include
TEST_CASE("Foo","Bar") {
REQUIRE(1 == 2); // I expect this to fail
}
Код: Выделить всё
cmake_minimum_required(VERSION 3.28)
project(HelloEmscripten)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
add_subdirectory(test)
Код: Выделить всё
add_executable(unit_tests test.cpp)
target_link_libraries(unit_tests PRIVATE Catch2::Catch2WithMain)
include(Catch)
catch_discover_tests(unit_tests)
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
target_link_options(unit_tests PRIVATE -fexceptions)
target_compile_options(unit_tests PRIVATE -fexceptions)
endif()
После этого я вижу следующий результат
Код: Выделить всё
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unit_tests is a Catch2 v3.4.0 host application.
Run with -? for options
-------------------------------------------------------------------------------
Foo
-------------------------------------------------------------------------------
~/workshop/cpp/tutorials/emscripten/source/test/test.cpp:3
...............................................................................
~/workshop/cpp/tutorials/emscripten/source/test/test.cpp:4: FAILED:
REQUIRE( 1 == 2 )
~/workshop/cpp/tutorials/emscripten/build/test/unit_tests.js:1242
exceptionLast = new CppException(ptr);
^
Catch::TestFailureException
at ___cxa_throw (~/workshop/cpp/tutorials/emscripten/build/test/unit_tests.js:1242:23)
at wasm://wasm/005ded6e:wasm-function[6608]:0xcf671
at wasm://wasm/005ded6e:wasm-function[478]:0xdc52
at invoke_vi (~/workshop/cpp/tutorials/emscripten/build/test/unit_tests.js:4646:29)
at wasm://wasm/005ded6e:wasm-function[56]:0x4c1f
at wasm://wasm/005ded6e:wasm-function[6637]:0xd0386
at wasm://wasm/005ded6e:wasm-function[5043]:0x9c8c1
at wasm://wasm/005ded6e:wasm-function[4946]:0x988ef
at wasm://wasm/005ded6e:wasm-function[4942]:0x98601
at wasm://wasm/005ded6e:wasm-function[4938]:0x97c78 {
excPtr: 136168
}
Личные наблюдения:
< li>Естественно, этой ошибки не произойдет, если я создаю код без emscripten, а затем запускаю ./test/unit_test
[*]Тесты выполняются до завершения, пока ни один из них не удалось.
[*]Сейчас я настраиваю EM обработка исключений через target_xxx_options и -fExceptions, но проблема сохраняется, если я использую fwasm-Exceptions или set(CMAKE_CXX_FLAGS "-s DISABLE_EXCEPTION_CATCHING=0")
Подробнее здесь: https://stackoverflow.com/questions/792 ... emscripten