Introduce "generator expressions" to add_test()
[cmake.git] / Tests / CTestUpdateGIT.cmake.in
blob2606254fd05f016acb44033d9394427cd7db679d
1 # This script drives creation of a git repository and checks
2 # that CTest can update from it.
4 #-----------------------------------------------------------------------------
5 # Test in a directory next to this script.
6 get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
7 set(TOP "${TOP}/@CTestUpdateGIT_DIR@")
9 # Include code common to all update tests.
10 include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
12 #-----------------------------------------------------------------------------
13 # Report git tools in use.
14 message("Using GIT tools:")
15 set(GIT "@GIT_EXECUTABLE@")
16 message(" git = ${GIT}")
18 set(AUTHOR_CONFIG "[user]
19 \tname = Test Author
20 \temail = testauthor@cmake.org
23 #-----------------------------------------------------------------------------
24 # Initialize the testing directory.
25 message("Creating test directory...")
26 init_testing()
28 #-----------------------------------------------------------------------------
29 # Create the repository.
30 message("Creating repository...")
31 file(MAKE_DIRECTORY ${TOP}/repo.git)
32 run_child(
33   WORKING_DIRECTORY ${TOP}/repo.git
34   COMMAND ${GIT} --bare init
35   )
36 file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
37 set(REPO file://${TOP}/repo.git)
39 #-----------------------------------------------------------------------------
40 # Import initial content into the repository.
41 message("Importing content...")
42 create_content(import)
44 # Import the content into the repository.
45 run_child(WORKING_DIRECTORY ${TOP}/import
46   COMMAND ${GIT} init
47   )
48 file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
49 file(APPEND ${TOP}/import/.git/config "
50 [remote \"origin\"]
51 \turl = ${REPO}
52 \tfetch = +refs/heads/*:refs/remotes/origin/*
53 ${AUTHOR_CONFIG}")
54 run_child(WORKING_DIRECTORY ${TOP}/import
55   COMMAND ${GIT} add .
56   )
57 run_child(WORKING_DIRECTORY ${TOP}/import
58   COMMAND ${GIT} commit -m "Initial content"
59   )
60 run_child(WORKING_DIRECTORY ${TOP}/import
61   COMMAND ${GIT} push origin master:refs/heads/master
62   )
64 #-----------------------------------------------------------------------------
65 # Create a working tree.
66 message("Checking out revision 1...")
67 run_child(
68   WORKING_DIRECTORY ${TOP}
69   COMMAND ${GIT} clone ${REPO} user-source
70   )
71 file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
72 file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
74 #-----------------------------------------------------------------------------
75 # Make changes in the working tree.
76 message("Changing content...")
77 update_content(user-source files_added files_removed dirs_added)
78 if(dirs_added)
79   run_child(
80     WORKING_DIRECTORY ${TOP}/user-source
81     COMMAND ${GIT} add ${dirs_added}
82     )
83 endif(dirs_added)
84 run_child(
85   WORKING_DIRECTORY ${TOP}/user-source
86   COMMAND ${GIT} add ${files_added}
87   )
88 run_child(
89   WORKING_DIRECTORY ${TOP}/user-source
90   COMMAND ${GIT} rm ${files_removed}
91   )
92 run_child(
93   WORKING_DIRECTORY ${TOP}/user-source
94   COMMAND ${GIT} add -u
95   )
97 #-----------------------------------------------------------------------------
98 # Commit the changes to the repository.
99 message("Committing revision 2...")
100 run_child(
101   WORKING_DIRECTORY ${TOP}/user-source
102   COMMAND ${GIT} commit -m "Changed content"
103   )
104 run_child(
105   WORKING_DIRECTORY ${TOP}/user-source
106   COMMAND ${GIT} push origin
107   )
109 #-----------------------------------------------------------------------------
110 # Make changes in the working tree.
111 message("Changing content again...")
112 change_content(user-source)
113 run_child(
114   WORKING_DIRECTORY ${TOP}/user-source
115   COMMAND ${GIT} add -u
116   )
118 #-----------------------------------------------------------------------------
119 # Commit the changes to the repository.
120 message("Committing revision 3...")
121 run_child(
122   WORKING_DIRECTORY ${TOP}/user-source
123   COMMAND ${GIT} commit -m "Changed content again"
124   )
125 run_child(
126   WORKING_DIRECTORY ${TOP}/user-source
127   COMMAND ${GIT} push origin
128   )
130 #-----------------------------------------------------------------------------
131 # Go back to before the changes so we can test updating.
132 message("Backing up to revision 1...")
133 run_child(
134   WORKING_DIRECTORY ${TOP}/user-source
135   COMMAND ${GIT} reset --hard master~2
136   )
138 # Create a modified file.
139 modify_content(user-source)
141 #-----------------------------------------------------------------------------
142 # Test updating the user work directory with the command-line interface.
143 message("Running CTest Dashboard Command Line...")
145 # Create the user build tree.
146 create_build_tree(user-source user-binary)
147 file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
148   "# GIT command configuration
149 UpdateCommand: ${GIT}
152 # Run the dashboard command line interface.
153 run_dashboard_command_line(user-binary)
155 #-----------------------------------------------------------------------------
156 # Test initial checkout and update with a dashboard script.
157 message("Running CTest Dashboard Script...")
159 create_dashboard_script(dashboard.cmake
160   "# git command configuration
161 set(CTEST_GIT_COMMAND \"${GIT}\")
162 set(CTEST_GIT_UPDATE_OPTIONS)
163 execute_process(
164   WORKING_DIRECTORY \"${TOP}\"
165   COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
166   )
167 execute_process(
168   WORKING_DIRECTORY \"${TOP}/dash-source\"
169   COMMAND \"${GIT}\" reset --hard master~2
170   )
173 # Run the dashboard script with CTest.
174 run_dashboard_script(dashboard.cmake)