1 | #!/bin/bash |
---|
2 | # ------------------------------------------------------------------------------ |
---|
3 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | # ------------------------------------------------------------------------------ |
---|
20 | # Optional enviroment variables: |
---|
21 | # TEST_PROJECT (tests using given project name) |
---|
22 | # TEST_REMOTE_HOST (tests using svn+ssh repositories located on given host) |
---|
23 | # ------------------------------------------------------------------------------ |
---|
24 | |
---|
25 | . $(dirname $0)/../lib/bash/test_header |
---|
26 | |
---|
27 | function file_cmp() { |
---|
28 | local TEST_KEY=$1 |
---|
29 | local FILE_ACTUAL=$2 |
---|
30 | local FILE_EXPECT=${3:--} |
---|
31 | if cmp $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT; then |
---|
32 | pass $TEST_KEY |
---|
33 | return |
---|
34 | fi |
---|
35 | fail $TEST_KEY |
---|
36 | } |
---|
37 | |
---|
38 | function file_grep() { |
---|
39 | local TEST_KEY=$1 |
---|
40 | local PATTERN=$2 |
---|
41 | local FILE=$3 |
---|
42 | if grep -q -e "$PATTERN" $TEST_DIR/$FILE; then |
---|
43 | pass $TEST_KEY |
---|
44 | return |
---|
45 | fi |
---|
46 | fail $TEST_KEY |
---|
47 | } |
---|
48 | |
---|
49 | function file_test() { |
---|
50 | local TEST_KEY=$1 |
---|
51 | local FILE=$2 |
---|
52 | local OPTION=${3:--e} |
---|
53 | if test $OPTION $TEST_DIR/$FILE; then |
---|
54 | pass $TEST_KEY |
---|
55 | else |
---|
56 | fail $TEST_KEY |
---|
57 | fi |
---|
58 | } |
---|
59 | |
---|
60 | function file_xxdiff() { |
---|
61 | local TEST_KEY=$1 |
---|
62 | local FILE_ACTUAL=$2 |
---|
63 | local FILE_EXPECT=${3:--} |
---|
64 | if xxdiff -D $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT; then |
---|
65 | pass $TEST_KEY |
---|
66 | return |
---|
67 | fi |
---|
68 | fail $TEST_KEY |
---|
69 | } |
---|
70 | |
---|
71 | function init_repos() { |
---|
72 | if [[ -n ${TEST_REMOTE_HOST:-} ]]; then |
---|
73 | TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d") |
---|
74 | ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR" |
---|
75 | REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR" |
---|
76 | else |
---|
77 | svnadmin create --fs-type fsfs $TEST_DIR/test_repos |
---|
78 | REPOS_URL="file://$TEST_DIR/test_repos" |
---|
79 | fi |
---|
80 | ROOT_URL=$REPOS_URL |
---|
81 | PROJECT= |
---|
82 | if [[ -n ${TEST_PROJECT:-} ]]; then |
---|
83 | ROOT_URL=$REPOS_URL/$TEST_PROJECT |
---|
84 | PROJECT=$TEST_PROJECT"/" |
---|
85 | fi |
---|
86 | svn import -q $TEST_SOURCE_DIR/../etc/repo_files \ |
---|
87 | $REPOS_URL/$PROJECT/trunk -m "initial trunk import" |
---|
88 | svn mkdir -q $REPOS_URL/$PROJECT/tags -m "make tags" |
---|
89 | svn mkdir -q --parents $REPOS_URL/$PROJECT/branches/dev/Share -m " " |
---|
90 | } |
---|
91 | |
---|
92 | function init_repos_layout_roses() { |
---|
93 | if [[ -n ${TEST_REMOTE_HOST:-} ]]; then |
---|
94 | TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d") |
---|
95 | ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR" |
---|
96 | REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR" |
---|
97 | else |
---|
98 | svnadmin create --fs-type fsfs $TEST_DIR/test_repos |
---|
99 | REPOS_URL="file://$TEST_DIR/test_repos" |
---|
100 | fi |
---|
101 | svn mkdir -q --parents $REPOS_URL/a/a/0/0/0/trunk |
---|
102 | svn import -q $TEST_SOURCE_DIR/../etc/repo_files \ |
---|
103 | $REPOS_URL/a/a/0/0/0/trunk -m "initial trunk import" |
---|
104 | TMPFILE=$(mktemp) |
---|
105 | cat >$TMPFILE <<__LAYOUT__ |
---|
106 | depth-project = 5 |
---|
107 | depth-branch = 1 |
---|
108 | depth-tag = 1 |
---|
109 | dir-trunk = trunk |
---|
110 | dir-branch = |
---|
111 | dir-tag = |
---|
112 | level-owner-branch = |
---|
113 | level-owner-tag = |
---|
114 | template-branch = |
---|
115 | template-tag = |
---|
116 | __LAYOUT__ |
---|
117 | TMPDIR=$(mktemp -d) |
---|
118 | svn checkout -q $REPOS_URL $TMPDIR |
---|
119 | svn propset -q --file=$TMPFILE fcm:layout $TMPDIR |
---|
120 | svn commit -q -m " " $TMPDIR |
---|
121 | rm -f $TMPFILE |
---|
122 | rm -rf $TMPDIR |
---|
123 | ROOT_URL=$REPOS_URL |
---|
124 | } |
---|
125 | |
---|
126 | function init_branch() { |
---|
127 | local BRANCH_NAME=$1 |
---|
128 | local REPOS_URL=$2 |
---|
129 | local ROOT_URL=$REPOS_URL |
---|
130 | local ROOT_PATH= |
---|
131 | if [[ -n ${TEST_PROJECT:-} ]]; then |
---|
132 | ROOT_URL=$REPOS_URL/$TEST_PROJECT |
---|
133 | ROOT_PATH=$ROOT_PATH/$TEST_PROJECT |
---|
134 | fi |
---|
135 | MESSAGE=$(echo -e "Created $ROOT_PATH/branches/dev/Share/$BRANCH_NAME from /trunk@1.") |
---|
136 | svn copy -q -r1 $ROOT_URL/trunk $ROOT_URL/branches/dev/Share/$BRANCH_NAME \ |
---|
137 | -m "Made a branch $MESSAGE" |
---|
138 | } |
---|
139 | |
---|
140 | function init_branch_wc() { |
---|
141 | local BRANCH_NAME=$1 |
---|
142 | local REPOS_URL=$2 |
---|
143 | local ROOT_URL=$REPOS_URL |
---|
144 | if [[ -n ${TEST_PROJECT:-} ]]; then |
---|
145 | ROOT_URL=$REPOS_URL/$TEST_PROJECT |
---|
146 | fi |
---|
147 | init_branch $BRANCH_NAME $REPOS_URL |
---|
148 | svn checkout -q $ROOT_URL/branches/dev/Share/$BRANCH_NAME $TEST_DIR/wc |
---|
149 | } |
---|
150 | |
---|
151 | function init_merge_branches() { |
---|
152 | local BRANCH_NAME=$1 |
---|
153 | local OTHER_BRANCH_NAME=$2 |
---|
154 | local REPOS_URL=$3 |
---|
155 | local ROOT_URL=$REPOS_URL |
---|
156 | if [[ -n ${TEST_PROJECT:-} ]]; then |
---|
157 | ROOT_URL=$REPOS_URL/$TEST_PROJECT |
---|
158 | fi |
---|
159 | init_branch_wc $BRANCH_NAME $REPOS_URL |
---|
160 | cd $TEST_DIR/wc |
---|
161 | modify_files="lib/python/info/__init__.py lib/python/info/poems.py \ |
---|
162 | module/hello_constants.f90 module/hello_constants.inc \ |
---|
163 | module/hello_constants_dummy.inc" |
---|
164 | for file in $modify_files; do |
---|
165 | sed -i "s/for/FOR/g; s/fi/end if/g; s/in/IN/g;" "$file" |
---|
166 | sed -i "/#/d; /^ *!/d" "$file" |
---|
167 | sed -i "s/!/!!/g; s/q/\nq/g; s/[(]/(\n/g" "$file" |
---|
168 | done |
---|
169 | copy_file="module/hello_constants_dummy.inc" |
---|
170 | copy_file_dir=$(dirname "$copy_file") |
---|
171 | svn copy -q "$copy_file" "./added_file" |
---|
172 | svn copy -q "$copy_file_dir" "added_directory" |
---|
173 | touch "$copy_file_dir/tree_conflict_file" |
---|
174 | append_line_file="subroutine/hello_sub_dummy.h" |
---|
175 | svn add -q "$copy_file_dir/tree_conflict_file" |
---|
176 | echo "Modified a line" >>$append_line_file |
---|
177 | svn commit -q -m "Made changes for future merge of this branch" |
---|
178 | svn update -q |
---|
179 | init_branch $OTHER_BRANCH_NAME $REPOS_URL |
---|
180 | svn switch -q $ROOT_URL/branches/dev/Share/$OTHER_BRANCH_NAME |
---|
181 | echo " " > unversioned_file |
---|
182 | properties_file="subroutine/hello_sub.h" |
---|
183 | svn propset -q svn:executable "executable" $properties_file |
---|
184 | other_copy_file="module/hello_constants_dummy.inc" |
---|
185 | svn copy -q "$other_copy_file" "renamed_added_file" |
---|
186 | svn commit -q -m "Made changes for future merge" |
---|
187 | svn update -q |
---|
188 | svn switch -q $ROOT_URL/trunk |
---|
189 | trunk_change_file="lib/python/info/__init__.py" |
---|
190 | echo "trunk change" >>"$trunk_change_file" |
---|
191 | svn commit -q -m "Made trunk change" |
---|
192 | svn update -q |
---|
193 | echo "another trunk change" >>"$trunk_change_file" |
---|
194 | svn commit -q -m "Made another trunk change" |
---|
195 | svn update -q |
---|
196 | } |
---|
197 | |
---|
198 | function run_pass() { |
---|
199 | local TEST_KEY=$1 |
---|
200 | shift 1 |
---|
201 | if ! "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then |
---|
202 | fail $TEST_KEY |
---|
203 | return |
---|
204 | fi |
---|
205 | pass $TEST_KEY |
---|
206 | } |
---|
207 | |
---|
208 | function run_fail() { |
---|
209 | local TEST_KEY=$1 |
---|
210 | shift 1 |
---|
211 | if "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then |
---|
212 | fail $TEST_KEY |
---|
213 | return |
---|
214 | fi |
---|
215 | pass $TEST_KEY |
---|
216 | } |
---|
217 | |
---|
218 | function setup() { |
---|
219 | mkdir -p $TEST_DIR/.subversion |
---|
220 | mkdir -p $TEST_DIR/run |
---|
221 | cd $TEST_DIR/run |
---|
222 | } |
---|
223 | |
---|
224 | function teardown() { |
---|
225 | cd $TEST_DIR |
---|
226 | rm -rf $TEST_DIR/test_repos |
---|
227 | rm -rf $TEST_DIR/wc |
---|
228 | rm -rf $TEST_DIR/run |
---|
229 | rm -rf $TEST_DIR/.subversion |
---|
230 | if [[ -n ${TEST_REMOTE_HOST:-} ]]; then |
---|
231 | ssh $TEST_REMOTE_HOST "rm -rf $TEST_REMOTE_DIR" |
---|
232 | fi |
---|
233 | } |
---|
234 | |
---|
235 | REPOS_URL= |
---|
236 | ROOT_URL= |
---|
237 | PROJECT= |
---|