New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
test_header in vendors/t/fcm-loc-layout – NEMO

source: vendors/t/fcm-loc-layout/test_header @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 7.1 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_REMOTE_HOST (tests using svn+ssh repositories located on given host)
22# ------------------------------------------------------------------------------
23
24. $(dirname $0)/../lib/bash/test_header
25
26function file_cmp() {
27    local TEST_KEY=$1
28    local FILE_ACTUAL=$2
29    local FILE_EXPECT=${3:--}
30    if cmp $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT; then
31        pass $TEST_KEY
32        return
33    fi
34    fail $TEST_KEY
35}
36
37function file_grep() {
38    local TEST_KEY=$1
39    local PATTERN=$2
40    local FILE=$3
41    if grep -q -e "$PATTERN" $TEST_DIR/$FILE; then
42        pass $TEST_KEY
43        return
44    fi
45    fail $TEST_KEY
46}
47
48function file_test() {
49    local TEST_KEY=$1
50    local FILE=$2
51    local OPTION=${3:--e}
52    if test $OPTION $TEST_DIR/$FILE; then
53        pass $TEST_KEY
54    else
55        fail $TEST_KEY
56    fi
57}
58
59function file_xxdiff() {
60    local TEST_KEY=$1
61    local FILE_ACTUAL=$2
62    local FILE_EXPECT=${3:--}
63    if xxdiff -D $TEST_DIR/$FILE_ACTUAL $FILE_EXPECT; then
64        pass $TEST_KEY
65        return
66    fi
67    fail $TEST_KEY
68}
69
70function init_repos() {
71    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
72        TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d")
73        ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR"
74        REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR"
75    else
76        svnadmin create --fs-type fsfs $TEST_DIR/test_repos
77        REPOS_URL="file://$TEST_DIR/test_repos"
78    fi
79    ROOT_URL=$REPOS_URL
80    PROJECT=
81    if [[ -n ${TEST_PROJECT:-} ]]; then
82        ROOT_URL=$REPOS_URL/$TEST_PROJECT
83        PROJECT=$TEST_PROJECT"/"
84    fi
85    svn import -q $TEST_SOURCE_DIR/../etc/repo_files \
86        $REPOS_URL/$PROJECT/trunk -m "initial trunk import"
87    svn mkdir -q $REPOS_URL/$PROJECT/tags -m "make tags"
88    svn mkdir -q --parents $REPOS_URL/$PROJECT/branches/dev/Share -m " "
89}
90
91function init_repos_layout_roses() {
92    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
93        TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d")
94        ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR"
95        REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR"
96    else
97        svnadmin create --fs-type fsfs $TEST_DIR/test_repos
98        REPOS_URL="file://$TEST_DIR/test_repos"
99    fi
100    svn mkdir -q --parents $REPOS_URL/a/a/0/0/0/trunk
101    svn import -q $TEST_SOURCE_DIR/../etc/repo_files \
102        $REPOS_URL/a/a/0/0/0/trunk -m "initial trunk import"
103    TMPFILE=$(mktemp)
104    cat >$TMPFILE <<__LAYOUT__
105depth-project = 5
106depth-branch = 1
107depth-tag = 1
108dir-trunk = trunk
109dir-branch =
110dir-tag =
111level-owner-branch =
112level-owner-tag =
113template-branch =
114template-tag =
115__LAYOUT__
116    TMPDIR=$(mktemp -d)
117    svn checkout -q $REPOS_URL $TMPDIR
118    svn propset -q --file=$TMPFILE fcm:layout $TMPDIR
119    svn commit -q -m " " $TMPDIR
120    rm -f $TMPFILE
121    rm -rf $TMPDIR
122    ROOT_URL=$REPOS_URL
123}
124
125function init_branch() {
126    local BRANCH_NAME=$1
127    local REPOS_URL=$2
128    local ROOT_URL=$REPOS_URL
129    local ROOT_PATH=
130    if [[ -n ${TEST_PROJECT:-} ]]; then
131        ROOT_URL=$REPOS_URL/$TEST_PROJECT
132        ROOT_PATH=$ROOT_PATH/$TEST_PROJECT
133    fi
134    MESSAGE=$(echo -e "Created $ROOT_PATH/branches/dev/Share/$BRANCH_NAME from /trunk@1.")
135    svn copy -q -r1 $ROOT_URL/trunk $ROOT_URL/branches/dev/Share/$BRANCH_NAME \
136                    -m "Made a branch $MESSAGE"
137}
138
139function init_branch_wc() {
140    local BRANCH_NAME=$1
141    local REPOS_URL=$2
142    local ROOT_URL=$REPOS_URL
143    if [[ -n ${TEST_PROJECT:-} ]]; then
144        ROOT_URL=$REPOS_URL/$TEST_PROJECT
145    fi
146    init_branch $BRANCH_NAME $REPOS_URL
147    svn checkout -q $ROOT_URL/branches/dev/Share/$BRANCH_NAME $TEST_DIR/wc
148}
149
150function init_merge_branches() {
151    local BRANCH_NAME=$1
152    local OTHER_BRANCH_NAME=$2
153    local REPOS_URL=$3
154    local ROOT_URL=$REPOS_URL
155    if [[ -n ${TEST_PROJECT:-} ]]; then
156        ROOT_URL=$REPOS_URL/$TEST_PROJECT
157    fi
158    init_branch_wc $BRANCH_NAME $REPOS_URL
159    cd $TEST_DIR/wc
160    modify_files="lib/python/info/__init__.py lib/python/info/poems.py \
161                  module/hello_constants.f90 module/hello_constants.inc \
162                  module/hello_constants_dummy.inc"
163    for file in $modify_files; 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    copy_file="module/hello_constants_dummy.inc"   
169    copy_file_dir=$(dirname "$copy_file")
170    svn copy -q "$copy_file" "./added_file"
171    svn copy -q "$copy_file_dir" "added_directory"
172    touch "$copy_file_dir/tree_conflict_file"
173    append_line_file="subroutine/hello_sub_dummy.h"   
174    svn add -q "$copy_file_dir/tree_conflict_file"
175    echo "Modified a line" >>$append_line_file
176    svn commit -q -m "Made changes for future merge of this branch"
177    svn update -q
178    init_branch $OTHER_BRANCH_NAME $REPOS_URL
179    svn switch -q $ROOT_URL/branches/dev/Share/$OTHER_BRANCH_NAME
180    echo " " > unversioned_file
181    properties_file="subroutine/hello_sub.h"
182    svn propset -q svn:executable "executable" $properties_file
183    other_copy_file="module/hello_constants_dummy.inc"
184    svn copy -q "$other_copy_file" "renamed_added_file"
185    svn commit -q -m "Made changes for future merge"
186    svn update -q
187    svn switch -q $ROOT_URL/trunk
188    trunk_change_file="lib/python/info/__init__.py"
189    echo "trunk change" >>"$trunk_change_file"
190    svn commit -q -m "Made trunk change"
191    svn update -q
192    echo "another trunk change" >>"$trunk_change_file"
193    svn commit -q -m "Made another trunk change"
194    svn update -q
195}
196
197function run_pass() {
198    local TEST_KEY=$1
199    shift 1
200    if ! "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then
201        fail $TEST_KEY
202        return
203    fi
204    pass $TEST_KEY
205}
206
207function run_fail() {
208    local TEST_KEY=$1
209    shift 1
210    if "$@" 1>$TEST_DIR/$TEST_KEY.out 2>$TEST_DIR/$TEST_KEY.err; then
211        fail $TEST_KEY
212        return
213    fi
214    pass $TEST_KEY
215}
216
217function setup() {
218    mkdir -p $TEST_DIR/.subversion
219    mkdir -p $TEST_DIR/run
220    cd $TEST_DIR/run
221}
222
223function teardown() {
224    cd $TEST_DIR
225    rm -rf $TEST_DIR/test_repos
226    rm -rf $TEST_DIR/wc
227    rm -rf $TEST_DIR/run
228    rm -rf $TEST_DIR/.subversion
229    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
230        ssh $TEST_REMOTE_HOST "rm -rf $TEST_REMOTE_DIR"
231    fi
232}
233
234REPOS_URL=
235ROOT_URL=
236PROJECT=
Note: See TracBrowser for help on using the repository browser.