1 # /*-------------------------------------------------------------------------*\
3 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / A nd | For copyright notice see file Copyright
7 # -----------------------------------------------------------------------------
9 # This file is part of foam-extend.
11 # foam-extend is free software: you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the
13 # Free Software Foundation, either version 3 of the License, or (at your
14 # option) any later version.
16 # foam-extend is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # CMake/CTest script for running the FOAM tutorials
28 # Martin Beaudoin, Hydro-Quebec, 2010. All rights reserved
30 # \*-------------------------------------------------------------------------*/
32 # Take care of tests specific variables
33 IF(NOT DEFINED testIdSuffix)
34 SET(testIdSuffix "_full")
35 ENDIF(NOT DEFINED testIdSuffix)
37 IF(NOT DEFINED testRunTimeDirectory)
38 SET(testRunTimeDirectory "tutorialsTestSuites${testIdSuffix}")
39 ENDIF(NOT DEFINED testRunTimeDirectory)
41 # Use the current directory for running the test cases
42 SET (TEST_CASE_DIR $ENV{PWD}/${testRunTimeDirectory}
43 CACHE INTERNAL "FOAM test case directory."
46 # Create the runTime directory for the test cases
47 MESSAGE("Removing the old test directory: ${TEST_CASE_DIR}")
48 file(REMOVE_RECURSE ${TEST_CASE_DIR})
49 MESSAGE("Creation of the new test directory: ${TEST_CASE_DIR}")
50 file(COPY $ENV{FOAM_TUTORIALS}/ DESTINATION ${TEST_CASE_DIR})
52 # Add a default Allrun file for the cases that don't have one.
53 # The test harness relies on the presence of an Allrun file for
55 MESSAGE("${testRunTimeDirectory}: Checking for missing Allrun file in tutorials")
57 COMMAND $ENV{FOAM_TEST_HARNESS_DIR}/scripts/addMissingAllrunFileToTutorial.sh ${TEST_CASE_DIR} $ENV{FOAM_TEST_HARNESS_DIR}/scripts/Allrun.default
61 # Iterate over each tutorial case:
62 # We are looking for tutorial cases with an Allrun file.
63 # If this file is present, (and it should), we add this case to the list of cases to run.
66 #First, add a global cleanup of the cases
67 SET(testId "Allclean_cases${testIdSuffix}")
68 ADD_TEST(${testId} bash -c "cd ${TEST_CASE_DIR}; ./Allclean")
70 # Next, recurse through the test cases root directory,
71 # find all the Allrun files, and add them as a new CTest test case
72 FILE(GLOB_RECURSE listofCasesWithAllrun ${TEST_CASE_DIR}/Allrun)
73 LIST(SORT listofCasesWithAllrun)
75 FOREACH(caseWithAllrun ${listofCasesWithAllrun})
76 #Grab the name of the directory containing the file Allrun
77 get_filename_component(thisCasePath ${caseWithAllrun} PATH)
79 # We need to skip the global Allrun file
80 IF(NOT ${thisCasePath} STREQUAL ${TEST_CASE_DIR})
81 MESSAGE("Found Allrun file in directory: ${thisCasePath}")
83 # Grab the parent name of the case directory
84 string(REPLACE ${TEST_CASE_DIR}/ "" caseParentPath ${caseWithAllrun})
86 # Construct the testId
87 string(REPLACE "/" "_" testId ${caseParentPath})
88 SET(testId ${testId}${testIdSuffix})
90 # Add the test to the test harness
91 MESSAGE("Adding test: ${testId}")
92 ADD_TEST(${testId} bash -c "cd ${thisCasePath}; ./Allrun")
93 # Use this following entry instead for testing purpose
94 #ADD_TEST(${testId} bash -c "cd ${thisCasePath}; true")
96 ENDIF(NOT ${thisCasePath} STREQUAL ${TEST_CASE_DIR})
97 ENDFOREACH(caseWithAllrun)
99 # Modify the cases Allrun files to incorporate additional shell functions
100 MESSAGE("${testRunTimeDirectory}: Modifying the Allrun files for additional shell functions in directory: ${TEST_CASE_DIR}")
102 COMMAND $ENV{FOAM_TEST_HARNESS_DIR}/scripts/prepareCasesForTestHarness.sh ${TEST_CASE_DIR} $ENV{FOAM_TEST_HARNESS_DIR}/scripts/AdditionalRunFunctions