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