1#!/bin/sh
2#
3#       aegis - project change supervisor
4#       Copyright (C) 2003-2008, 2012 Peter Miller
5#       Copyright (C) 2008 Walter Franzini
6#
7#       This program 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#       This program 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 this program. If not, see
19#       <http://www.gnu.org/licenses/>.
20#
21
22unset AEGIS_PROJECT
23unset AEGIS_CHANGE
24unset AEGIS_PATH
25unset AEGIS
26umask 022
27
28#
29# Make sure cvs is installed on this machine.
30# If it is not, give an automatic pass.
31#
32if cvs --version > /dev/null 2>&1
33then
34    :
35else
36    echo ''
37    echo '      You do not have CVS installed on this machine.'
38    echo '      This test is assumed to pass by default.'
39    echo ''
40    exit 0
41fi
42
43CVSversion=`cvs --version |
44awk 'NR==2{split($5,a,"[.]");printf("%02d.%02d.%02d\n",a[1],a[2],a[3]);}'`
45if expr "$CVSversion" "<" "01.11.00" > /dev/null 2>&1
46then
47    echo ''
48    echo '      You do not have CVS 1.11 or later installed on this machine.'
49    echo '      This test is assumed to pass by default.'
50    echo ''
51    exit 0
52fi
53
54LINES=24
55export LINES
56COLS=80
57export COLS
58
59USER=${USER:-${LOGNAME:-`whoami`}}
60
61work=${AEGIS_TMP:-/tmp}/$$
62PAGER=cat
63export PAGER
64AEGIS_FLAGS="delete_file_preference = no_keep; \
65        lock_wait_preference = always; \
66        diff_preference = automatic_merge; \
67        pager_preference = never; \
68        persevere_preference = all; \
69        log_file_preference = never;"
70export AEGIS_FLAGS
71AEGIS_THROTTLE=-1
72export AEGIS_THROTTLE
73
74here=`pwd`
75if test $? -ne 0 ; then exit 2; fi
76
77bin=$here/${1-.}/bin
78
79if test "$EXEC_SEARCH_PATH" != ""
80then
81    tpath=
82    hold="$IFS"
83    IFS=":$IFS"
84    for tpath2 in $EXEC_SEARCH_PATH
85    do
86        tpath=${tpath}${tpath2}/${1-.}/bin:
87    done
88    IFS="$hold"
89    PATH=${tpath}${PATH}
90else
91    PATH=${bin}:${PATH}
92fi
93export PATH
94
95check_it()
96{
97        sed     -e "s|$work|...|g" \
98                -e 's|= [0-9][0-9]*; /.*|= TIME;|' \
99                -e "s/\"$USER\"/\"USER\"/g" \
100                -e 's/19[0-9][0-9]/YYYY/' \
101                -e 's/20[0-9][0-9]/YYYY/' \
102                -e 's/node = ".*"/node = "NODE"/' \
103                -e 's/crypto = ".*"/crypto = "GUNK"/' \
104                < $2 > $work/sed.out
105        if test $? -ne 0; then no_result; fi
106        diff -b $1 $work/sed.out
107        if test $? -ne 0; then fail; fi
108}
109
110pass()
111{
112        set +x
113        echo PASSED 1>&2
114        cd $here
115        find $work -type d -user $USER -exec chmod u+w {} \;
116        rm -rf $work
117        exit 0
118}
119fail()
120{
121        set +x
122        echo 'FAILED test of the aecvsserver remove functionality' \
123                "($activity)" 1>&2
124        cd $here
125        find $work -type d -user $USER -exec chmod u+w {} \;
126        rm -rf $work
127        exit 1
128}
129no_result()
130{
131        set +x
132        echo 'NO RESULT when testing the aecvsserver remove functionality' \
133                "($activity)" 1>&2
134        cd $here
135        find $work -type d -user $USER -exec chmod u+w {} \;
136        rm -rf $work
137        exit 2
138}
139trap \"no_result\" 1 2 3 15
140
141mkdir $work $work/lib
142if test $? -ne 0 ; then no_result; fi
143chmod 777 $work/lib
144if test $? -ne 0 ; then no_result; fi
145cd $work
146if test $? -ne 0 ; then no_result; fi
147
148#
149# use the built-in error messages
150#
151AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
152export AEGIS_MESSAGE_LIBRARY
153unset LANG
154unset LANGUAGE
155
156workproj=$work/proj
157workchan=$work/chan
158
159AEGIS_PATH=$work/lib ; export AEGIS_PATH
160AEGIS_PROJECT=foo ; export AEGIS_PROJECT
161
162#
163# make a new project
164#
165activity="new project 154"
166$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
167if test $? -ne 0 ; then cat log; no_result; fi
168
169#
170# change project attributes
171#
172activity="project attributes 161"
173cat > tmp << 'end'
174description = "A bogus project created to test the aecvsserver add "
175    "functionality.";
176developer_may_review = true;
177developer_may_integrate = true;
178reviewer_may_integrate = true;
179default_test_exemption = true;
180end
181if test $? -ne 0 ; then no_result; fi
182$bin/aegis -pa -f tmp > log 2>&1
183if test $? -ne 0 ; then cat log; no_result; fi
184
185#
186# add the staff
187#
188activity="staff 177"
189$bin/aegis -nd $USER > log 2>&1
190if test $? -ne 0 ; then cat log; no_result; fi
191$bin/aegis -nrv $USER > log 2>&1
192if test $? -ne 0 ; then cat log; no_result; fi
193$bin/aegis -ni $USER > log 2>&1
194if test $? -ne 0 ; then cat log; no_result; fi
195
196# --------------------------------------------------------------------------
197
198#
199# create a new change
200#
201activity="new change 190"
202cat > tmp << 'end'
203brief_description = "The first change";
204cause = internal_bug;
205end
206if test $? -ne 0 ; then no_result; fi
207$bin/aegis -nc 1 -f tmp -p foo > log 2>&1
208if test $? -ne 0 ; then cat log; no_result; fi
209
210#
211# begin development of a change
212#
213$bin/aegis -db 1 -dir $workchan > log 2>&1
214if test $? -ne 0 ; then cat log; no_result; fi
215
216#
217# add a new files to the change
218#
219activity="new file 208"
220$bin/aegis -nf $workchan/dir/bogus -nl \
221    -uuid "aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd1" > log 2>&1
222if test $? -ne 0 ; then cat log; no_result; fi
223$bin/aegis -nf $workchan/aegis.conf -nl \
224    -uuid "aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd2" > log 2>&1
225if test $? -ne 0 ; then cat log; no_result; fi
226
227cat > $workchan/dir/bogus << 'end'
228the trunk version
229end
230if test $? -ne 0 ; then no_result; fi
231
232cat > $workchan/aegis.conf << 'end'
233build_command = "exit 0";
234link_integration_directory = true;
235
236history_get_command = "aesvt -check-out -edit ${quote $edit} "
237    "-history ${quote $history} -f ${quote $output}";
238history_put_command = "aesvt -check-in -history ${quote $history} "
239    "-f ${quote $input}";
240history_query_command = "aesvt -query -history ${quote $history}";
241history_content_limitation = binary_capable;
242
243diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
244diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
245        echo '1,$$p' ) | ed - $mr > $out";
246patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
247test $$? -le 1";
248end
249if test $? -ne 0 ; then no_result; fi
250
251#
252# build the change
253#
254activity="build 243"
255$bin/aegis -build -nl -v > log 2>&1
256if test $? -ne 0 ; then cat log; no_result; fi
257
258#
259# difference the change
260#
261activity="diff 250"
262$bin/aegis -diff > log 2>&1
263if test $? -ne 0 ; then cat log; no_result; fi
264
265activity="set the change UUID 264"
266$bin/aegis -ca -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd5 > log 2>&1
267if test $? -ne 0 ; then cat log; no_result; fi
268
269#
270# finish development of the change
271#
272activity="develop end 257"
273$bin/aegis -de > log 2>&1
274if test $? -ne 0 ; then cat log; no_result; fi
275
276#
277# pass the review
278#
279activity="review pass 264"
280$bin/aegis -rpass -c 1 > log 2>&1
281if test $? -ne 0 ; then cat log; no_result; fi
282
283#
284# start integrating
285#
286activity="integrate begin 271"
287$bin/aegis -ib 1 > log 2>&1
288if test $? -ne 0 ; then cat log; no_result; fi
289
290#
291# integrate build
292#
293activity="build 278"
294$bin/aegis -b -nl -v > log 2>&1
295if test $? -ne 0 ; then cat log; no_result; fi
296
297#
298# pass the integration
299#
300activity="integrate pass 285"
301$bin/aegis -intpass -nl > log 2>&1
302if test $? -ne 0 ; then cat log; no_result; fi
303
304# --------------------------------------------------------------------------
305
306#
307# create a new change
308#
309activity="new change 294"
310cat > tmp << 'end'
311brief_description = "The second change";
312cause = internal_bug;
313end
314if test $? -ne 0 ; then no_result; fi
315$bin/aegis -nc 2 -f tmp -p foo > log 2>&1
316if test $? -ne 0 ; then cat log; no_result; fi
317
318#
319# begin development of a change
320#
321activity="develop begin 306"
322$bin/aegis -db 2 -dir $workchan > log 2>&1
323if test $? -ne 0 ; then cat log; no_result; fi
324
325# --------------------------------------------------------------------------
326
327unset AELOG
328CVS_SERVER=$bin/aecvsserver
329export CVS_SERVER
330
331#
332# Now use cvs to checkout the project.
333#
334activity="cvs checkout 319"
335cvs -d :fork:/aegis co ${AEGIS_PROJECT}.C002 > log 2>&1
336if test $? -ne 0 ; then cat log; no_result; fi
337
338#
339# Add a file in the cvs workarea and
340# then used cvs remove and commit it.
341#
342activity="cvs remove 327"
343rm $AEGIS_PROJECT.C002/dir/bogus
344if test $? -ne 0 ; then no_result; fi
345
346cd $AEGIS_PROJECT.C002/dir
347cvs -d :fork:/aegis remove bogus > log 2>&1
348if test $? -ne 0 ; then cat log; cat server.log; fail; fi
349
350cd $work
351
352activity="cvs commit 337"
353cvs -d :fork:/aegis commit -m "message" $AEGIS_PROJECT.C002 > log 2>&1
354if test $? -ne 0 ; then cat log; cat server.log; fail; fi
355
356#
357# make sure the meta-data matches
358#
359activity="check change file state 344"
360cat > ok << 'fubar'
361src =
362[
363        {
364                file_name = "dir/bogus";
365                uuid = "aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd1";
366                action = remove;
367                edit_origin =
368                {
369                        revision = "1";
370                        encoding = none;
371                        uuid = "aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd5";
372                };
373                usage = source;
374        },
375];
376fubar
377if test $? -ne 0 ; then no_result; fi
378
379check_it ok $workproj/info/change/0/002.fs
380
381#
382# Only definite negatives are possible.
383# The functionality exercised by this test appears to work,
384# no other guarantees are made.
385#
386pass
387# vim: set ts=8 sw=4 et :
388