如何将CTest与Node js命令一起使用,以测试使用emscripten从C ++编译的JS文件,并使用Catch2?

时间:2018-09-09 08:05:17

标签: 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目录并运行node 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);
}

,这里是CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
project(trytest)

enable_testing()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(try-test "test/main.cpp")

target_include_directories(try-test
PRIVATE
  "${PROJECT_SOURCE_DIR}/third_party/Catch2/single_include"
)

target_compile_options(try-test PRIVATE "-Wall" "-Wpedantic" "-stdlib=libc++")

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

感谢您能提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

我知道了。我使用add_test错误。应该是

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

因此ctest将运行带有参数node的命令${CMAKE_CURRENT_BINARY_DIR}/try-test.js