source: vendors/FCM-2017.10.0/t/lib/bash/svn_test_header @ 11150

Last change on this file since 11150 was 10672, checked in by nicolasmartin, 3 years ago

Reimport latest FCM release

File size: 9.2 KB
Line 
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
27function file_cmp() {
28    local TEST_KEY=$1
29    local FILE_ACTUAL=$2
30    local FILE_EXPECT=${3:--}
31    if diff -u $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT >&2; then
32        pass $TEST_KEY
33        return
34    fi
35    fail $TEST_KEY
36}
37
38function 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
49function 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
60function 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
71function init_repos() {
72    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
73        TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d")
74        ssh $TEST_REMOTE_HOST bash -l -c "svnadmin create --fs-type fsfs\
75            $TEST_REMOTE_DIR"
76        REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR"
77    else
78        svnadmin create --fs-type fsfs $TEST_DIR/test_repos
79        REPOS_URL="file://$TEST_DIR/test_repos"
80    fi
81    ROOT_URL=$REPOS_URL
82    PROJECT=
83    if [[ -n ${TEST_PROJECT:-} ]]; then
84        ROOT_URL=$REPOS_URL/$TEST_PROJECT
85        PROJECT=$TEST_PROJECT"/"
86    fi
87    svn import -q $TEST_SOURCE_DIR/../etc/repo_files \
88        $REPOS_URL/$PROJECT/trunk -m "initial trunk import"
89    svn mkdir -q $REPOS_URL/$PROJECT/tags -m "make tags"
90    svn mkdir -q --parents $REPOS_URL/$PROJECT/branches/dev/Share -m " "
91}
92
93function init_repos_layout_roses() {
94    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
95        TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d")
96        ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR"
97        REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR"
98    else
99        svnadmin create --fs-type fsfs $TEST_DIR/test_repos
100        REPOS_URL="file://$TEST_DIR/test_repos"
101    fi
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__
106depth-project = 5
107depth-branch = 1
108depth-tag = 1
109dir-trunk = trunk
110dir-branch =
111dir-tag =
112level-owner-branch =
113level-owner-tag =
114template-branch =
115template-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
126function 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
140function 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
151function 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
198function 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
208function 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
218function get_results() {
219    local RESULT_KEY=$1
220    local RESULTS_FILE=$2
221    local BEGIN="^begin-$RESULT_KEY$"
222    local END="^end-$RESULT_KEY$"
223    local RESULTS_TEMP=$(mktemp)
224    sed -n "/$BEGIN/,/$END/{/$BEGIN\|$END/d; p;}" $RESULTS_FILE >$RESULTS_TEMP
225    echo $RESULTS_TEMP
226}
227
228function test_mergeinfo() {
229    local TEST_INFO_NAME="$1-svn-mergeinfo"
230    local DIFF_BRANCH=$2
231    local INPUT_RESULTS_FILE=${3:--}
232    local WC_REVISION=${4:-WC}
233    if "$SVN_VERSION_IS_19"; then
234        WC_REVISION=WC
235    elif (( WC_REVISION < 10 )); then
236        WC_REVISION="$WC_REVISION "
237    fi
238    local RESULTS_FILE=$(mktemp)
239    sed "s/^\(.\{23\}\)WC/\1$WC_REVISION/" "$INPUT_RESULTS_FILE" \
240        >"$RESULTS_FILE"
241    # Test svn:mergeinfo property.
242    TEST_KEY=$TEST_INFO_NAME-prop
243    PROP_RESULT_TEXT=$(cat <$(get_results prop $RESULTS_FILE))
244    if [[ -n "$PROP_RESULT_TEXT" ]]; then
245        run_pass "$TEST_KEY" svn propget svn:mergeinfo .
246        file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <$(get_results prop $RESULTS_FILE)
247        file_cmp "$TEST_KEY.err" "$TEST_KEY.err" </dev/null
248    else
249        # Subversion 1.9 won't set null mergeinfo.
250        skip 3
251    fi
252    # Test svn mergeinfo output.
253    TEST_KEY=$TEST_INFO_NAME-info
254    run_pass "$TEST_KEY" svn mergeinfo $DIFF_BRANCH
255    file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <$(get_results info $RESULTS_FILE)   
256    file_cmp "$TEST_KEY.err" "$TEST_KEY.err" </dev/null
257    # Test svn mergeinfo show-revs eligible before merge.
258    TEST_KEY=$TEST_INFO_NAME-show-revs-eligible
259    run_pass "$TEST_KEY" svn mergeinfo --show-revs eligible $DIFF_BRANCH
260    file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <$(get_results eligible $RESULTS_FILE)       
261    file_cmp "$TEST_KEY.err" "$TEST_KEY.err" </dev/null
262    # Test svn mergeinfo show-revs merged before merge.
263    TEST_KEY=$TEST_INFO_NAME-show-revs-merged
264    run_pass "$TEST_KEY" svn mergeinfo --show-revs merged $DIFF_BRANCH
265    file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <$(get_results merged $RESULTS_FILE)           
266    file_cmp "$TEST_KEY.err" "$TEST_KEY.err" </dev/null
267}
268
269function setup() {
270    mkdir -p $TEST_DIR/.subversion
271    mkdir -p $TEST_DIR/run
272    cd $TEST_DIR/run
273}
274
275function teardown() {
276    cd $TEST_DIR
277    rm -rf $TEST_DIR/test_repos
278    rm -rf $TEST_DIR/wc
279    rm -rf $TEST_DIR/run
280    rm -rf $TEST_DIR/.subversion
281    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
282        ssh $TEST_REMOTE_HOST "rm -rf $TEST_REMOTE_DIR"
283    fi
284}
285
286REPOS_URL=
287ROOT_URL=
288PROJECT=
Note: See TracBrowser for help on using the repository browser.