Skip to content

Commit

Permalink
Fix COPY_FILES_TO_TEST_DIR when overall working dir is not test name (T…
Browse files Browse the repository at this point in the history
…riBITSPub#228)

This was a use case that I forgot to test and I accidentally hard-coded the
default dest dir to be the test name dir.
  • Loading branch information
bartlettroscoe committed Dec 20, 2017
1 parent f5599af commit 1dfc788
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TRIBITS_ADD_ADVANCED_TEST( TestingFunctionMacro_UnitTests
-D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TestingFunctionMacro_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 507"
"Final UnitTests Result: num_run = 515"
"Final UnitTests Result: PASSED"
)

Expand Down
36 changes: 35 additions & 1 deletion test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,40 @@ FUNCTION(UNITEST_TRIBITS_ADD_ADVANCED_TEST_COPY_FILES_TO_TEST_DIR)
"NUM_CMNDS 1"
)

MESSAGE("\n*** Test basic copy of files to dest dir under working dir with test name\n")
SET(TEST_NAME TAAT_COPY_FILES_TO_TEST_DIR_1_test_explicit_dirs)
TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME}
OVERALL_WORKING_DIRECTORY TEST_NAME
TEST_0 COPY_FILES_TO_TEST_DIR file1 file2
SOURCE_DIR /the/source/dir
)
UNITTEST_FILE_REGEX(
"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
REGEX_STRINGS
"TEST_0_COPY_FILES_TO_TEST_DIR \"file1,file2\""
"TEST_0_SOURCE_DIR \"/the/source/dir\""
"TEST_0_DEST_DIR \"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}\""
"NUM_CMNDS 1"
)

MESSAGE("\n*** Test basic copy of files to dest dir under special-named working dir\n")
SET(TEST_NAME TAAT_COPY_FILES_TO_TEST_DIR_1_test_explicit_dirs)
TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
TRIBITS_ADD_ADVANCED_TEST( ${TEST_NAME}
OVERALL_WORKING_DIRECTORY ${TEST_NAME}_other
TEST_0 COPY_FILES_TO_TEST_DIR file1 file2
SOURCE_DIR /the/source/dir
)
UNITTEST_FILE_REGEX(
"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_${TEST_NAME}.cmake"
REGEX_STRINGS
"TEST_0_COPY_FILES_TO_TEST_DIR \"file1,file2\""
"TEST_0_SOURCE_DIR \"/the/source/dir\""
"TEST_0_DEST_DIR \"${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}_other\""
"NUM_CMNDS 1"
)

MESSAGE("\n*** Test using an empty COPY_FILES_TO_TEST_DIR values\n")
SET(TEST_NAME TAAT_COPY_FILES_TO_TEST_DIR_missing_files)
TRIBITS_ADD_ADVANCED_TEST_UNITTEST_RESET()
Expand Down Expand Up @@ -3391,4 +3425,4 @@ MESSAGE("*** Determine final result of all unit tests")
MESSAGE("***\n")

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(507)
UNITTEST_FINAL_RESULT(515)
23 changes: 15 additions & 8 deletions tribits/core/package_arch/TribitsAddAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,19 @@ FUNCTION(TRIBITS_ADD_ADVANCED_TEST TEST_NAME_IN)
SET(${PARSE_ADDED_TEST_NAME_OUT} "" PARENT_SCOPE )
ENDIF()

# Set the relative overall working directory and abs working directory
IF (PARSE_OVERALL_WORKING_DIRECTORY)
IF ("${PARSE_OVERALL_WORKING_DIRECTORY}" STREQUAL "TEST_NAME")
SET(PARSE_OVERALL_WORKING_DIRECTORY ${TEST_NAME})
ENDIF()
# Test will run in created working subdir
SET(ABS_OVERALL_WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${PARSE_OVERALL_WORKING_DIRECTORY})
ELSE()
# Test runs in current binary directory (not a good idea!)
SET(ABS_OVERALL_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
ENDIF()

#
# B) Add or don't add tests based on a number of criteria
#
Expand Down Expand Up @@ -1164,11 +1177,11 @@ FUNCTION(TRIBITS_ADD_ADVANCED_TEST TEST_NAME_IN)
"${PARSE_DEST_DIR}")
ELSE()
SET(COPY_FILES_TO_TEST_DIR_DEST_DIR
"${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}/${PARSE_DEST_DIR}")
"${ABS_OVERALL_WORKING_DIRECTORY}/${PARSE_DEST_DIR}")
ENDIF()
ELSE()
SET(COPY_FILES_TO_TEST_DIR_DEST_DIR
"${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}")
"${ABS_OVERALL_WORKING_DIRECTORY}")
ENDIF()

ELSE()
Expand Down Expand Up @@ -1394,12 +1407,6 @@ FUNCTION(TRIBITS_ADD_ADVANCED_TEST TEST_NAME_IN)
#
# F.2) Write the cmake -P script
#

IF (PARSE_OVERALL_WORKING_DIRECTORY)
IF ("${PARSE_OVERALL_WORKING_DIRECTORY}" STREQUAL "TEST_NAME")
SET(PARSE_OVERALL_WORKING_DIRECTORY ${TEST_NAME})
ENDIF()
ENDIF()

APPEND_STRING_VAR( TEST_SCRIPT_STR
"\n"
Expand Down

0 comments on commit 1dfc788

Please sign in to comment.