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