Skip to content

Commit

Permalink
Get tribits_add_advanced_test() to work from non-CMake projects (TriB…
Browse files Browse the repository at this point in the history
…ITSPub#368, TriBITSPub#582)

Changes to TriBITS:

* Changed explicit includes from TribitsAddAdvancedTest.cmake (this module and
  its included modules will be moved to tribits/core/test_support/ in next
  commit).

* Remove option to prefix test base name in tribits_add_advanced_test() by
  '${PROJECT_NAME}_' (since tribits_set_tribits_package_name() is now being
  called to set PACKAGE_NAME give PROJECT_NAME).

* Changed tribits_add_advanced_test() to set explicit include of
  DriveAdvancedTest.cmake without setting CMAKE_MODULE_PATH.

* Use more explicit includes in tribits/core/utils/*.cmake mdoules needed to
  get above to work.

Changes to TribitsExampleProject2/Packages1:

* Updated package1-prg to accept command-line arguments that are echoed to
  STDOUT.

* Added new test Package1_Prg-advanced taking in command-line arguments using
  tribits_add_advanced_test() and in raw CMake build.

Changes to tests:

* Removed regex for CMAKE_MODULE_PATH from driver file for
  tribits_add_advanced_test() (which reduces the total number of checks by 1).
  • Loading branch information
bartlettroscoe committed Sep 6, 2023
1 parent 1f69bbb commit 7332f9b
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 36 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 = 721"
"Final UnitTests Result: num_run = 720"
"Final UnitTests Result: PASSED"
)

Expand Down
25 changes: 16 additions & 9 deletions test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMetho
CMND ${CMAKE_CTEST_COMMAND} ARGS -VV
PASS_REGULAR_EXPRESSION_ALL
"Test.*Package1_Prg.*Passed"
"Test.*Package1_Prg-advanced.*Passed"
"Test.*Package2_Prg.*Passed"
"Test.*Package3_Prg.*Passed"
"100% tests passed, 0 tests failed out of 3"
"100% tests passed, 0 tests failed out of 4"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_5
Expand Down Expand Up @@ -393,9 +394,10 @@ function(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls shared
CMND ${CMAKE_CTEST_COMMAND} ARGS -VV
PASS_REGULAR_EXPRESSION_ALL
"Test.*Package1_Prg.*Passed"
"Test.*Package1_Prg-advanced.*Passed"
"Test.*Package2_Prg.*Passed"
"Test.*Package3_Prg.*Passed"
"100% tests passed, 0 tests failed out of 3"
"100% tests passed, 0 tests failed out of 4"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
Expand Down Expand Up @@ -496,9 +498,10 @@ function(TribitsExampleProject2_explicit_tpl_vars sharedOrStatic)
CMND ${CMAKE_CTEST_COMMAND} ARGS -VV
PASS_REGULAR_EXPRESSION_ALL
"Test.*Package1_Prg.*Passed"
"Test.*Package1_Prg-advanced.*Passed"
"Test.*Package2_Prg.*Passed"
"Test.*Package3_Prg.*Passed"
"100% tests passed, 0 tests failed out of 3"
"100% tests passed, 0 tests failed out of 4"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_3
Expand Down Expand Up @@ -569,7 +572,8 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR
string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" )
list(APPEND package1ConfiRegex
"Using TriBITS Test Functions in a raw CMake Package1 build"
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" )
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]"
"Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" )
elseif (package1UseTribitsTestFunctions STREQUAL "")
list(APPEND package1ConfiRegex
"Using Raw CMake add_test[(][)] in a raw CMake Package1 build" )
Expand Down Expand Up @@ -654,9 +658,10 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR
CMND ${CMAKE_CTEST_COMMAND} ARGS -VV
PASS_REGULAR_EXPRESSION_ALL
"Test.*Package1_Prg.*Passed"
"Test.*Package1_Prg-advanced.*Passed"
"Test.*Package2_Prg.*Passed"
"Test.*Package3_Prg.*Passed"
"100% tests passed, 0 tests failed out of 3"
"100% tests passed, 0 tests failed out of 4"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
Expand Down Expand Up @@ -1221,7 +1226,8 @@ function(TribitsExampleProject2_External_RawPackage1_PBP
string(APPEND testNameSuffix "_${package1UseTribitsTestFunctions}" )
set(package1ConfiRegex
"Using TriBITS Test Functions in a raw CMake Package1 build"
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]" )
"Package1_Prg: Added test [(]BASIC, PROCESSORS=1[)]"
"Package1_Prg-advanced: Added test [(]BASIC, PROCESSORS=1[)]" )
elseif (package1UseTribitsTestFunctions STREQUAL "")
set(package1UseTribitsTestFunctionsArgs "")
set(package1ConfiRegex
Expand Down Expand Up @@ -1278,8 +1284,9 @@ function(TribitsExampleProject2_External_RawPackage1_PBP
SKIP_CLEAN_WORKING_DIRECTORY
CMND ${CMAKE_CTEST_COMMAND}
PASS_REGULAR_EXPRESSION_ALL
"1/1 Test [#]1: Package1_Prg [.]* *Passed"
"100% tests passed, 0 tests failed out of 1"
"Test.*Package1_Prg [.]* *Passed"
"Test.*Package1_Prg-advanced [.]* *Passed"
"100% tests passed, 0 tests failed out of 2"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
Expand Down Expand Up @@ -1422,7 +1429,7 @@ function(TribitsExampleProject2_External_RawPackage1_PBP
SKIP_CLEAN_WORKING_DIRECTORY
CMND ${CMAKE_CTEST_COMMAND}
PASS_REGULAR_EXPRESSION_ALL
"Package3_Prg [.]+ *Passed"
"Test.*Package3_Prg [.]+ *Passed"
"100% tests passed, 0 tests failed out of 1"
ALWAYS_FAIL_ON_NONZERO_RETURN

Expand Down
5 changes: 2 additions & 3 deletions test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2567,11 +2567,10 @@ function(unittest_tribits_add_advanced_test_basic)
"NUM_CMNDS 1"
"set[(]OVERALL_WORKING_DIRECTORY .PackageA_TAAT_basic_cmnd_1_args_2.[)]"
"set[(]SKIP_CLEAN_OVERALL_WORKING_DIRECTORY .TRUE.[)]"
"CMAKE_MODULE_PATH"
"set[(]SHOW_START_END_DATE_TIME OFF[)]"
"set[(] TEST_0_WORKING_DIRECTORY .someSubdir. [)]"
"set[(] TEST_0_SKIP_CLEAN_WORKING_DIRECTORY TRUE [)]"
"DriveAdvancedTest"
"tribits/core/utils/DriveAdvancedTest"
"drive_advanced_test"
)

Expand Down Expand Up @@ -4845,4 +4844,4 @@ message("*** Determine final result of all unit tests")
message("***\n")

# Pass in the number of expected tests that must pass!
unittest_final_result(721)
unittest_final_result(720)
25 changes: 12 additions & 13 deletions tribits/core/package_arch/TribitsAddAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsCMakePolicies.cmake" NO_POLICY_SCOPE)
include("${CMAKE_CURRENT_LIST_DIR}/../common/TribitsConstants.cmake")

include(TribitsAddAdvancedTestHelpers)
set(tribitsAddAdvancedTestModuleDir "${CMAKE_CURRENT_LIST_DIR}")

include(TribitsPrintList)
include(AppendStringVar)
include(PrintVar)
include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddAdvancedTestHelpers.cmake")

include("${CMAKE_CURRENT_LIST_DIR}/../utils/TribitsPrintList.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/../utils/AppendStringVar.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/../utils/PrintVar.cmake")


# @FUNCTION: tribits_add_advanced_test()
Expand Down Expand Up @@ -886,16 +888,13 @@ function(tribits_add_advanced_test TEST_NAME_IN)
message("\nPACKAGE_ADD_ADVANCED_TEST: ${TEST_NAME_IN}\n")
endif()

tribits_set_tribits_package_name()

global_set(TRIBITS_SET_TEST_PROPERTIES_INPUT)
global_set(MESSAGE_WRAPPER_INPUT)

# Set the full TEST_NAME
if (PACKAGE_NAME)
set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN})
else()
set(TEST_NAME ${TEST_NAME_IN})
endif()

set(TEST_NAME ${PACKAGE_NAME}_${TEST_NAME_IN})

#
# A) Parse the overall arguments and figure out how many tests
Expand Down Expand Up @@ -1518,6 +1517,8 @@ function(tribits_add_advanced_test TEST_NAME_IN)
# F.2) Write the cmake -P script
#

set(coreUtilsDir "${tribitsAddAdvancedTestModuleDir}/../utils")
cmake_path(NORMAL_PATH coreUtilsDir)
string(APPEND TEST_SCRIPT_STR
"\n"
"set(PROJECT_NAME ${PROJECT_NAME})\n"
Expand Down Expand Up @@ -1548,9 +1549,7 @@ function(tribits_add_advanced_test TEST_NAME_IN)
"# Test invocation\n"
"#\n"
"\n"
"set(CMAKE_MODULE_PATH ${${PROJECT_NAME}_TRIBITS_DIR}/${TRIBITS_CMAKE_UTILS_DIR})\n"
"\n"
"include(DriveAdvancedTest)\n"
"include(\"${coreUtilsDir}/DriveAdvancedTest.cmake\")\n"
"\n"
"drive_advanced_test()\n"
)
Expand Down
8 changes: 5 additions & 3 deletions tribits/core/utils/AppendStringVar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
# ************************************************************************
# @HEADER

include(ConcatStrings)
include(PrintVar)
include(TribitsDeprecatedHelpers)
include_guard()

include("${CMAKE_CURRENT_LIST_DIR}/ConcatStrings.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/PrintVar.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TribitsDeprecatedHelpers.cmake")


# @FUNCTION: append_string_var()
Expand Down
12 changes: 7 additions & 5 deletions tribits/core/utils/DriveAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
# ************************************************************************
# @HEADER

include(PrintVar)
include(AppendStringVar)
include(Join)
include(TimingUtils)
include(TribitsGetCategoriesString)
include_guard()

include("${CMAKE_CURRENT_LIST_DIR}/PrintVar.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/AppendStringVar.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Join.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TimingUtils.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/TribitsGetCategoriesString.cmake")


function(print_current_date_time PREFIX_STR)
Expand Down
2 changes: 1 addition & 1 deletion tribits/core/utils/TimingUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# platforms so call with care.
#

include(Split)
include("${CMAKE_CURRENT_LIST_DIR}/Split.cmake")


# @FUNCTION: timer_get_raw_seconds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ else()
if (Package1_USE_TRIBITS_TEST_FUNCTIONS AND Package1_TRIBITS_DIR)
set(Package1_ENABLE_TESTS ON)
include("${Package1_TRIBITS_DIR}/core/test_support/TribitsAddTest.cmake")
include("${Package1_TRIBITS_DIR}/core/package_arch/TribitsAddAdvancedTest.cmake")
endif()
add_subdirectory(test)
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <iostream>
#include <string>

#include "Package1.hpp"

int main()
int main(int argc, char* argv[])
{
std::cout << "Package1 Deps: " << Package1::deps() << "\n";
for (int arg_i = 0; arg_i < argc; ++arg_i) {
std::cout << argv[arg_i+1] << "\n";
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
add_test(NAME Package1_Prg COMMAND package1-prg)
set_tests_properties(Package1_Prg
PROPERTIES PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1")

add_test(NAME Package1_Prg-advanced COMMAND package1-prg something_extra)
set_tests_properties(Package1_Prg-advanced
PROPERTIES PASS_REGULAR_EXPRESSION "something_extra")

# NOTE: With raw CMake/CTest, it is not possible to require the matches of
# multiple regexes. Also, it is not possible to require a non-zero return
# code in addition to requiring a regex match the output. These more advanced
# features of tribits_add_advanced_test() would need to be provided by writing
# a wrapper script (e.g. using a Python script, a cmake -P script, etc.)
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
tribits_add_test(package1-prg NOEXEPREFIX NOEXESUFFIX
NAME Prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src" NUM_MPI_PROCS 1
PASS_REGULAR_EXPRESSION "Package1 Deps: tpl1" )

tribits_add_advanced_test(Prg-advanced
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1
TEST_0
EXEC package1-prg DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../src"
NOEXEPREFIX NOEXESUFFIX
ARGS "something_extra"
PASS_REGULAR_EXPRESSION_ALL
"Package1 Deps: tpl1"
"something_extra"
ALWAYS_FAIL_ON_NONZERO_RETURN
)

0 comments on commit 7332f9b

Please sign in to comment.