2

我正在尝试使用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")

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

4

1 回答 1

1

我想通了。我用add_test错了。它应该是

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

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

于 2018-09-09T09:34:02.450 回答