Introduce "generator expressions" to add_test()
[cmake.git] / Tests / CTestUpdateCommon.cmake
blob9b6960ff16304decb0fd7d1e2f494a3b24ff8ca0
1 #-----------------------------------------------------------------------------
2 # Function to run a child process and report output only on error.
3 function(run_child)
4   execute_process(${ARGN}
5     RESULT_VARIABLE FAILED
6     OUTPUT_VARIABLE OUTPUT
7     ERROR_VARIABLE OUTPUT
8     OUTPUT_STRIP_TRAILING_WHITESPACE
9     ERROR_STRIP_TRAILING_WHITESPACE
10     )
11   if(FAILED)
12     string(REGEX REPLACE "\n" "\n  " OUTPUT "${OUTPUT}")
13     message(FATAL_ERROR "Child failed (${FAILED}), output is\n  ${OUTPUT}\n")
14   endif(FAILED)
15 endfunction(run_child)
17 #-----------------------------------------------------------------------------
18 # Function to find the Update.xml file and check for expected entries.
19 function(check_updates build)
20   # Find the Update.xml file for the given build tree
21   set(PATTERN ${TOP}/${build}/Testing/*/Update.xml)
22   file(GLOB UPDATE_XML_FILE RELATIVE ${TOP} ${PATTERN})
23   string(REGEX REPLACE "//Update.xml$" "/Update.xml"
24     UPDATE_XML_FILE "${UPDATE_XML_FILE}"
25     )
26   if(NOT UPDATE_XML_FILE)
27     message(FATAL_ERROR "Cannot find Update.xml with pattern\n  ${PATTERN}")
28   endif(NOT UPDATE_XML_FILE)
29   message(" found ${UPDATE_XML_FILE}")
31   # Read entries from the Update.xml file
32   file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_ENTRIES
33     REGEX "FullName"
34     LIMIT_INPUT 4096
35     )
37   # Verify that expected entries exist
38   set(MISSING)
39   foreach(f ${ARGN})
40     string(REPLACE "/" "[/\\\\]" regex "${f}")
41     string(REPLACE "." "\\." regex "${regex}")
42     if(NOT "${UPDATE_XML_ENTRIES}" MATCHES "<FullName>${regex}</FullName>")
43       list(APPEND MISSING ${f})
44     endif()
45   endforeach(f)
47   # Report the result
48   if(MISSING)
49     # List the missing entries
50     set(MSG "Update.xml is missing an entry for:\n")
51     foreach(f ${MISSING})
52       set(MSG "${MSG}  ${f}\n")
53     endforeach(f)
55     # Provide the log file
56     file(GLOB UPDATE_LOG_FILE
57       ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
58     if(UPDATE_LOG_FILE)
59       file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT 4096)
60       string(REGEX REPLACE "\n" "\n  " UPDATE_LOG "${UPDATE_LOG}")
61       set(MSG "${MSG}Update log:\n  ${UPDATE_LOG}")
62     else(UPDATE_LOG_FILE)
63       set(MSG "${MSG}No update log found!")
64     endif(UPDATE_LOG_FILE)
66     # Display the error message
67     message(FATAL_ERROR "${MSG}")
68   else(MISSING)
69     # Success
70     message(" no entries missing from Update.xml")
71   endif(MISSING)
72 endfunction(check_updates)
74 #-----------------------------------------------------------------------------
75 # Function to create initial content.
76 function(create_content dir)
77   file(MAKE_DIRECTORY ${TOP}/${dir})
79   # An example CTest project configuration file.
80   file(WRITE ${TOP}/${dir}/CTestConfig.cmake
81     "# CTest Configuration File
82 set(CTEST_PROJECT_NAME TestProject)
83 set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
86   # Some other files.
87   file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
88   file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
89 endfunction(create_content)
91 #-----------------------------------------------------------------------------
92 # Function to update content.
93 function(update_content dir added_var removed_var dirs_var)
94   file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
95   file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
96   file(REMOVE ${TOP}/${dir}/bar.txt)
97   file(MAKE_DIRECTORY ${TOP}/${dir}/subdir)
98   file(WRITE ${TOP}/${dir}/subdir/foo.txt "foo\n")
99   file(WRITE ${TOP}/${dir}/subdir/bar.txt "bar\n")
100   set(${dirs_var} subdir PARENT_SCOPE)
101   set(${added_var} zot.txt subdir/foo.txt subdir/bar.txt PARENT_SCOPE)
102   set(${removed_var} bar.txt PARENT_SCOPE)
103 endfunction(update_content)
105 #-----------------------------------------------------------------------------
106 # Function to change existing files
107 function(change_content dir)
108   file(APPEND ${TOP}/${dir}/foo.txt "foo line 3\n")
109   file(APPEND ${TOP}/${dir}/subdir/foo.txt "foo line 2\n")
110 endfunction(change_content)
112 #-----------------------------------------------------------------------------
113 # Function to create local modifications before update
114 function(modify_content dir)
115   file(APPEND ${TOP}/${dir}/CTestConfig.cmake "# local modification\n")
116 endfunction(modify_content)
118 #-----------------------------------------------------------------------------
119 # Function to write CTestConfiguration.ini content.
120 function(create_build_tree src_dir bin_dir)
121   file(MAKE_DIRECTORY ${TOP}/${bin_dir})
122   file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
123     "# CTest Configuration File
124 SourceDirectory: ${TOP}/${src_dir}
125 BuildDirectory: ${TOP}/${bin_dir}
126 Site: test.site
127 BuildName: user-test
129 endfunction(create_build_tree)
131 #-----------------------------------------------------------------------------
132 # Function to write the dashboard test script.
133 function(create_dashboard_script name custom_text)
134   # Write the dashboard script.
135   file(WRITE ${TOP}/dashboard.cmake
136     "# CTest Dashboard Script
137 set(CTEST_DASHBOARD_ROOT \"${TOP}\")
138 set(CTEST_SITE test.site)
139 set(CTEST_BUILD_NAME dash-test)
140 set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
141 set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-binary)
142 ${custom_text}
143 # Start a dashboard and run the update step
144 ctest_start(Experimental)
145 ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
147 endfunction(create_dashboard_script)
149 #-----------------------------------------------------------------------------
150 # Function to run the dashboard through the command line
151 function(run_dashboard_command_line bin_dir)
152   run_child(
153     WORKING_DIRECTORY ${TOP}/${bin_dir}
154     COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
155     )
157   # Verify the updates reported by CTest.
158   check_updates(${bin_dir} foo.txt bar.txt zot.txt CTestConfig.cmake
159                            subdir/foo.txt subdir/bar.txt)
160 endfunction(run_dashboard_command_line)
162 #-----------------------------------------------------------------------------
163 # Function to run the dashboard through a script
164 function(run_dashboard_script name)
165   run_child(
166     WORKING_DIRECTORY ${TOP}
167     COMMAND ${CMAKE_CTEST_COMMAND} -S ${name} -V
168     )
170   # Verify the updates reported by CTest.
171   check_updates(dash-binary foo.txt bar.txt zot.txt
172                             subdir/foo.txt subdir/bar.txt)
173 endfunction(run_dashboard_script)
175 #-----------------------------------------------------------------------------
176 # Function to initialize the testing directory.
177 function(init_testing)
178   file(REMOVE_RECURSE ${TOP})
179   file(MAKE_DIRECTORY ${TOP})
180 endfunction(init_testing)