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