1#!/bin/sh
2#
3# aegis - project change supervisor
4# Copyright (C) 2002, 2005-2008, 2011, 2012 Peter Miller
5# Copyright (C) 2007 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 (at
10# 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 GNU
15# 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 <http://www.gnu.org/licenses/>.
19#
20
21unset AEGIS_PROJECT
22unset AEGIS_CHANGE
23unset AEGIS_PATH
24unset AEGIS
25unset LINES
26unset COLS
27umask 022
28
29USER=${USER:-${LOGNAME:-`whoami`}}
30
31work=${AEGIS_TMP:-/tmp}/$$
32
33here=`pwd`
34if test $? -ne 0 ; then exit 2; fi
35
36if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
37
38if test "$EXEC_SEARCH_PATH" != ""
39then
40    tpath=
41    hold="$IFS"
42    IFS=":$IFS"
43    for tpath2 in $EXEC_SEARCH_PATH
44    do
45        tpath=${tpath}${tpath2}/${1-.}/bin:
46    done
47    IFS="$hold"
48    PATH=${tpath}${PATH}
49else
50    PATH=${bin}:${PATH}
51fi
52export PATH
53
54no_result()
55{
56    set +x
57    echo "NO RESULT for test of aepatch -send (diff) functionality ($activity)" 1>&2
58    cd $here
59    find $work -type d -user $USER -exec chmod u+w {} \;
60    rm -rf $work
61    exit 2
62}
63fail()
64{
65    set +x
66    echo "FAILED test of aepatch -send (diff) functionality ($activity)" 1>&2
67    cd $here
68    find $work -type d -user $USER -exec chmod u+w {} \;
69    rm -rf $work
70    exit 1
71}
72pass()
73{
74    set +x
75    echo PASSED 1>&2
76    cd $here
77    find $work -type d -user $USER -exec chmod u+w {} \;
78    rm -rf $work
79    exit 0
80}
81trap "no_result" 1 2 3 15
82
83#
84# some variable to make things earier to read
85#
86PAGER=cat
87export PAGER
88
89AEGIS_FLAGS="delete_file_preference = no_keep; \
90    lock_wait_preference = always; \
91    diff_preference = automatic_merge; \
92    pager_preference = never; \
93    persevere_preference = all; \
94    log_file_preference = never;"
95export AEGIS_FLAGS
96AEGIS_THROTTLE=-1
97export AEGIS_THROTTLE
98
99worklib=$work/lib
100workproj=$work/foo.proj
101workchan=$work/foo.chan
102tmp=$work/tmp
103AEGIS_PATH=$worklib ; export AEGIS_PATH
104AEGIS_PROJECT=foo ; export AEGIS_PROJECT
105
106#
107# make the directories
108#
109activity="working directory 112"
110mkdir $work $work/lib
111if test $? -ne 0 ; then no_result; fi
112chmod 777 $work/lib
113if test $? -ne 0 ; then no_result; fi
114cd $work
115if test $? -ne 0 ; then no_result; fi
116
117#
118# use the built-in error messages
119#
120AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
121export AEGIS_MESSAGE_LIBRARY
122unset LANG
123unset LANGUAGE
124
125#
126# make a new project
127#
128activity="new project 131"
129$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
130if test $? -ne 0 ; then cat log; no_result; fi
131
132#
133# change project attributes
134#
135activity="project attributes 138"
136cat > $tmp << 'end'
137description = "A bogus project created to test the aepatch -send (diff) functionality.";
138developer_may_review = true;
139developer_may_integrate = true;
140reviewer_may_integrate = true;
141end
142if test $? -ne 0 ; then no_result; fi
143$bin/aegis -pa -f $tmp > log 2>&1
144if test $? -ne 0 ; then cat log; no_result; fi
145
146#
147# create a new change
148#
149activity="new change 152"
150cat > $tmp << 'end'
151brief_description = "The first change";
152cause = internal_bug;
153end
154if test $? -ne 0 ; then no_result; fi
155$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
156if test $? -ne 0 ; then cat log; no_result; fi
157
158#
159# add the staff
160#
161activity="staff 164"
162$bin/aegis -nd $USER > log 2>&1
163if test $? -ne 0 ; then cat log; no_result; fi
164$bin/aegis -nrv $USER > log 2>&1
165if test $? -ne 0 ; then cat log; no_result; fi
166$bin/aegis -ni $USER > log 2>&1
167if test $? -ne 0 ; then cat log; no_result; fi
168
169#
170# begin development of a change
171#
172$bin/aegis -db 1 -dir $workchan > log 2>&1
173if test $? -ne 0 ; then cat log; no_result; fi
174
175#
176# add a new files to the change
177#
178activity="new file 181"
179$bin/aegis -nf $workchan/main.c -nl \
180    -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd1 > log 2>&1
181if test $? -ne 0 ; then cat log; no_result; fi
182$bin/aegis -nf $workchan/test.c -nl \
183    -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd2 > log 2>&1
184if test $? -ne 0 ; then cat log; no_result; fi
185$bin/aegis -nf $workchan/Makefile -nl \
186    -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd3 > log 2>&1
187if test $? -ne 0 ; then cat log; no_result; fi
188$bin/aegis -nf $workchan/aegis.conf -nl \
189    -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd4 > log 2>&1
190if test $? -ne 0 ; then cat log; no_result; fi
191cat > $workchan/main.c << 'end'
192int
193main(argc, argv)
194    int argc;
195    char **argv;
196{
197    test();
198    exit(0);
199    return 0;
200    /* cough */
201}
202end
203if test $? -ne 0 ; then no_result; fi
204cat > $workchan/test.c << 'end'
205void test() { }
206end
207if test $? -ne 0 ; then no_result; fi
208TAB=`awk 'BEGIN{printf("%c", 9)}' /dev/null`
209sed "s|{TAB}|$TAB|g" > $workchan/Makefile << 'end'
210.c.o:
211{TAB}date > $@
212
213foo: main.o test.o
214{TAB}date > $@
215end
216if test $? -ne 0 ; then no_result; fi
217cat > $workchan/aegis.conf << 'end'
218build_command = "exit 0";
219link_integration_directory = true;
220
221history_get_command = "aesvt -check-out -edit ${quote $edit} "
222    "-history ${quote $history} -f ${quote $output}";
223history_put_command = "aesvt -check-in -history ${quote $history} "
224    "-f ${quote $input}";
225history_query_command = "aesvt -query -history ${quote $history}";
226history_content_limitation = binary_capable;
227
228diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
229diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
230    echo '1,$$p' ) | ed - $mr > $out";
231patch_diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
232end
233if test $? -ne 0 ; then no_result; fi
234
235#
236# create a new test
237#
238activity="new test 240"
239$bin/aegis -nt -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd5 > log 2>&1
240if test $? -ne 0 ; then cat log; no_result; fi
241cat > $workchan/test/00/t0001a.sh << 'end'
242#!/bin/sh
243exit 0
244end
245if test $? -ne 0 ; then no_result; fi
246
247#
248# build the change
249#
250activity="build 252"
251$bin/aegis -build -nl -v > log 2>&1
252if test $? -ne 0 ; then cat log; fail; fi
253
254#
255# difference the change
256#
257activity="diff 259"
258$bin/aegis -diff > log 2>&1
259if test $? -ne 0 ; then cat log; no_result; fi
260
261#
262# test the change
263#
264activity="test 266"
265$bin/aegis -t -v > log 2>&1
266if test $? -ne 0 ; then cat log; no_result; fi
267
268$bin/aegis -ca -uuid aaaaaaaa-bbbb-4bbb-8ccc-ccccddddddd6 > log 2>&1
269if test $? -ne 0 ; then cat log; no_result; fi
270
271#
272# finish development of the change
273#
274activity="develop end 276"
275$bin/aegis -de > log 2>&1
276if test $? -ne 0 ; then cat log; fail; fi
277
278#
279# pass the review
280#
281activity="review pass 283"
282$bin/aegis -rpass -c 1 > log 2>&1
283if test $? -ne 0 ; then cat log; no_result; fi
284
285#
286# start integrating
287#
288activity="integrate begin 290"
289$bin/aegis -ib 1 > log 2>&1
290if test $? -ne 0 ; then cat log; no_result; fi
291
292#
293# integrate build
294#
295activity="build 297"
296$bin/aegis -b -nl -v > log 2>&1
297if test $? -ne 0 ; then cat log; no_result; fi
298
299#
300# integrate test
301#
302activity="test 304"
303$bin/aegis -t -nl -v > log 2>&1
304if test $? -ne 0 ; then cat log; no_result; fi
305
306#
307# pass the integration
308#
309activity="integrate pass 311"
310$bin/aegis -intpass -nl > log 2>&1
311if test $? -ne 0 ; then cat log; no_result; fi
312
313#
314# create a new change, to generate a patch
315#
316activity="new change 318"
317cat > $tmp << 'end'
318brief_description = "The 2nd change";
319description = "The second change";
320cause = internal_bug;
321end
322if test $? -ne 0 ; then no_result; fi
323$bin/aegis -nc 2 -f $tmp -p foo > log 2>&1
324if test $? -ne 0 ; then cat log; no_result; fi
325
326#
327# begin development of a change
328#
329$bin/aegis -db 2 -dir $workchan > log 2>&1
330if test $? -ne 0 ; then cat log; no_result; fi
331
332#
333# add a new files to the change
334#
335activity="copy file 336"
336$bin/aegis -cp $workchan/main.c -c 2 -nl > log 2>&1
337if test $? -ne 0 ; then cat log; no_result; fi
338cat > $workchan/main.c << 'end'
339int
340main(argc, argv)
341    int argc;    /* changed */
342    char **argv;
343{
344    if (argc != 1)
345    {
346        fprintf(stderr, "usage: %s\n", argv[0]);
347        exit(1);
348    }
349    test();
350    exit(0);
351    return 0;
352}
353end
354if test $? -ne 0 ; then no_result; fi
355
356#
357# Now use the change to generate a patch.
358#
359aepatch -send 2 -o the.patch -cte=none -nocomp > log 2>&1
360if test $? -ne 0 ; then no_result; fi
361
362#
363# And check the the patch is OK.
364#
365action="check patch"
366sed -e "s|{TAB}|$TAB|g" -e 's/X$//' > ok << 'end'
367MIME-Version: 1.0X
368Content-Type: application/aegis-patchX
369Subject: foo - The 2nd changeX
370Content-Name: foo.C002.patchX
371Content-Disposition: attachment; filename=foo.C002.patchX
372X-Aegis-Project-Name: fooX
373X-Aegis-Change-Number: 2X
374X
375#{TAB}X
376#{TAB}Summary:X
377#{TAB}The 2nd changeX
378#{TAB}X
379#{TAB}Description:X
380#{TAB}The second changeX
381#{TAB}X
382# Aegis-Change-Set-BeginX
383# QlpoMzFBWSZTWRmfNFsAAEBbgEwQUAc0SgQKv+ff6jAA2iw0SYKPBTwoGgNPUaMg1NIaMTI0
384# AAAACVMgp6Q003qnoQAAHqUwxxbQwfkc7BIBtn0LHnkR6LGAgPQopK8K3XTU6bLC2Jh0jHbV
385# ODACQOIXl4axIN/MmtzvovaDuLOrLAXMsrQSv7khJldatgrMV7/JhA6xgedeFnckmEfjq/HC
386# NEaak98wtBIkVbCjpRsYXuGgU93RtIwMqMChbpFOSVnB2TpJmZawJklogNqtnF0R99Mudhna
387# SiLErFHUgAnGqgAQd8OagRpmaxyVkw5GoeH4u5IpwoSAzPmi2A==
388# Aegis-Change-Set-EndX
389#X
390Index: main.cX
3913c3X
392<     int argc;X
393---X
394>     int argc;    /* changed */X
3955a6,10X
396>     if (argc != 1)X
397>     {X
398>         fprintf(stderr, "usage: %s\n", argv[0]);X
399>         exit(1);X
400>     }X
4019d13X
402<     /* cough */X
403end
404if test $? -ne 0 ; then no_result; fi
405
406diff -b ok the.patch
407if test $? -ne 0 ; then fail; fi
408
409#
410# receive the patch
411#
412activity="aepatch receive 409"
413$bin/aepatch -receive -dir ${workchan}3 -f the.patch -trojan > log 2>&1
414if test $? -ne 0 ; then cat log; fail; fi
415
416#
417# Make sure the patch is applied properly.
418#
419activity="verify 416"
420diff -b $workchan/main.c ${workchan}3/main.c
421if test $? -ne 0 ; then fail; fi
422
423#
424# the things tested in this test, worked
425#
426pass
427
428
429# vim: set ts=8 sw=4 et :
430