Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cmake 如何将CTest与Node js命令结合使用,用于测试从C++;使用emscripten和Catch2?_Cmake_Emscripten_Ctest_Catch2 - Fatal编程技术网

Cmake 如何将CTest与Node js命令结合使用,用于测试从C++;使用emscripten和Catch2?

Cmake 如何将CTest与Node js命令结合使用,用于测试从C++;使用emscripten和Catch2?,cmake,emscripten,ctest,catch2,Cmake,Emscripten,Ctest,Catch2,我尝试使用Catch2库进行测试,并使用emscripten编译它并运行测试。我的项目的目录结构如下所示 |- CMakeLists.txt |- build |   |- ... |   |- try-test.js |   |- try-test.wasm |   |- try-test.wast |- test |   |- main.cpp |- third_party |- Catch2 |- ... 当我移动到build目录并运行节点try test.js时

我尝试使用
Catch2
库进行测试,并使用
emscripten
编译它并运行测试。我的项目的目录结构如下所示

|- CMakeLists.txt
|- build
|   |- ...
|   |- try-test.js
|   |- try-test.wasm
|   |- try-test.wast
|- test
|   |- main.cpp
|- third_party
    |- Catch2
        |- ...
当我移动到
build
目录并运行
节点try test.js
时,它成功了。但是当我运行
ctest
时,它失败了。下面是输出消息

Test project /Users/janucaria/Projects/junk/em-cpp-unit-test/build
Start 1: trytest
Could not find executable node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
Looked in the following places:
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
Unable to find executable: node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
1/1 Test #1: trytest ..........................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.01 sec

The following tests FAILED:
          1 - trytest (Not Run)
Errors while running CTest
我是不是遗漏了什么

这是我的
test/main.cpp

#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

TEST_CASE("Try test")
{
  int foo = 1;
  REQUIRE(foo == 1);
}

如果您能提供任何帮助,我将不胜感激。

我想明白了。我使用了
添加测试
错误。应该是

add_test(
  NAME trytest
  COMMAND node "${CMAKE_CURRENT_BINARY_DIR}/try-test.js")
因此,
ctest
将运行带有参数的命令
node
${CMAKE\u CURRENT\u BINARY\u DIR}/try test.js

add_test(
  NAME trytest
  COMMAND node "${CMAKE_CURRENT_BINARY_DIR}/try-test.js")