source: vendors/FCM-2017.10.0/t/svn-username/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: 6.9 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 cmp $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT; 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 "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
92function 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__
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    file_list=$(find . -type f | sed "/\.svn/d" | sort | head -5)
162    other_file=$(find . -type f | sed "/\.svn/d" | sort | tail -1)
163    for file in $file_list; do
164        sed -i "s/for/FOR/g; s/fi/end if/g; s/in/IN/g;" $file
165        sed -i "/#/d; /^ *!/d" $file
166        sed -i "s/!/!!/g; s/q/\nq/g; s/[(]/(\n/g" $file
167    done
168    file_dir=$(dirname $file)
169    svn copy -q $file ./added_file
170    svn copy -q module added_directory
171    touch module/tree_conflict_file
172    svn add -q $file_dir/tree_conflict_file
173    echo "Modified a line" >>$other_file
174    svn commit -q -m "Made changes for future merge of this branch"
175    svn update -q
176    init_branch $OTHER_BRANCH_NAME $REPOS_URL
177    svn switch -q $ROOT_URL/branches/dev/Share/$OTHER_BRANCH_NAME
178    echo " " > unversioned_file
179    properties_file=$(find . -type f | sed " /\.svn/d" | sort | tail -3 | head -1)
180    svn propset -q svn:executable "executable" $properties_file
181    svn copy -q $file renamed_added_file
182    svn commit -q -m "Made changes for future merge"
183    svn update -q
184    svn switch -q $ROOT_URL/trunk
185    echo "trunk change" >>$(find . -type f | sed "/\.svn/d" | sort | head -1)
186    svn commit -q -m "Made trunk change"
187    svn update -q
188    echo "another trunk change" >>$(find . -type f | sed "/\.svn/d" | sort | head -1)
189    svn commit -q -m "Made another trunk change"
190    svn update -q
191}
192
193function run_pass() {
194    local TEST_KEY=$1
195    shift 1
196    if ! "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then
197        fail $TEST_KEY
198        return
199    fi
200    pass $TEST_KEY
201}
202
203function run_fail() {
204    local TEST_KEY=$1
205    shift 1
206    if "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then
207        fail $TEST_KEY
208        return
209    fi
210    pass $TEST_KEY
211}
212
213function setup() {
214    mkdir -p $TEST_DIR/.subversion
215    mkdir -p $TEST_DIR/run
216    cd $TEST_DIR/run
217}
218
219function teardown() {
220    cd $TEST_DIR
221    rm -rf $TEST_DIR/test_repos
222    rm -rf $TEST_DIR/wc
223    rm -rf $TEST_DIR/run
224    rm -rf $TEST_DIR/.subversion
225    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
226        ssh $TEST_REMOTE_HOST "rm -rf $TEST_REMOTE_DIR"
227    fi
228}
229
230REPOS_URL=
231ROOT_URL=
232PROJECT=
Note: See TracBrowser for help on using the repository browser.