1#!/bin/sh
2#
3#       aegis - project change supervisor
4#       Copyright (C) 2003-2008, 2012 Peter Miller
5#
6#       This program is free software; you can redistribute it and/or modify
7#       it under the terms of the GNU General Public License as published by
8#       the Free Software Foundation; either version 3 of the License, or
9#       (at your option) any later version.
10#
11#       This program is distributed in the hope that it will be useful,
12#       but WITHOUT ANY WARRANTY; without even the implied warranty of
13#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#       GNU General Public License for more details.
15#
16#       You should have received a copy of the GNU General Public License
17#       along with this program. If not, see
18#       <http://www.gnu.org/licenses/>.
19#
20
21unset AEGIS_PROJECT
22unset AEGIS_CHANGE
23unset AEGIS_PATH
24unset AEGIS
25umask 022
26
27#
28# Make sure cvs is installed on this machine.
29# If it is not, give an automatic pass.
30#
31if cvs --version > /dev/null 2>&1
32then
33    :
34else
35    echo ''
36    echo '      You do not have CVS installed on this machine.'
37    echo '      This test is assumed to pass by default.'
38    echo ''
39    exit 0
40fi
41
42CVSversion=`cvs --version |
43awk 'NR==2{split($5,a,"[.]");printf("%02d.%02d.%02d\n",a[1],a[2],a[3]);}'`
44if expr "$CVSversion" "<" "01.11.00" > /dev/null 2>&1
45then
46    echo ''
47    echo '      You do not have CVS 1.11 or later installed on this machine.'
48    echo '      This test is assumed to pass by default.'
49    echo ''
50    exit 0
51fi
52
53LINES=24
54export LINES
55COLS=80
56export COLS
57
58USER=${USER:-${LOGNAME:-`whoami`}}
59
60work=${AEGIS_TMP:-/tmp}/$$
61PAGER=cat
62export PAGER
63AEGIS_FLAGS="delete_file_preference = no_keep; \
64        lock_wait_preference = always; \
65        diff_preference = automatic_merge; \
66        pager_preference = never; \
67        persevere_preference = all; \
68        log_file_preference = never;"
69export AEGIS_FLAGS
70AEGIS_THROTTLE=-1
71export AEGIS_THROTTLE
72
73here=`pwd`
74if test $? -ne 0 ; then exit 2; fi
75
76bin=$here/${1-.}/bin
77
78if test "$EXEC_SEARCH_PATH" != ""
79then
80    tpath=
81    hold="$IFS"
82    IFS=":$IFS"
83    for tpath2 in $EXEC_SEARCH_PATH
84    do
85        tpath=${tpath}${tpath2}/${1-.}/bin:
86    done
87    IFS="$hold"
88    PATH=${tpath}${PATH}
89else
90    PATH=${bin}:${PATH}
91fi
92export PATH
93
94check_it()
95{
96        sed     -e "s|$work|...|g" \
97                -e 's|= [0-9][0-9]*; /.*|= TIME;|' \
98                -e "s/\"$USER\"/\"USER\"/g" \
99                -e 's/19[0-9][0-9]/YYYY/' \
100                -e 's/20[0-9][0-9]/YYYY/' \
101                -e 's/node = ".*"/node = "NODE"/' \
102                -e 's/crypto = ".*"/crypto = "GUNK"/' \
103                -e 's/uuid = ".*"/uuid = "UUID"/' \
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 add 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 add 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 165"
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 172"
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 188"
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 201"
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 219"
220$bin/aegis -nf  $workchan/aegis.conf $workchan/dir/bogus -nl > log 2>&1
221if test $? -ne 0 ; then cat log; no_result; fi
222
223cat > $workchan/dir/bogus << 'end'
224the trunk version
225end
226if test $? -ne 0 ; then no_result; fi
227
228cat > $workchan/aegis.conf << 'end'
229build_command = "exit 0";
230link_integration_directory = true;
231
232history_get_command = "aesvt -check-out -edit ${quote $edit} "
233    "-history ${quote $history} -f ${quote $output}";
234history_put_command = "aesvt -check-in -history ${quote $history} "
235    "-f ${quote $input}";
236history_query_command = "aesvt -query -history ${quote $history}";
237history_content_limitation = binary_capable;
238
239diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
240diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
241        echo '1,$$p' ) | ed - $mr > $out";
242patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
243test $$? -le 1";
244end
245if test $? -ne 0 ; then no_result; fi
246
247#
248# build the change
249#
250activity="build 250"
251$bin/aegis -build -nl -v > log 2>&1
252if test $? -ne 0 ; then cat log; no_result; fi
253
254#
255# difference the change
256#
257activity="diff 257"
258$bin/aegis -diff > log 2>&1
259if test $? -ne 0 ; then cat log; no_result; fi
260
261#
262# finish development of the change
263#
264activity="develop end 264"
265$bin/aegis -de > log 2>&1
266if test $? -ne 0 ; then cat log; no_result; fi
267
268#
269# pass the review
270#
271activity="review pass 271"
272$bin/aegis -rpass -c 1 > log 2>&1
273if test $? -ne 0 ; then cat log; no_result; fi
274
275#
276# start integrating
277#
278activity="integrate begin 278"
279$bin/aegis -ib 1 > log 2>&1
280if test $? -ne 0 ; then cat log; no_result; fi
281
282#
283# integrate build
284#
285activity="build 285"
286$bin/aegis -b -nl -v > log 2>&1
287if test $? -ne 0 ; then cat log; no_result; fi
288
289#
290# pass the integration
291#
292activity="integrate pass 292"
293$bin/aegis -intpass -nl > log 2>&1
294if test $? -ne 0 ; then cat log; no_result; fi
295
296# --------------------------------------------------------------------------
297
298#
299# create a new change
300#
301activity="new change 301"
302cat > tmp << 'end'
303brief_description = "The second change";
304cause = internal_bug;
305end
306if test $? -ne 0 ; then no_result; fi
307$bin/aegis -nc 2 -f tmp -p foo > log 2>&1
308if test $? -ne 0 ; then cat log; no_result; fi
309
310#
311# begin development of a change
312#
313activity="develop begin 313"
314$bin/aegis -db 2 -dir $workchan > log 2>&1
315if test $? -ne 0 ; then cat log; no_result; fi
316
317# --------------------------------------------------------------------------
318
319unset AELOG
320CVS_SERVER=$bin/aecvsserver
321export CVS_SERVER
322
323#
324# Now use cvs to checkout the project.
325#
326activity="cvs checkout 326"
327cvs -d :fork:/aegis co ${AEGIS_PROJECT}.C002 > log 2>&1
328if test $? -ne 0 ; then cat log; no_result; fi
329
330#
331# Add a file in the cvs workarea and
332# then used cvs add and commit it.
333#
334activity="cvs add 334"
335echo "Change Two" > $AEGIS_PROJECT.C002/dir/baboon
336if test $? -ne 0 ; then no_result; fi
337
338cd $AEGIS_PROJECT.C002/dir
339cvs -d :fork:/aegis add baboon > log 2>&1
340if test $? -ne 0 ; then cat log; fail; fi
341
342cd $work
343
344activity="cvs commit 344"
345cvs -d :fork:/aegis commit -m "message" $AEGIS_PROJECT.C002 > log 2>&1
346if test $? -ne 0 ; then cat log; fail; fi
347
348#
349# make sure the change tracks the cvs work area
350#
351diff $AEGIS_PROJECT.C002/dir/baboon $workchan/dir/baboon
352if test $? -ne 0 ; then fail; fi
353
354#
355# make sure the meta-data matches
356#
357activity="check change file state 357"
358cat > ok << 'fubar'
359src =
360[
361        {
362                file_name = "dir/baboon";
363                uuid = "UUID";
364                action = create;
365                usage = source;
366        },
367];
368fubar
369if test $? -ne 0 ; then no_result; fi
370
371check_it ok $workproj/info/change/0/002.fs
372
373#
374# Only definite negatives are possible.
375# The functionality exercised by this test appears to work,
376# no other guarantees are made.
377#
378pass
379# vim: set ts=8 sw=4 et :
380