1#!/bin/sh
2#
3#       aegis - project change supervisor
4#       Copyright (C) 2001, 2005-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
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
55#
56# set the path, so that the aegis command that aepath invokes
57# is from the same test set as the aepatch command itself.
58#
59PATH=${bin}:$PATH
60export PATH
61
62no_result()
63{
64        set +x
65        echo "NO RESULT for test of aepatch -send functionality ($activity)" 1>&2
66        cd $here
67        find $work -type d -user $USER -exec chmod u+w {} \;
68        rm -rf $work
69        exit 2
70}
71fail()
72{
73        set +x
74        echo "FAILED test of aepatch -send functionality ($activity)" 1>&2
75        cd $here
76        find $work -type d -user $USER -exec chmod u+w {} \;
77        rm -rf $work
78        exit 1
79}
80pass()
81{
82        set +x
83        echo PASSED 1>&2
84        cd $here
85        find $work -type d -user $USER -exec chmod u+w {} \;
86        rm -rf $work
87        exit 0
88}
89trap "no_result" 1 2 3 15
90
91#
92# some variable to make things earier to read
93#
94PAGER=cat
95export PAGER
96
97AEGIS_FLAGS="delete_file_preference = no_keep; \
98        lock_wait_preference = always; \
99        diff_preference = automatic_merge; \
100        pager_preference = never; \
101        persevere_preference = all; \
102        log_file_preference = never;"
103export AEGIS_FLAGS
104AEGIS_THROTTLE=-1
105export AEGIS_THROTTLE
106
107worklib=$work/lib
108workproj=$work/foo.proj
109workchan=$work/foo.chan
110tmp=$work/tmp
111AEGIS_PATH=$worklib ; export AEGIS_PATH
112AEGIS_PROJECT=foo ; export AEGIS_PROJECT
113
114#
115# make the directories
116#
117activity="working directory 117"
118mkdir $work $work/lib
119if test $? -ne 0 ; then no_result; fi
120chmod 777 $work/lib
121if test $? -ne 0 ; then no_result; fi
122cd $work
123if test $? -ne 0 ; then no_result; fi
124
125#
126# use the built-in error messages
127#
128AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
129export AEGIS_MESSAGE_LIBRARY
130unset LANG
131unset LANGUAGE
132
133#
134# make a new project
135#
136activity="new project 136"
137$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
138if test $? -ne 0 ; then cat log; no_result; fi
139
140#
141# change project attributes
142#
143activity="project attributes 143"
144cat > $tmp << 'end'
145description = "A bogus project created to test the aepatch -send functionality.";
146developer_may_review = true;
147developer_may_integrate = true;
148reviewer_may_integrate = true;
149end
150if test $? -ne 0 ; then no_result; fi
151$bin/aegis -pa -f $tmp > log 2>&1
152if test $? -ne 0 ; then cat log; no_result; fi
153
154#
155# create a new change
156#
157activity="new change 157"
158cat > $tmp << 'end'
159brief_description = "The first change";
160cause = internal_bug;
161end
162if test $? -ne 0 ; then no_result; fi
163$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
164if test $? -ne 0 ; then cat log; no_result; fi
165
166#
167# add the staff
168#
169activity="staff 169"
170$bin/aegis -nd $USER > log 2>&1
171if test $? -ne 0 ; then cat log; no_result; fi
172$bin/aegis -nrv $USER > log 2>&1
173if test $? -ne 0 ; then cat log; no_result; fi
174$bin/aegis -ni $USER > log 2>&1
175if test $? -ne 0 ; then cat log; no_result; fi
176
177#
178# begin development of a change
179#
180$bin/aegis -db 1 -dir $workchan > log 2>&1
181if test $? -ne 0 ; then cat log; no_result; fi
182
183#
184# add a new files to the change
185#
186activity="new file 186"
187$bin/aegis -nf $workchan/main.c $workchan/test.c $workchan/Makefile \
188        $workchan/aegis.conf -nl > log 2>&1
189if test $? -ne 0 ; then cat log; no_result; fi
190cat > $workchan/main.c << 'end'
191int
192main(argc, argv)
193        int     argc;
194        char    **argv;
195{
196        test();
197        exit(0);
198        return 0;
199}
200end
201if test $? -ne 0 ; then no_result; fi
202cat > $workchan/test.c << 'end'
203void test() { }
204end
205if test $? -ne 0 ; then no_result; fi
206cat > $workchan/Makefile << 'end'
207.c.o:
208        date > $@
209
210foo: main.o test.o
211        date > $@
212end
213if test $? -ne 0 ; then no_result; fi
214cat > $workchan/aegis.conf << 'end'
215build_command = "exit 0";
216link_integration_directory = true;
217
218history_get_command = "aesvt -check-out -edit ${quote $edit} "
219    "-history ${quote $history} -f ${quote $output}";
220history_put_command = "aesvt -check-in -history ${quote $history} "
221    "-f ${quote $input}";
222history_query_command = "aesvt -query -history ${quote $history}";
223history_content_limitation = binary_capable;
224
225diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
226diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
227        echo '1,$$p' ) | ed - $mr > $out";
228end
229if test $? -ne 0 ; then no_result; fi
230
231#
232# create a new test
233#
234activity="new test 234"
235$bin/aegis -nt > log 2>&1
236if test $? -ne 0 ; then cat log; no_result; fi
237cat > $workchan/test/00/t0001a.sh << 'end'
238#!/bin/sh
239exit 0
240end
241if test $? -ne 0 ; then no_result; fi
242
243#
244# build the change
245#
246activity="build 246"
247$bin/aegis -build -nl -v > log 2>&1
248if test $? -ne 0 ; then cat log; fail; fi
249
250#
251# difference the change
252#
253activity="diff 253"
254$bin/aegis -diff > log 2>&1
255if test $? -ne 0 ; then cat log; no_result; fi
256
257#
258# test the change
259#
260activity="test 260"
261$bin/aegis -t -v > log 2>&1
262if test $? -ne 0 ; then cat log; no_result; fi
263
264#
265# finish development of the change
266#
267activity="develop end 267"
268$bin/aegis -de > log 2>&1
269if test $? -ne 0 ; then cat log; fail; fi
270
271#
272# pass the review
273#
274activity="review pass 274"
275$bin/aegis -rpass -c 1 > log 2>&1
276if test $? -ne 0 ; then cat log; no_result; fi
277
278#
279# start integrating
280#
281activity="integrate begin 281"
282$bin/aegis -ib 1 > log 2>&1
283if test $? -ne 0 ; then cat log; no_result; fi
284
285#
286# integrate build
287#
288activity="build 288"
289$bin/aegis -b -nl -v > log 2>&1
290if test $? -ne 0 ; then cat log; no_result; fi
291
292#
293# integrate test
294#
295activity="test 295"
296$bin/aegis -t -nl -v > log 2>&1
297if test $? -ne 0 ; then cat log; no_result; fi
298
299#
300# pass the integration
301#
302activity="integrate pass 302"
303$bin/aegis -intpass -nl > log 2>&1
304if test $? -ne 0 ; then cat log; no_result; fi
305#
306# Here is the patch we are going to receive.
307#
308cat > test.in << 'end'
309+ diff -u /tmp/9229/foo.proj/baseline/main.c test.ok
310--- main.c.old  Tue Jul 31 19:00:26 2001
311+++ bl/main.c   Tue Jul 31 19:00:29 2001
312@@ -1,8 +1,15 @@
313+#include <stdio.h>
314+
315 int
316 main(argc, argv)
317        int     argc;
318        char    **argv;
319 {
320+       if (argc != 1)
321+       {
322+               fprintf(stderr, "usage: %s\n", argv[0]);
323+               exit(1);
324+       }
325        test();
326        exit(0);
327        return 0;
328end
329if test $? -ne 0 ; then no_result; fi
330
331#
332# receive the patch
333#
334activity="aepatch receive 334"
335$bin/aepatch -receive -dir $workchan -f test.in -output number -trojan \
336    > log 2>&1
337if test $? -ne 0 ; then cat log; fail; fi
338
339#
340# this is what we're looking for
341#
342activity="verify 342"
343cat > test.ok << 'end'
344#include <stdio.h>
345
346int
347main(argc, argv)
348        int     argc;
349        char    **argv;
350{
351        if (argc != 1)
352        {
353                fprintf(stderr, "usage: %s\n", argv[0]);
354                exit(1);
355        }
356        test();
357        exit(0);
358        return 0;
359}
360end
361if test $? -ne 0 ; then no_result; fi
362
363diff -b test.ok $workchan/main.c
364if test $? -ne 0 ; then fail; fi
365
366activity="check the -output 366"
367cat > ok <<EOF
36810
369EOF
370if test $? -ne 0; then no_result; fi
371
372diff ok number
373if test $? -ne 0; then no_result; fi
374
375#
376# the things tested in this test, worked
377#
378pass
379# vim: set ts=8 sw=4 et :
380