Skip to content

Commit

Permalink
support multiple test suites in a single file
Browse files Browse the repository at this point in the history
linh2931 committed Jun 13, 2024
1 parent 229dd4f commit 10e9ce7
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -41,15 +41,18 @@ foreach(TEST_SUITE ${UNIT_TESTS}) # create an independent target for each test s
COMMAND
bash -c
"grep -E 'BOOST_AUTO_TEST_SUITE\\s*[(]' ${TEST_SUITE} | grep -vE '//.*BOOST_AUTO_TEST_SUITE\\s*[(]' | cut -d ')' -f 1 | cut -d '(' -f 2"
OUTPUT_VARIABLE SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # get the test suite name from the *.cpp file
if(NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
execute_process(
COMMAND bash -c "echo ${SUITE_NAME} | sed -e 's/s$//' | sed -e 's/_test$//'"
OUTPUT_VARIABLE TRIMMED_SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # trim "_test" or "_tests" from the end of ${SUITE_NAME}
# to run unit_test with all log from blockchain displayed, put "--verbose" after "--", i.e. "unit_test -- --verbose"
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed
--color_output)
endif()
OUTPUT_VARIABLE SUITE_NAMES
OUTPUT_STRIP_TRAILING_WHITESPACE) # get all the test suite names from each *.cpp file
string(REPLACE "\n" ";" SUITE_NAMES "${SUITE_NAMES}")
foreach(SUITE_NAME IN LISTS SUITE_NAMES)
if(NOT "" STREQUAL "${SUITE_NAME}") # ignore empty lines
execute_process(
COMMAND bash -c "echo ${SUITE_NAME} | sed -e 's/s$//' | sed -e 's/_test$//'"
OUTPUT_VARIABLE TRIMMED_SUITE_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE) # trim "_test" or "_tests" from the end of ${SUITE_NAME}
# to run unit_test with all log from blockchain displayed, put "--verbose" after "--", i.e. "unit_test -- --verbose"
add_test(NAME ${TRIMMED_SUITE_NAME}_unit_test COMMAND unit_test --run_test=${SUITE_NAME} --report_level=detailed
--color_output)
endif()
endforeach(SUITE_NAME)
endforeach(TEST_SUITE)

0 comments on commit 10e9ce7

Please sign in to comment.