1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 2001, 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
25umask 022
26
27LINES=24
28export LINES
29COLS=80
30export COLS
31
32USER=${USER:-${LOGNAME:-`whoami`}}
33
34work=${AEGIS_TMP:-/tmp}/$$
35PAGER=cat
36export PAGER
37AEGIS_FLAGS="delete_file_preference = no_keep; \
38	lock_wait_preference = always; \
39	diff_preference = automatic_merge; \
40	pager_preference = never; \
41	persevere_preference = all; \
42	log_file_preference = never;"
43export AEGIS_FLAGS
44AEGIS_THROTTLE=-1
45export AEGIS_THROTTLE
46
47here=`pwd`
48if test $? -ne 0 ; then exit 2; fi
49
50bin=$here/${1-.}/bin
51
52if test "$EXEC_SEARCH_PATH" != ""
53then
54    tpath=
55    hold="$IFS"
56    IFS=":$IFS"
57    for tpath2 in $EXEC_SEARCH_PATH
58    do
59	tpath=${tpath}${tpath2}/${1-.}/bin:
60    done
61    IFS="$hold"
62    PATH=${tpath}${PATH}
63else
64    PATH=${bin}:${PATH}
65fi
66export PATH
67
68pass()
69{
70	set +x
71	echo PASSED 1>&2
72	cd $here
73	find $work -type d -user $USER -exec chmod u+w {} \;
74	rm -rf $work
75	exit 0
76}
77fail()
78{
79	set +x
80	echo "FAILED test of the aemvu functionality ($activity)" 1>&2
81	cd $here
82	find $work -type d -user $USER -exec chmod u+w {} \;
83	rm -rf $work
84	exit 1
85}
86no_result()
87{
88	set +x
89	echo "NO RESULT when testing the aemvu functionality ($activity)" 1>&2
90	cd $here
91	find $work -type d -user $USER -exec chmod u+w {} \;
92	rm -rf $work
93	exit 2
94}
95trap \"no_result\" 1 2 3 15
96
97check_it()
98{
99	sed	-e "s|$work|...|g" \
100		-e 's|= [0-9][0-9]*; /.*|= TIME;|' \
101		-e "s/\"$USER\"/\"USER\"/g" \
102		-e 's/19[0-9][0-9]/YYYY/' \
103		-e 's/20[0-9][0-9]/YYYY/' \
104		-e 's/node = ".*"/node = "NODE"/' \
105		-e 's/crypto = ".*"/crypto = "GUNK"/' \
106		< $2 > $work/sed.out
107	if test $? -ne 0; then no_result; fi
108	diff $1 $work/sed.out
109	if test $? -ne 0; then fail; fi
110}
111
112activity="working directory 99"
113mkdir $work $work/lib
114if test $? -ne 0 ; then no_result; fi
115chmod 777 $work/lib
116if test $? -ne 0 ; then no_result; fi
117cd $work
118if test $? -ne 0 ; then no_result; fi
119tmp="$work/temp-file"
120
121worklib=$work/lib
122workchan=$work/change-dir
123
124AEGIS_PATH=$worklib
125export AEGIS_PATH
126PATH=$bin:$PATH
127export PATH
128AEGIS_PROJECT=example
129export AEGIS_PROJECT
130
131#
132# use the built-in error messages
133#
134AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
135export AEGIS_MESSAGE_LIBRARY
136unset LANG
137unset LANGUAGE
138
139#
140# test the aemvu functionality
141#
142activity="new project 129"
143$bin/aegis -npr example -version '' -lib $worklib -dir $work/proj -v > log 2>&1
144if test $? -ne 0 ; then cat log; no_result; fi
145
146#
147# change project attributes
148#
149activity="project attributes 136"
150cat > $tmp << 'TheEnd'
151description = "bogosity";
152developer_may_review = true;
153developer_may_integrate = true;
154reviewer_may_integrate = true;
155default_test_exemption = true;
156TheEnd
157if test $? -ne 0 ; then no_result; fi
158
159$bin/aegis -proatt -f $tmp -proj example -v > log 2>&1
160if test $? -ne 0 ; then cat log; no_result; fi
161
162#
163# create a new change
164#
165activity="new change 152"
166cat > $tmp << 'TheEnd'
167brief_description = "c1";
168description = "c1";
169cause = internal_enhancement;
170TheEnd
171if test $? -ne 0 ; then no_result; fi
172
173AEGIS_PROJECT=example
174export AEGIS_PROKECT
175
176$bin/aegis -nc 1 -f $tmp -project example -v > log 2>&1
177if test $? -ne 0 ; then cat log; no_result; fi
178
179#
180# add a new developer
181#
182activity="new developer 169"
183$bin/aegis -newdev $USER -v > log 2>&1
184if test $? -ne 0 ; then cat log; no_result; fi
185activity="new reviewer 172"
186$bin/aegis -newrev $USER -v > log 2>&1
187if test $? -ne 0 ; then cat log; no_result; fi
188activity="new integrator 175"
189$bin/aegis -newint $USER -v > log 2>&1
190if test $? -ne 0 ; then cat log; no_result; fi
191
192#
193# begin development of the change
194#
195activity="develop begin 182"
196$bin/aegis -devbeg 1 -dir $workchan -v > log 2>&1
197if test $? -ne 0 ; then cat log; no_result; fi
198
199#
200# add the new files to the change
201#
202activity="new file 189"
203$bin/aegis -new_file $workchan/Howto.cook $workchan/aegis.conf $workchan/f1 \
204	$workchan/f2 $workchan/f3 -nl -v > log 2>&1
205if test $? -ne 0 ; then cat log; no_result; fi
206
207date > $workchan/f1
208if test $? -ne 0 ; then no_result; fi
209date > $workchan/f2
210if test $? -ne 0 ; then no_result; fi
211date > $workchan/f3
212if test $? -ne 0 ; then no_result; fi
213
214cat > $workchan/aegis.conf << 'TheEnd'
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";
226
227merge_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
228	echo '1,$$p' ) | ed - $mr > $out";
229TheEnd
230if test $? -ne 0 ; then no_result; fi
231
232#
233# build the change
234#
235activity="build 224"
236$bin/aegis -build -nl -v > log 2>&1
237if test $? -ne 0 ; then cat log; no_result; fi
238
239#
240# difference the change
241#
242activity="diff 231"
243$bin/aegis -diff -v -nl > log 2>&1
244if test $? -ne 0 ; then cat log; no_result; fi
245
246#
247# finish development of the change
248#
249activity="develop end 238"
250$bin/aegis -dev_end -v > log 2>&1
251if test $? -ne 0 ; then cat log; no_result; fi
252
253#
254# pass the review
255#
256activity="review pass 245"
257$bin/aegis -review_pass -chan 1 -proj example -v > log 2>&1
258if test $? -ne 0 ; then cat log; no_result; fi
259
260#
261# start integrating
262#
263activity="integrate begin 252"
264$bin/aegis -intbeg 1 -v > log 2>&1
265if test $? -ne 0 ; then cat log; no_result; fi
266
267#
268# integrate build and test
269#
270activity="build 259"
271$bin/aegis -build -nl -v > log 2>&1
272if test $? -ne 0 ; then cat log; no_result; fi
273
274#
275# pass the integration
276#
277activity="integrate pass 266"
278$bin/aegis -intpass -nl -v > log 2>&1
279if test $? -ne 0 ; then cat log; no_result; fi
280
281#
282# create the second change
283#
284activity="new change 273"
285cat > $tmp << 'fubar'
286brief_description = "c2";
287description = "c2";
288cause = internal_bug;
289fubar
290if test $? -ne 0 ; then no_result; fi
291$bin/aegis -nc 2 -f $tmp -project example -v > log 2>&1
292if test $? -ne 0 ; then cat log; no_result; fi
293
294#
295# begin development of the change
296#
297activity="develop begin 286"
298$bin/aegis -devbeg 2 -dir $workchan -v > log 2>&1
299if test $? -ne 0 ; then cat log; no_result; fi
300
301#
302# move files with the change
303#
304activity="move file 293"
305$bin/aegis -mv $workchan/f2 $workchan/bogus -nl -v > log 2>&1
306if test $? -ne 0 ; then cat log; no_result; fi
307
308#
309# move file undo
310#
311activity="move file undo 300"
312$bin/aegis -mvu $workchan/bogus -nl -v > log 2>&1
313if test $? -ne 0 ; then cat log; fail; fi
314
315#
316# make sure the file state looks like we expect
317#
318cat > ok << fubar
319src =
320[
321];
322fubar
323if test $? -ne 0 ; then cat log; no_result; fi
324check_it ok $work/proj/info/change/0/002.fs
325
326#
327# the things tested in this test, worked
328# the things not tested in this test, may or may not work
329#
330pass
331