不在调试模式下正常启动测试

时间:2019-06-15 16:48:00

标签: c++ makefile gdb

对于我的C ++项目,请具有以下Makefile

GDB=gdb
DEBUG ?= 1
ifeq ($(DEBUG), 1)
    CCFLAGS =-DDEBUG
    RUNPATH =${GDB}
else
    CCFLAGS=-DNDEBUG
    RUNPATH="/bin/sh -c"
endif

CPP=g++ ${CCFLAGS}
TESTGEN=cxxtestgen
CFLAGS_DBG=""
TEST_BUILD_PATH="./build/tests"
BUILD_PATH="./build"
TESTS_SRC_PATH="./tests"
SRC_PATH=""

# NORMAL TARGETS
# To Be filled

# RUN TESTS

test_command_parser_gen:
    ${TESTGEN} --error-printer -o ${TESTS_SRC_PATH}/CommandParser/runner.cpp  ./tests/CommandParser/testCommandParser.h

test_command_parser_build: test_command_parser_gen
    ${CPP} -o ${TEST_BUILD_PATH}/commandParser ${TESTS_SRC_PATH}/CommandParser/runner.cpp ./src/tools/command_parser.cpp

test_command_parser_run: test_command_parser_build
    ${RUNPATH} ./build/tests/commandParser

clean:
    find ./build ! -name '.gitkeep' -type f -exec rm -f {} + && find ./tests ! -name *.h -type f -exec rm -f {} +

当我通过以下命令启动测试时:

make test_command_parser_run

正如预期的那样,gdb会启动,我可以用它来调试测试。但是有时候我只需要按原样运行测试(例如,在CI中时),因此我可以使用以下命令来进行测试:

make test_command_parser_run DEBUG=0

但是在那种情况下,我会遇到以下错误:

cxxtestgen --error-printer -o "./tests"/CommandParser/runner.cpp  ./tests/CommandParser/testCommandParser.h
g++ -DNDEBUG -o "./build/tests"/commandParser "./tests"/CommandParser/runner.cpp ./src/tools/command_parser.cpp
"/bin/sh -c" ./build/tests/commandParser
/bin/sh: 1: /bin/sh -c: not found
Makefile:31: recipe for target 'test_command_parser_run' failed
make: *** [test_command_parser_run] Error 127

因此,我想知道如何在“调试”模式下时告诉make不使用gdb而执行测试。

其背后的整个想法是以某种方式自动调试我的应用程序,而无需记住命令和编译顺序。

1 个答案:

答案 0 :(得分:1)

删除/bin/sh -c周围的引号,就像这样:

else
  CCFLAGS=-DNDEBUG
  RUNPATH=/bin/sh -c
相关问题