Skip to content

Commit

Permalink
Add clear error msg when funcs not called correctly (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
fryeguy52 authored and bartlettroscoe committed Aug 11, 2017
1 parent 4d988ab commit 8d7fb25
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 8 deletions.
129 changes: 129 additions & 0 deletions test/core/ExamplesUnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,7 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_PASS
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Explicitly enabled packages on input [(]by user[)]: PkgWithUserErrors 1"
Expand Down Expand Up @@ -3070,9 +3071,137 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_PACKAGE_POST_
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_SKIP_PACKAGE_POST_PROCESS=TRUE
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Processing enabled package: PkgWithUserErrors [(]Libs, Tests, Examples[)]"
"ERROR: Forgot to call TRIBITS_PACKAGE_POSTPROCESS[(][)] .*/TribitsExampleProject/PkgWithUserErrors/CMakeLists.txt"
ALWAYS_FAIL_ON_ZERO_RETURN
)

TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_SKIP_PACKAGE_INIT
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSAGE "Copy TribitsExampleProject so that we can copy in PkgWithUserErrors."
CMND cp
ARGS -r ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .

TEST_1
MESSAGE "Copy PkgWithUserErrors to base dir."
CMND cp
ARGS -r ${CMAKE_CURRENT_SOURCE_DIR}/PkgWithUserErrors
TribitsExampleProject/.

TEST_2
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_SKIP_TRIBITS_PACKAGE_INIT=TRUE
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Must call TRIBITS_PACKAGE[(][)] before TRIBITS_ADD_LIBRARY[(][)]"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

TEST_3
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_SKIP_TRIBITS_PACKAGE_INIT=TRUE
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=FALSE
-DPkgWithUserErrors_ADD_EXECUTABLE_BEFORE_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Must call TRIBITS_PACKAGE[(][)] before TRIBITS_ADD_EXECUTABLE[(][)]"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

TEST_4
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_SKIP_TRIBITS_PACKAGE_INIT=TRUE
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=FALSE
-DPkgWithUserErrors_ADD_EXECUTABLE_BEFORE_POST_PROCESS=""
-DPkgWithUserErrors_SKIP_PACKAGE_TESTS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Must call TRIBITS_PACKAGE[(][)] before TRIBITS_PACKAGE_POSTPROCESS[(][)]"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

)

TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithUserErrors_TARGETS_AFTER_POSTPROCESS
OVERALL_WORKING_DIRECTORY TEST_NAME
OVERALL_NUM_MPI_PROCS 1

TEST_0
MESSAGE "Copy TribitsExampleProject so that we can copy in PkgWithUserErrors."
CMND cp
ARGS -r ${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject .

TEST_1
MESSAGE "Copy PkgWithUserErrors to base dir."
CMND cp
ARGS -r ${CMAKE_CURRENT_SOURCE_DIR}/PkgWithUserErrors
TribitsExampleProject/.

TEST_2
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_ADD_LIBRARY_BEFORE_POST_PROCESS=FALSE
-DPkgWithUserErrors_ADD_LIBRARY_AFTER_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Must call TRIBITS_ADD_LIBRARY[(][)] before TRIBITS_PACKAGE_POSTPROCESS[(][)] in"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

TEST_3
MESSAGE "Configure PkgWithUserErrors"
CMND ${CMAKE_COMMAND}
ARGS
${TribitsExampleProject_COMMON_CONFIG_ARGS}
-DTribitsExProj_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj_ENABLE_Fortran=OFF
-DTribitsExProj_EXTRA_REPOSITORIES=PkgWithUserErrors
-DTribitsExProj_ENABLE_PkgWithUserErrors=ON
-DTribitsExProj_ENABLE_TESTS=ON
-DPkgWithUserErrors_ADD_LIBRARY_AFTER_POST_PROCESS=FALSE
-DPkgWithUserErrors_ADD_EXECUTABLE_AFTER_POST_PROCESS=TRUE
TribitsExampleProject
PASS_REGULAR_EXPRESSION_ALL
"Must call TRIBITS_ADD_EXECUTABLE[(][)] before TRIBITS_PACKAGE_POSTPROCESS[(][)] in"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

)
50 changes: 43 additions & 7 deletions test/core/ExamplesUnitTests/PkgWithUserErrors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
TRIBITS_PACKAGE(PkgWithUserErrors)
# TRIBITS_PACKAGE() will be called by default
IF(NOT ${PACKAGE_NAME}_SKIP_TRIBITS_PACKAGE_INIT)
TRIBITS_PACKAGE(PkgWithUserErrors)
ENDIF()

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

TRIBITS_ADD_LIBRARY(
pkgwithusererrors
HEADERS PkgWithUserErrorsLib.hpp
SOURCES PkgWithUserErrorsLib.cpp
)
# Not added by defult
IF(${PACKAGE_NAME}_ADD_LIBRARY_BEFORE_POST_PROCESS)
MESSAGE("building library")
TRIBITS_ADD_LIBRARY(
pkgwithusererrors
HEADERS PkgWithUserErrorsLib.hpp
SOURCES PkgWithUserErrorsLib.cpp
)
ENDIF()

TRIBITS_ADD_TEST_DIRECTORIES(test)
# Not added by defult
IF(${PACKAGE_NAME}_ADD_EXECUTABLE_BEFORE_POST_PROCESS)
MESSAGE("building exectuable")
TRIBITS_ADD_EXECUTABLE(
usererrorexec
SOURCES PkgWithUserErrorsEX.cpp
)
ENDIF()

IF(NOT ${PACKAGE_NAME}_SKIP_PACKAGE_TESTS)
TRIBITS_ADD_TEST_DIRECTORIES(test)
ENDIF()

# TRIBITS_PACKAGE_POSTPROCESS() will be called by default
IF (NOT ${PACKAGE_NAME}_SKIP_PACKAGE_POST_PROCESS)
TRIBITS_PACKAGE_POSTPROCESS()
ENDIF()

# Not added by defult
IF (${PACKAGE_NAME}_ADD_LIBRARY_AFTER_POST_PROCESS)
TRIBITS_ADD_LIBRARY(
pkgwithusererrors2
HEADERS PkgWithUserErrorsLib.hpp
SOURCES PkgWithUserErrorsLib.cpp
)
ENDIF()

# Not added by defult
IF(${PACKAGE_NAME}_ADD_EXECUTABLE_AFTER_POST_PROCESS)
TRIBITS_ADD_EXECUTABLE(
usererrorexec
SOURCES PkgWithUserErrorsEX.cpp
)
ENDIF()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "Package With User Errors\n";
return 0;
}
12 changes: 12 additions & 0 deletions tribits/core/package_arch/TribitsAddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
MESSAGE("")
MESSAGE("TRIBITS_ADD_EXECUTABLE: ${EXE_NAME} ${ARGN}")
ENDIF()

#
# Confirm that TRIBITS_PACKAGE() was called prior to adding executable
#

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() before TRIBITS_ADD_EXECUTABLE() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_EXECUTABLE() before TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

#
# A) Parse the input arguments
Expand Down
10 changes: 9 additions & 1 deletion tribits/core/package_arch/TribitsLibraryMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,16 @@ ENDFUNCTION()
#
FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)

SET(LIBRARY_NAME_PREFIX "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}")
IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() before TRIBITS_ADD_LIBRARY() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_LIBRARY() before TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()


SET(LIBRARY_NAME_PREFIX "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}")
SET(LIBRARY_NAME ${LIBRARY_NAME_PREFIX}${LIBRARY_NAME_IN})

IF (${PROJECT_NAME}_VERBOSE_CONFIGURE)
Expand Down
9 changes: 9 additions & 0 deletions tribits/core/package_arch/TribitsPackageMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ MACRO(TRIBITS_PACKAGE_DECL PACKAGE_NAME_IN)
MESSAGE("\nTRIBITS_PACKAGE_DECL: ${PACKAGE_NAME_IN}")
ENDIF()

# Set flag to check that macros are called in the correct order
SET(${PACKAGE_NAME}_TRIBITS_PACKAGE_CALLED TRUE)

#
# A) Parse the input arguments
#
Expand Down Expand Up @@ -603,6 +606,10 @@ ENDMACRO()
#
MACRO(TRIBITS_PACKAGE_POSTPROCESS)

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() before TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

# Only parent packages have the targets (${PACKAGE_NAME}_libs and
# (${PACKAGE_NAME}_all
IF (${PROJECT_NAME}_VERBOSE_CONFIGURE)
Expand All @@ -622,6 +629,8 @@ MACRO(TRIBITS_PACKAGE_POSTPROCESS)
SET(${PACKAGE_NAME}_TRIBITS_PACAKGE_POSTPROCESS TRUE PARENT_SCOPE)
ENDIF()

SET(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED TRUE)

ENDMACRO()


Expand Down
3 changes: 3 additions & 0 deletions tribits/core/package_arch/TribitsSubPackageMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ MACRO(TRIBITS_SUBPACKAGE SUBPACKAGE_NAME_IN)
TRIBITS_SET_COMMON_VARS(${SUBPACKAGE_FULLNAME})
TRIBITS_DEFINE_LINKAGE_VARS(${SUBPACKAGE_FULLNAME})

# Set flag to check that macros are called in the correct order
SET(${PACKAGE_NAME}_TRIBITS_PACKAGE_CALLED TRUE)

ENDMACRO()


Expand Down

0 comments on commit 8d7fb25

Please sign in to comment.